Monday, February 8, 2021

Support for channel moderation in Microsoft Graph

Microsoft release recently support for channel moderation via Microsoft Graph Teams APIs. This allows administrators to read and apply channel moderation settings programmatically. The feature itself has already been there since a while. However, API support wasn’t available in Microsoft Graph before. In this blog post, I will demonstrate how to use this new functionality and what limitations I faced while testing this new approach.


Benefits of channel moderation

A Microsoft Teams team consists of one or more channels. A channel is the place where chat based communication and content sharing happens. Previously, team members or everyone (including guests) have been able to start a new channel post, which represents channel moderation equals OFF. Now, team owners are capable of turning channel moderation ON which allows them to limit the posting of new posts to only moderators, with additional control options. This becomes handy if a channel should only by used for announcements or if only a specific users should be allowed to start posts in a channel.

Read channel moderation settings

Reading channel moderation settings is only possible with a Microsoft Graph beta API. Please, keep in mind that beta APIs are subject to change and its usage in production environments are not recommended! That being said, you can use the already existing GET channel API to retrieve the channelModerationSettings which is part of the response. This is what the API and the response look like:

GET https://graph.microsoft.com/beta/teams/{id}/channels/{id}
{
   "@odata.context":"https://graph.microsoft.com/beta/$metadata#teams...",
   "id":"...",
   "createdDateTime":"2020-01-09T19:05:27.498Z",
   "displayName":"Test",
   "description":null,
   "isFavoriteByDefault":false,
   "email":"",
   "webUrl":"https://teams.microsoft.com/l/channel...",
   "membershipType":"standard",
   "moderationSettings":{
      "userNewMessageRestriction":"moderators",
      "replyRestriction":"everyone",
      "allowNewMessageFromBots":true,
      "allowNewMessageFromConnectors":false
   }
}

Note: During my tests, I wasn’t able to get moderation settings of the General channel! The moderationSettings object was always returned with a value of null

Applying channel moderation settings

In case you want to apply channel moderation settings programmatically, you can either update an existing channel or apply the moderation settings while creating a new channel. Note that currently only beta API support is available! The example below shows how to apply moderation settings while creating a new channel:

https://graph.microsoft.com/beta/teams/{id}/channels/
{ "description":"description-value", "displayName":"test 2", "membershipType":"standard", "moderationSettings":{ "userNewMessageRestriction":"moderators", "replyRestriction":"everyone", "allowNewMessageFromBots":true, "allowNewMessageFromConnectors":false } }

Channel moderation is a good improvement in Microsoft Teams and opens new scenarios while giving more control to team members. This new API support brings flexibility to administrators and developers.

I hope it helps!
Thanks for reading my blog post.

No comments:

Post a Comment