0

My team is planning on building an MS Teams Bot (nodeJS) that would be used to send and schedule notifications to users within a company (Multi-Tenant).

Were planning on implementing the following workflow:

  1. have an admin user within an external company install/authorize our app into their MS Teams instance

  2. obtain a tokens from the step above that our app would be able to persist

3a. admin user would schedule a notification for a future date

4a. once future date arrives, bot is able retrieve persisted tokens (perhaps use refresh token to obtain new) and then send message to specific users

3b. admin user wants to push a notification to specific users

4b. bot is able retrieve persisted tokens (perhaps use refresh token to obtain new) and then send message to specific users

Slack offers a flow where a "bot token" is obtained rather than a user token which can then be leveraged to send notifications at a later point.

For some reference, something like this is similar to what we want: https://stackoverflow.com/a/47509000/5431797

Can you point me towards the right direction for making something like this work in MS Teams, namely, what would I need to do to have a company admin user accept scopes on behalf of everyone, get a token, store the token, leverage the token for future use as needed without needing users to signin (The Bot has no UI component) ?

Cabrera
  • 1,670
  • 1
  • 16
  • 16

1 Answers1

0

You don't actually need to use tokens in this way in Teams, it has another mechanism for what you're trying to do. Whenever a bot is installed, it receives an installation "welcome" command from the user, and it is able to save the context for that conversation for the future. It just needs that context to be able to send a message to the user whenever it needs. In Teams, this is called "Proactive Messaging", and I've got a detailed answer on how to get started with it over here: Sending proactive messages from an outside process to organizational users via Teams chat bot

The answer above includes links to starter code, a video overview and also more detail on how the admin can auto-install the app for the selected users using the Microsoft Graph.

Hilton Giesenow
  • 9,809
  • 2
  • 10
  • 24
  • Assuming everyone has the app installed because the admin auto installed it for them. Would I be able to use my Bot to proactively message different users by using their email to get their user id, and then send a message to a user based on their user id ? Also, where would permissions be handled ? is it when the Admin installs the app and they accept installing it ? Is there any callback for when the app is installed so my bot can record what company has installed it ? – Cabrera Apr 25 '23 at 17:02
  • You can't do it based on email address unfortunately - you need the unique ID of the conversation context. It gets sent with every message the user sends to your bot but it's also sent with the initial installation - something called the `OnMembersAddedAsync` event. See more at https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-send-welcome-message?view=azure-bot-service-4.0&tabs=csharp – Hilton Giesenow Apr 25 '23 at 18:30
  • In terms of permissions, only the members of that conversation (being the user and your bot) can message to it, and the ability for your bot to actually send a message to Teams is handled via the client id / client key as part of your bot's registration in Azure bot services. See this post for some more info on that: https://hilton.giesenow.com/how-bot-calls-actually-work – Hilton Giesenow Apr 25 '23 at 18:32
  • would this `OnMembersAdded` event be called for every single installation ? meaning, it would be called for single install events and for proactive company wide install events ? – Cabrera May 10 '23 at 18:16
  • I'm not totally understanding your question, but in any case, it's called for every user who installs a bot into a personal scope (i.e. in the left menu) or whenever the bot is added to a chat or channel – Hilton Giesenow May 10 '23 at 18:20