0
votes

I want to be able to use the graph API to get a list of channels & teams, then have the app send an update to the appropriate channel without the user having to interact with MS Teams. Looking around I see a lot of posts saying this isn't possible yet, but Monday.com and Smartsheet seem to be doing this. Monday.com even specifies its using the beta api and neither are using connectors.

I attempted to do use the api POST /teams/{id}/channels/{id}/messages after authenticating via the way shown in this documentation

First Call for adminconsent

https://login.microsoftonline.com/organizations/v2.0/adminconsent?&client_id={botID}&response_type=code&redirect_uri=https://myoauthCallback&scope=offline_access User.ReadWrite.All Group.ReadWrite.All

After that returns I do an immediate call to get an access token, the above call doesn't seem to return anything I need to put into this request.

POST => /organizations/oauth2/v2.0/token

body = client_id={botId}&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default&client_secret={secret}&grant_type=client_credentials

I set the permissions in https://portal.azure.com/#blade/ for the bot to have the same scope as the first request above. Here it doesn't like the scope passed in the same way so I set it to default

I then take the access_token that is returned and attempt the call to POST a message to the channel.

URL: /teams/{TEAM_ID}/channels/{CHANNEL_ID}/messages

body: { subject: 'test subj', body: { contentType: 'text', content: 'Test message from app' }, }

This results in an error

statusCode: 401, code: 'UnknownError', message: ''

So how do I get the same functionality of these other apps so I can send a message directly to teams without setting up a connector?

2

2 Answers

0
votes

If you look at the "auth" page you linked to, it's talking about creating Application permissions. However, see the "create chatMessage in a channel" graph documentation and under "permissions" near the top it shows that it supports "Delegated" permissions only, so you can't use that particular endpoint with Application permissions unfortunately.

Connectors (Webhooks) will be able to do what you need, but you say you want to avoid that - perhaps you can explain why it's not ideal? I'm not aware of how to create a webhook programmatically, I'm afraid.

0
votes

Turns out it was a Office 365 Connector vs the regular "connector" that requires configuration within teams.

https://www.youtube.com/watch?v=EqodWkS5PYM

Edit: Disregard, even with office 365 connectors it requires the user to still interact with MS Teams in some way.

Another Edit: Turns out it is using Proactive Messaging https://docs.microsoft.com/en-us/microsoftteams/platform/resources/bot-v3/bot-conversations/bots-conv-proactive#net-example-from-this-sample

Although technically you cannot actually send a message to the app without a user interacting with the bot first, the installation of the app does trigger a conversationUpdate to which you can reply. So In the end, I can install the Teams app, and send a bot notification all within my web app, without the user having to actually touch Microsoft Teams.