How do I use Teams integration

This topic will show you how the Team’s integration on Ideta works, and will explain how to use it for message sending.

First of all, you used this following link to integrate your bot:

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=5611367f-9280-4747-ad01-6938b5d7469a&response_type=code&redirect_uri=https://api.ideta.io/api/receive-message/-MvVx-PHkVIDPuxrYqD2/Badr1&response_mode=query&scope=offline_access%20https://graph.microsoft.com/Directory.Read.All%20https://graph.microsoft.com/User.Read%20https://graph.microsoft.com/ChannelMessage.Send&state=BotID___BotToken

After using this, you received two tokens, an access token and a refresh token, those tokens have to be refreshed at each new authorization request. The access token is available during 1 hour. The refresh token is renewed every time you renew your access with it. Those tokens are added as bot data:

There is a flow managing refreshes, you can call an Ideta API using this endpoint: https://api.ideta.io/api/receive-message/-MvVx-PHkVIDPuxrYqD2/{{conversationId}} (there is no need in adding a conversationId, but you can enter the id of the bot, that could help in case of bugs).

As a query parameter, you need to add a “refreshtok” (?refreshtok={your refresh token}, the API will return a JSON response, as below:

Do not forget to update your ts_refresh_token each time you use the request.

Now you know how to get access to Teams API, let’s see the main flow we need to send a message on a Team channel.

1-How to get the team-id (also known as groupId)

There is two different ways to find your team-id:

On Teams, try to get a link leading to your teamThe groupId in the link is the team-id.

Second way to get your team-id: listing all the groups (teams) the account you integrated has access to, and selecting the one you want (with a get request to collect the list).

You can then create a list of objects to collect basic information about all groups your account is associated with.

You can check team ids in the test page or in the live chat page.

You can repeat this process to get the list of channels:

Now you have your channel list, you are able to send any messages you want in any channel you want (you have access to).

Headers:

Content-Type: application/json; Authorization: Bearer {{access_token.access_token}}

Endpoint:

https://graph.microsoft.com/v1.0/teams/1ec80186-0311-4bef-a574-778df9b257e3/channels/{{channel_id}}/messages

Request body (example):

{

“body”: {

“content”: “Hello there”

},

“from”:{“application”: {

“displayName”: “Ideta”,

“id”:“35265d23-5965-4f02-997d-ddd3196dacbb”}}

}

To see the full documentation about the request: Send chatMessage in a channel or a chat - Microsoft Graph v1.0 | Microsoft Docs