Seeking Technical Feedback: Subscribing to MS Teams Channel Mentions

The Mattermost <> MS Teams integration currently relies on a global chats subscription (/chats/getAllMessages) to proxy notifications of chats and group chat messages from Teams into Mattermost, enabling a controlled flow of real-time information across general collaboration and mission critical environments.

The ideal next step is to expand notifications for @mentions from any Teams channel in which a user is a member. There are three potential paths forward:

  1. Subscribe to all chat messages across all channels (/teams/getAllMessages). This requires application level permissions, as well as a careful permissions check to only forward an @mention if the user actually had access to the message in question.
  2. Subscribe to handful of administrator configured channels (/teams/{id}/channels/{id}/messages). This could potentially be done with delegated permissions (for the administrator), but still requires a careful permission check to selectively forward any @mentions.
  3. Work with Microsoft to introduce a new, delegated Graph API subscription for a user’s messages across all channels.

This last option might look like a subscription against /users/{id}/teams/getAllMessages, notifying for all channel messages in an organization of which the given user is a member, with the integration doing the work of deciding when to notify based on the presence of a mention. Optionally, the Graph API endpoint might only notify for @mentions, with a subscription against /users/{id}/teams/getAllMentions only notifying if the user is explicitly mentioned in a post, but a more general purpose API would be more flexible.

There are existing APIs that get close. At first glance, /users/{id}/chats (see docs) suggests the ability to “track messages across all chats a particular user is part of”, but testing confirms this is only for chats and group chats – not channel chat messages.

There is also /teams/{team-id}/channels/{channel-id}/messages?$filter=mentions/any(u: u/mentioned/user/id eq '{id}') (see docs, as well as the chats version), but requires a subscription per channel. It’s also not clear if it checks if the user is actually a member, so may still require the permissions check.

Feedback on the above approaches or perhaps anything we’ve missed would be very welcome!

1 Like