Burgers & Bytes
February 12, 2024

Using Microsoft Graph and Power Automate to post an Announcement Message in Teams channel

Feb 12, 2024  •  3   • 440 
Table of contents

Scenario

This blog describes the Flow to create a Team and start with a message of type Announcement. The default ‘Post a message in a chat or channel’ isn’t sufficient, because the message type can’t be selected, so it can’t be an Announcement.

The end result should be a clear message in a Teams channel: Announcement

Flow actions to create Team

In order to share the full story the Team needs to be created and Team ID and Channel ID needs to be stored in a variable. To read the details collapse these steps below:

Full Flow steps

The Team is created using these steps: The ‘initialize var Teamname’ and ‘Initialize var ChannelID’ are variables of type string. Create Team Create Team Get the ID of the newly created team. Create Team

Get the ChannelID of the General channel and store that in the variable.

ChannelID ChannelID

Add a member to the newly create team. Add member

As a preparation for the content of the message the list of members is set up in HTML format.

MembersList

Invoke an HTTP Request

To post the announcement message add the action Invoke an HTTP Request. For both the Base Resource URL and Entra ID Resource URI you can enter: https://graph.microsoft.com

Graph authentication

The Url of the request is, for which team-id and channel-id are replaced for the corresponding variables:

https://graph.microsoft.com/v1.0/teams/team-id/channels/channel-id/messages

The ‘Invoke an HTTP Request’: Invoke HTTP Request

The body of the request contains all the information needed for the message to set up correctly. The body content of the message is in HTML format, so you can use your own creativity. In this example a hyperlink to a manual and a list of added members is configured.

For both the body content and attachments id the same GUID needs to be set. Therefor use a variable with expression guid(), so both locations have the same GUID.

{
  "subject": "Team for @{variables('Teamname')}",
  "body": {
    "contentType": "html",
    "content": "<attachment id=\"@{variables('GUID')}\"></attachment>Welcome in this team. <br><br>You have access to the planner, files and OneNote.<br><br>The user manual can be found<a href='link'> here</a>. <br><br>  The following users were added when the project was created:<br> <ul>@{variables('MembersList')}</ul>"
  },
  "attachments": [
    {
      "id": "@{variables('GUID')}",
      "contentType": "application/vnd.microsoft.teams.messaging-announcementBanner",
      "contentUrl": null,
      "content": "{\"title\":\"This is an Announcement\",\"cardImageType\":\"colorTheme\",\"cardImageDetails\":{\"colorTheme\":\"mulberryred\"}}",
      "name": null,
      "thumbnailUrl": null,
      "teamsAppId": null
    }
  ]
}

In the attachments>content the colorTheme can be defined. colorTheme

Color names you can choose from:

Delegated or application only permissions

Unfortunately at this moment you can’t use application-only permissions to achieve this. Following the documentation you should be apply to Post a message while creating a Team in migration mode. Currently the Announcement type is out-of-scope.

comments powered by Disqus
Empowering productivity - one blog at a time!