Yammer Moderation Using MS Flow

MODERATE YAMMER FOR PROFANITY USING MS FLOW

 
If you want to handle inappropriate/ offensive posts on yammer in your tenant, then the combination of Azure Cognitive Services and MS Flow is the right choice.

Scenario

The admin in the organization wants to get notified if people post certain monitored keywords (racist, adult content, rival organization names etc.). Also, such posts should be auto-deleted without any human intervention.

Accounts you will require

You will require a valid account, license, and admin rights for the below-mentioned tools.

  1. Office 365: https://login.microsoftonline.com/ : O365 Plan should include a valid license for yammer, flow, and Outlook.
  2. Azure: https://portal.azure.com/
  3. Content moderator human review tool: (Optional) https://contentmoderator.cognitive.microsoft.com/

Note
Create an account on O365 and Azure with the same Microsoft account.

Your MS Flow will be integrated with Azure Content Moderator API and Outlook.

Environment setup
  1. Register to Azure content moderator cognitive service
    This service will analyze text, image, and video content for material that is potentially offensive, risky, or otherwise undesirable. When such material is found, the service applies appropriate labels (flags) to the content.
  2. Register on Content Moderator human review tool: (Optional)
    You can use this tool so human moderators can make the final moderation decisions. You can set up team reviews of text, image, and video content, according to filters that you specify. The human input does not train the service, but the combined work of the service and human review teams allows developers to strike the right balance between efficiency and accuracy.
  3. Get yammer authorization token
    This token will be required for REST calls to yammer from MS Flow.
  4. Create Azure Term list: (Optional)
    Azure term list will store blocked keywords relevant to your organization. You can skip this if you do not wish to add organization relevant keywords.
  5. Create MS Flow
    This is the final step to achieve your goal. You can select MS Flow trigger either for a group or for feeds you follow.

So, let’s begin the endeavor...!!!
 

Register to Azure Content Moderator Cognitive Service

  1. Assuming you have a valid subscription to Azure Portal, navigate to https://portal.azure.com/ .
  2. Click on Create a resource (‘+’ symbol) from left navigation, to create new resource. Search for ‘Content Moderator’ in ‘Search the Marketplace’ bar.
  3. The below cognitive service will be populated. Click on ‘Create’ button.
  4. The user will be prompted to fill in mandatory fields to register for service as below,

    1. Name: Use a unique name for your service.
    2. Subscription: Choose valid subscription from the dropdown.
    3. Location: Choose the nearest location available to your area. (This denotes location where your resources will be residing).
    4. Pricing tier: You can choose F0 pricing tier as it is a free trial version 
    5. Resource group: You can create a new resource group or use the existing one. You can create a resource group from the article: create new resource group.

  5. Note and copy one of the subscription keys from ‘Grab your Keys’ section and endpoint from ‘Make an API call to this endpoint’ section. This piece of information will be used in upcoming steps.

Get yammer authorization token

You can follow the below yammer developer article to create yammer authorization token:

https://developer.yammer.com/docs/test-token

As I used in SharePoint environment, I have used the website and redirected the URI relevant to SharePoint. You are free to use your company/relevant website for these values except localhost.

Click on continue and ta-da… your app is registered. You will get a window with the client ID, client secret as below:

Create Term List

The below amazing GitHub article explains in detail how to create, view, update, delete term lists:

https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/cognitive-services/Content-Moderator/term-lists-quickstart-dotnet.md

To create a term list, download GitHub application. In Program.cs file, change Subscription key (You will get this from your Azure portal and navigating to Content moderator resource) and Azure region (e.g. central India) as per your Azure cognitive service subscription. After executing console application, Term list ID will be displayed. Note this term list ID.

Create MS Flow for Yammer text moderation

 
MS Flow provides ready to use flow template: Yammer moderation for profanity. Alternatively, you can choose trigger and template you would like from yammer + flow templates.

Below are changes you will need to do to make the ‘yammer moderation for profanity’ template work.

  1. You need to add a connection for ‘Content Moderator’ as prompted.

    Add subscription API Key and endpoint copied after registering to ‘Content moderator cognitive service’ as shown below,

  2. Select Network Id from the populated dropdown. Click on ‘Edit’ link next to ‘Using the default values for the parameters.’ and Group Id field will be populated. Delete string function which is available by default and a select group from the populated dropdown.

  3. Find the action ‘detect profanity and match against custom and shared blacklists (preview)’. Add List-id of term list created by running console application in ‘Create Termlist’.

  4. You can send flagged content to ‘Content moderator human review tool’ or you can delete an offensive post.

To send content to ‘Content moderator human review tool’

Find the action ‘Create Reviews for Reviewers in your moderation team’. Add the below mandatory values:

  • Team Name
    This is the review team you created in https://contentmoderator.cognitive.microsoft.com/.

  • Content Type
    This is the type of content you are passing for review.

  • Review content
    In this case, it is yammer text. (You can select ‘Message List Message Text’ from ‘Add dynamic content’ wizard).

  • Content Id
    In this case, it is Yammer message ID. (You can select ‘Message List Message Text’ from ‘Add dynamic content’ wizard).

To delete Yammer post automatically

Add an action ‘HTTP’ to delete the offensive post. Fill in mandatory fields as below,

  • Method - DELETE
  • URI - https://www.yammer.com/api/v1/messages/ (Add ‘Message List Message ID’ from dynamic content).
  • Headers,
accept*/*
authorizationBearer Enter_yammer_Authorization_token
accept-encodinggzip
content-typeApplication/json
content-length2

You can refer to this amazing article for REST calls to Yammer:

https://techcommunity.microsoft.com/t5/Yammer/Moved-Joined-Messages/td-p/9459