Forum Discussion
Send messages/notifications to a user on MS Teams
Hello,
I am currently integrating MS Teams into our SaaS Product. The goal of the integration is to send notifications (messages) from our service to the appropriate user(s) in MS Teams. Eventually, we want to make the integration interactive, but step one is just messages.
I have already integrated with Slack and I am working on MS Teams. With Slack, I was able to request a "bot token" when the user authenticates through the OAuth2 flow (not an AI Bot).
I realize MS Teams most likely won't be that easy. (But if it is, please let me know). MS Teams is a part of the entire MS ecosystem while Slack is just Slack. So a simple "auth as a bot" may not exist.
This is my flow. I would appreciate some advice on if this flow seems correct. If not, what's the correct flow. If so, what am I missing?
Step 1
OAuth2 with permissions
{
"scopes": [
"TeamsAppInstallation.ReadWriteSelfForTeam",
"TeamsAppInstallation.ReadWriteAndConsentSelfForTeam",
"email",
"offline_access",
"openid",
"profile"
]
}
Step 2
Get list of user's teams (so they can choose the team)
- GET https://graph.microsoft.com/v1.0/me/joinedTeams
Step 3
Get list of Installed Apps (to check if we're already installed)
- GET https://graph.microsoft.com/v1.0/teams/[teamId]/installedApps
Step 4
Create (install) my app to the team
- POST https://graph.microsoft.com/v1.0/teams/[teamId]/installedApps
{"teamsApp[at]odata.bind":"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/ea99b1d4-8e99-4f29-b02a-a42ef14dd444"}
- 404 Response
{
"error": {
"code": "NotFound",
"message": "No Teams App found for id 'teamsAppId'.",
"innerError": {
"date": "2024-08-06T16:35:17",
"request-id": "b1a2321f-ba78-4600-8677-bcd89d211517",
"client-request-id": "b1a2321f-ba78-4600-8677-bcd89d211517"
}
}
}
I can't seem to figure out what id is used to install the Teams App.
Following Steps Questions
Once the TeamsApp is installed, do I continue to use the user's access token to send messages? Or do I use the ClientId/Secret for client auth and send messages as the app I created in "App Registration"? The App has been linked to the Teams App in the "webApplicationInfo" section of the teams app manifest. Is that enough? What graph endpoints should I use?
Notable Items
- I've created an "App Registration" object on portal.azure.com. That's where I'm getting the ClientId and ClientSecret for the OAuth2 flow. As well as setting OAuth2 permissions.
- I've created an "App" object on dev.teams.microsoft.com. This is where I'm getting the teamsAppId. This app has been published to my org. It has been approved by an admin.
- I created an "Azure Bot", but I don't think I need this.
- I tried to create a bot at dev.botframework.com, but the create flow sends me back to portal.azure.com to select a service to integration. Which I don't want to do.
Regarding Tutorials
I've gone through several tutorials, but I am not finding what I need. I've also had trouble finding tutorials that explain every step of how to get things setup up. Most tutorials have VSCode lifecycle tasks that hide what I think I need.
Again, any help would be appreciated. Thank you in advance.
- JonathonStorer6384Copper Contributor
Quick follow up, since it was removed from my post.
Where you see "email address removed for privacy reasons" in the code block, you should see "teamsApp[at]odata.bind". Must have gotten caught in the email address filter.
- JonathonStorer6384Copper Contributorfixed it in the main post
- JonathonStorer6384Copper Contributor
I got one step further.
The AppId from the App on dev.teams.microsoft.com is not the AppId required to install an app. I submitted & admin approved the dev.teams.microsoft.com app in my org. Then I was able to fetch it from the app catalog (https://graph.microsoft.com/v1.0/appCatalogs/teamsApps) to get it's actual AppId. I can add and remove the app from the team now.
Still can't send anything. Hopefully soon.