Site icon UnofficialSF

Use Flows to Post Messages to Microsoft Teams

This new extension provides support for:

Post Message to MS Teams
Create Teams Channel
Invite User to Teams Channel
Kick User from Teams Channel
Delete Teams Channel

Post Message to MS Teams

The Message data structure is discussed here: https://docs.microsoft.com/en-us/graph/api/resources/chatmessage?view=graph-rest-1.0

Input Properties

subject
body


Output Properties
messageId
errorText

The only Teams inputs we will support in this first version are Subject and Body. They should be string inputs on the action.
Verify that rich text entered into a Flow Text Template can be passed by reference into the Body of this action and the formatting is retained in the posting on Teams.

If an error is returned extract the most readable part of the error text and return it in the ErrorText output attribute

Create Teams Channel

Input Properties
displayName
description
membershipType

Output Properties
same as for ‘Post Message’, above, except call it ‘ChannelId’

Invite User to Teams Channel

This Teams API takes a huge User object, but we’ll just have our action take an id String initially. Convert it to the expected User structure

Input Properties
userid
channelId

Output Properties
errorText

Kick User from Teams Channel

Input Properties
channelId
userId

Output Properties
errorText

Delete Teams Channel

Input Properties
channelId

Output Properties
errorText

Authentication

setting up authentication to make calls to the Microsoft Graph API (which is what MS Teams relies on)is challenging but anyone who administers Teams will probably be familiar with the process. Currently, the only tokens we’ve tested this with are developer tokens that last for 1 hour and have to be refreshed, and the tokens are generated through a complex process involving HTTP and a rig like Postman.

Here’s the Postman configuration that I use to generate valid auth tokens:

All access to Teams starts with an Azure App. This produces the clientID and TenantID

You combine that app id info with a client secret to create an environment that you use to get a temporary access token:

You can generate Client Secrets from the Azure App management UI:

This gives you the access token. Teams actions also usually require IDs for the Team and Channel:

You can generally extract these values from the URLs found in Teams:

https://teams.microsoft.com/l/channel/19%3ac44259973e3a444ebcb82aeb0d5b272f%40thread.tacv2/General?groupId=cc3f17a9-b923-468b-96bf-4fb29057976a&tenantId=168867c6-0022-4fde-92ab-591b3813d528

However, you have to watch out for the encoding. In the example above, the channelID that Flow would expect is

19:c44259973e3a444ebcb82aeb0d5b272f@thread.tacv2

and the teamsID is referred to here as the groupID and Flow would expect;

cc3f17a9-b923-468b-96bf-4fb29057976a

There is certainly a better way to extract these ID’s! This is an area where I’m sadly ignorant, and Teams experts are encouraged to comment on this post with improvements to these docs.

Install

Prerequisites

Install: Flow Actions Base Pack minimum version 3.15
Install: Flow Screen Components Base Pack minimum version 3.3.1
Install: Datatable minimum version 4.0.3

Version 1.1 12/9/23 Production Sandbox updated to work with latest generation Base Packs and Data Table

View Source

Source

Exit mobile version
Skip to toolbar