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 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

Step 1) Install Required Support Packages

This extension requires the following extensions, which should be installed first, in order. If you already have these extensions then you may not need to install them. However, you may need to upgrade them.
Install: Flow Actions Base Pack minimum version 2.16
Install: Flow Screen Components Base Pack minimum version 2.2
Install: Datatable minimum version 3.0.10

Step 2) Install MSTeamsActions

Version 1.0.0 Unmanaged 4/1

View Source

Source

Skip to toolbar