Using Flow to Delete #Joined Messages in All Company Group of Yammer | Quisitive
Using Flow to Delete #Joined Messages in All Company Group of Yammer
May 24, 2016
I wanted to post this to the blog to increase the signal and share the knowledge.

Huge kudos to Tom Kretzmer (MVP) for the idea and how to on this one.

I wanted to post this to the blog to increase the signal and share the knowledge.

The problem

Yammer has this great functionality that automatically post a message to the All Company group whenever a new person joins Yammer.  It looks something like:


This is a great feature to welcome new users into the Yammer fold and to direct them to the Day One or Yammer 101 group.  The problem comes in when you have a very large network, or when you are launching Yammer and a lot of people are joining the feed can get overwhelmed with #joined messages.  If your network crosses the 20,000 user threshold, then Microsoft will automatically disable the #joined messages, but until then they can be annoying and you cannot turn them off.

The Old Solution

In the past the best way to get rid of them was to export your Yammer messages, identify all the ones that were #joined and then grab the messageID and pass that to a PowerShell script that would remove them.  H/T again to Tom Kreztmer (MVP).  Here is the PowerShell that he developed:

12345678910111213141516171819#PowerShell Script to Delete Messages $token = “<Token>” $Headers = @{ “Accept” = “*/*” “Authorization” = “Bearer “+$token “accept-encoding” = “gzip” “content-type”=”application/json” “content-length” = “2” } #import Message ID’s that need removed. $messages = import-csv C:YammerMessagesToDelete.csv $messages = $ #loop through all Message ID’s foreach ($message in $messages){ $uri = “$message” (Invoke-WebRequest -Uri $uri -Method Delete -Headers $Headers).content | ConvertFrom-Json }

Flow to the Rescue

But now Microsoft has released Flow.  Flow allows us to interact with Yammer directly so there should be a way to do this.  There is, but there are a few issues.  First off, you need to sign up for Microsoft Flow to get into the free preview.  From there you can create no-code solutions that are like simple workflows that run against workloads in the cloud, or other locations.  In this case we want to create a new Flow


This will take you the initiation selection screen.  Here you are picking how to kick off the Flow.  There are a number of options and as you look through this you will see a bunch of other ideas for how to use Flow, but for our purposes the two we care about are all the way at the bottom.


Now, we all know that All Company is a group, so that makes sense.  However, if we select that option, All Company does not exist.


There doesn’t appear to be a Group ID for the All Company group, so we have to look at the other initiator for Yammer, the Following Feed.  To make that work, we need to make sure that we follow the #joined topic.  That way the messages will appear in our feed and then we can use the Following initiator.  The Group initiator would have only fired off for messages in that group, but this will fire off every time a message appears in our following feed, so the first thing we need to do next is to add a condition to our incoming message.Addcondition

We need to add in the condition that we want this to fire off because of.  We could just use the #joined topic tag, but that might cause other problems, so let’s use as much text as we can.  In this case I selected “has #joined the [Network Name] network because that is the text of the #joined message.  The more exact the text, the less likely of a mistaken deletion.


If the condition is false we don’t want to do anything, so that branch is complete.  However if we match, then we want to delete the message.  The question is…do we first want to move it someplace else.  If we do, then we have to change the message text or the flow will fire on the new message and we don’t want that.  Instead of porting to to another Yammer group, we could add it to a SharePoint Online List via Flow, but for my purposes, I just want it gone, so I skip that step and go straight to the deletion by using the Yammer REST API Delete method.

A Brief Segue, Getting a Yammer Token

OK, so you want to use the REST API and you never have before.  To accomplish this you have to create a Yammer Token.  This isn’t hard, but the documentation is confusing and won’t work, at least it didn’t for me.  You have to create a Yammer Test Token and this page tells you how.  There are two things that didn’t work for me.  First off, Step 5 says to type the following into your browser:[:client_id]&redirect_uri=[:redirect_uri]

From the document the Client_ID is taken from the page, and the Redirect URL is the URL of the Application you are registering.  However whenever I pass the Redirect_URL it throws an error.  My solution was to just leave that off and it works just fine.

The next confusion point was in getting the token that we will use in the headers.  The JSON you get back looks something like this:

1234567891011121314151617181920{  “access_token”:  {    “user_id”:1234369302,    “network_id”:3343673,    “network_permalink”:””,    “network_name”:”Network Name”,    “token”:”312344-Fr5351DFRsAcr7v7sIcDVg”,    “view_members”:true,    “view_groups”:true,    “view_messages”:true,    “view_subscriptions”:true,    “modify_subscriptions”:true,    “modify_messages”:true,    “view_tags”:true,    “created_at”:”2016/05/21 14:28:49 +0000″,    “authorized_at”:”2016/05/21 14:28:49 +0000″,    “expires_at”:null  }}

Now the documentation most times shows the token as “Fr5351DFRsAcr7v7sIcDVg”, but mine had the “312344-” in front of it.  I’m not sure why, but I THINK it is because we are using the O365 Identity for our accounts.  At any rate, you need to have that full token to make this work


Now we are ready for the last bit.  The REST API call.  In our action we will add an HTML call


Then we will configure it like below:


Note that you use the MessageID from the message that initiated this, make it a DELETE call and pass the headers to include your token to make sure this is authorized.

After that Name and Save your flow and it will work.