- 20 May 2021
- 3 Minutes to read
- Print
- DarkLight
Integrating With Microsoft Teams
- Updated on 20 May 2021
- 3 Minutes to read
- Print
- DarkLight
Overview
Microsoft Teams provides its users a workspace and place to work in a collaborative online format. Microsoft Teams provides a number of tools to implement these practices such as a text and video chat system, the ability to share documents, and a number of other tools. By using a combination of Microsoft Teams and Microsoft's Azure cloud system, users are able to integrate with Microsoft Teams out of the Teams environment, within a Flow that has been set up as a REST integration with a Microsoft Teams App or Channel.
The following document demonstrates how to set up and use integration with Microsoft Teams to interact with the Microsoft Teams messaging system.
Example A: Obtaining OAuth Token
To obtain an OAuth Token for a Microsoft Teams Channel:
For more information on how to register an application in Azure, see: Register a new application using the Azure portal.
- From the Decisions Studio, navigate to System > Integrations > OAuth > Providers, and click ADD OAUTH PROVIDER.
- From the Add OAuth Provider window, provide the desired Name. Under Provider Settings > OAuth Version, select OAuth2.
- Input "https://login.microsoftonline.com/common/oauth2/v2.0/token" under Token Request URL, and "https://login.microsoftonline.com/common/oauth2/v2.0/authorize" under Authorize URL.
- Provide the Default Consumer Key and Callback URL. Then input the Default Consumer Secret Key. Then click SAVE. Consumer Keys and Callback URLThe Callback URL should be the Redirect URI for the Application.
The two keys are as follows:- The Default Consumer Key is the Application Client ID that can be found under the Overview page for the Application in Azure.
- The Default Consumer Secret Key is found under the Certificates & secrets page of the Application.
Navigate to System > Integrations > OAuth > Tokens. Then, click CREATE TOKEN.
From the Create and Store OAuth Credentials window, provide a Token Name and select the recently created Provider from the Providers dropdown. Under OAuth Flow, select Authorization Code. Provide the Scope for the Token; in this case, "https://graph.microsoft.com/User.Read https://graph.microsoft.com/Group.Read.All https://graph.microsoft.com/Group.ReadWrite.All".
Click Request Token, after the Token has been successfully requested, click OK.
Example B: Setting up Integration
- From a Designer Folder in Decisions Studio, click CREATE DATATYPES/INTEGRATION; from the subsequent popup, select External Services > Add REST Service.
- From the Add REST Service window, provide the desired Service Name. Under Service URL, input "https://graph.microsoft.com/v1.0". Under Authentication, select Use OAuth. Then, check the Use Custom Tag in Auth Header box; in the Custom Tag for Auth Header box, input "Bearer". Then click OK.
- From the newly created REST Service's Folder, select All > Add Method to Service. From the New REST Service Method window, provide a Name, then if desired, a Description. Under URL (Relative to Base), input "- /teams/{teamid}/channels/{channelid}/messages". Note on URLThe Team and Channel ID's represent the unique value belonging to the integrated channel.
To obtain the Team ID, navigate to Microsoft Teams, click the ellipses beside the Team Name, and select Get link to team. Copy the Group ID from the resulting URL.
To get the Channel ID, select the ellipses beside the Channel Name and click Get link to channel. Then copy the text between "channel/" and "/{CHANNELNAME} from the URL. Under HTTP Method, select POST. Under Content Type, select JSON. Then select Get String From Flow under Request Body Format and Raw Value for Output Type. Click OK to save and close.
Example C: Integration Flow
The following example demonstrates how to create a Flow to integrate with Microsoft Teams to send a message in a designated Channel.
To do so:
- Navigate to a Designer Project and select CREATE FLOW from the Global Action Bar. Then, CREATE a new Flow.
- From the FlowDesigner, from Toolbox > Data > Text, attach a Custom Merge [NVelocity] step to the Start step.
- From the Properties tab of the Custom Merge step, map the JSON text below to Template. Then Constant map the desired Message.
{ "body": { "content": "$Message" } }
Navigate to Steps > Integration > Rest Services > [REST SERVICE NAME], and attach the REST Service step to the Custom Merge step. From the Properties tab of the REST Service, set the OAuth Token Input to Constant, and select the respective Token from the dropdown. Then Select From Flow map MergedString to Request Body.
Connect both the Done and Error paths to the End step. Save the Flow, then if desired Close the Designer.
Debug
To Debug and test the Flow:
- From the Flow Designer, select the Debug link, then click FULL.
- After the Flow runs, verify that the Message sent by navigating to the Channel in Microsoft Teams and checking the Posts tab.