When David met Microsoft Flow
Microsoft Flow is the entry level workflow product built-in to Office365.
It promises that normal people, not developers, can connect systems and automate processes using workflow, and without code.
There is so much press around Robotic Process Automation (RPA), that I thought I would give it a go.
I wanted to see how realistic it would be for SME and Midmarket business to do basic automations. They are the ones most under threat from the massive RPA investments being made by Enterprise. RPA is lessening the cost curve for organisations that are introducing it, and so I wanted to see if Microsoft Flow could level the playing field for users of Office 365 and Azure.
We do have developers at Within Reach Software, but I am not one, so this was strictly an unassisted experiment.
I decided I would attempt something that might be relevant to any size business; to automate a social media activity.
What I aimed to do was to scan Twitter for any mention of certain key words and to retweet those out with an added hashtag of my own.
Here's how I got along.
Hands on with Flow
Whilst there are templates for common automations, there isnt one for this scenario and anyway I wanted to create one from scratch.
The first thing that I needed to do was to trigger the flow.
I selected the triggers for Twitter and found there was only one, to "Tweet when a new tweet is posted" so I chose and configured that one.
The next thing I needed was an action
There are 9 actions for Twitter, but interestingly they don’t reflect what a user would typically do.
For example there is no retweet, favourite, comment, or quote so the only option to work with for my scenario is Post a tweet.
If I had wanted to make up my own Tweet with the same text every time, this step would be easy. Since I want to retweet though I need to include "dynamic content" which will vary every time the flow is triggered.
Figuring out what the dynamic content labels actually relate to what data is not obvious. The descriptions are very brief and there are multiple options that might correspond to what you are looking for.
For example to get the twitter handle of the original poster what choice should we make from the 6 different possible user names we are presented with?
The only way I found to resolve this was trial and error, and I settled for in_reply_to_user_id
Once I had triggered the flow, I realised 2 things; one was that I had created a loop. The new retweet also matched the criteria that triggers the flow, and so the retweet would be sent (slightly elongated) over and over again. The second issue was that the value of in_reply_to_user_id was blank.
The first issue required the use of a condition to break the cycle. I needed to check that the tweet triggering the flow did not in fact come from me before retweeting it. This condition was easy to create and I was able to drag my existing action into it which was nice not to have to retype it.
For the second issue I replaced in_reply_to_user_id with UserName in both the condition and the action.
Then it was time for another test run.
This time the result was much closer. Just one tweet, and almost what I wanted, except UserName has no '@' sign and so will not link back to the original poster. I thought perhaps I had picked the wrong choice of dynamic content again and tried the other options, but UserName is the correct option and just the '@' is missing.
No problem, I can just add "@" as text in the action.
And then a very strange thing happened…..
It seems that '@' is a special character in Microsoft Flow, and is interpreted as the start of a function or parameter, a bit like the '=' at the start of a cell formula in excel.
A quick google showed that other people had the same problem, and this took me briefly into the world of Workflow Definition Language (WDL as the techies would shorten it to).
If you are really curious you can find out all about WDL here https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language but trust me it is a place that no non-developer wants to go.
Tools like Flow are about productivity so I settled on getting close enough to what I wanted and left WDL well alone.
What about IFTTT?
Not being 100% successful, I would have been somewhat negative about Microsoft Flow had things ended there. It was running through my mind that this was so much harder than doing the same thing in If-This-Then-That (IFTTT) which serves a similar purpose. This bothered me and so I fired up my IFTTT user and tried to do exactly the same automation.
To my surprise there was no pre-existing recipe for this which is unusual as it is a common task. No problem, I would start from scratch and follow the same logic as previously above.
Configuring the Twitter search was straightforward, and then based on my lesson about repetitive retweets, I would have needed a condition. IFTTT doesn’t have those, so that would have been a problem, however, I thought I would push on and at least prove the retweet was simple. To my surprise this was not so. IFTTT does not allow the addition of my own hashtag to a retweet, and even if it did, a search based on tweet criteria, followed by a retweet is not allowed (perhaps because it will repeat and repeat).
Based on this I felt much better about some of my conclusions about Microsoft Flow.
Microsoft Flow is suitable for non-developers and you can get meaningful automation done through the user interface without needing any code.
Like any productivity tool you have to know when to quit or when to call in an expert. I am sure with the help of a developer I could have got the '@' into our tweet if it was worth the time and cost.
Microsoft Flow is not a primitive tool. The availability of conditions, loops, scopes and branches allows for very complex logic to be implemented if and when it's needed.
Be prepared to iterate to find the correct dynamic values for your needs and to get your flow logic right. Even this simple automation needed conditions and several attempts to get the output right.
Debugging is well supported. When the flow fails, there is quite a bit of information provided to indicate why.
Most importantly, Microsoft Flow can not only level the playing field for SME and Midsize organisations against Enterprise, but it could keep them ahead by delivering the kind of agility at low cost of entry and low total cost of ownership that Enterprise typically don’t have.
If you are considering automated workflow or robotic process automation and need assistance, or if you have started and outgrown your capability with Microsoft Flow please give Within Reach Software the opportunity to help your business reach peak performance.
In a cruel twist of fate the weekend following my automation, Ashley Madison the adultery website agreed to pay $11.2 million to it's users affected by a huge data breach.
Seemingly unrelated to the topic of Microsoft Flows this actually caused something of a problem because in announcing this, Reuters used the combination of keywords I was searching Twitter for in my autotweeting flow.
The amount of activity went wild.
For every tweet and retweet about this globally (and there were many) my flow diligently found and tweeted them out. Hundreds of tweets went out very very efficiently!
This meant that I needed to throttle the flow in some way to prevent this situation from happening again.
....and this took me into the realm of the dreaded Workflow Definition Language (WDL) mentioned before.
As suspected Microsoft Flow WDL is not that easy to get working with date comparisons which is what I wanted to do.
I aimed to compare the time of the newly found tweet with the time of my last tweet, and to limit my tweets to one every 15 minutes.
The first step was to get the time of my last tweet.
Then I needed to add 15 minutes (or 900 seconds) to this and compare with the time of the new tweet.
This is where the fun began.
There is a WDL function to @addseconds to a date/time but the required syntax in Microsoft Flow is not that easy to work out, and the documentation is not very helpful.
Eventually, and this was after several hours of fiddling, I got the right logic in place.
The user timeline returns an array of tweet times even though I set maximum results to 1. Because of this the Microsoft Flow editor inserts an "Apply to each" container. Since I only retrieve my very latest tweet time, the "Apply to each" will only ever execute once.
Inside of that is my time comparison. The logic checks that my last tweet time is at least 15 minutes earlier than the new tweet time.
I decided to subtract 900 seconds from the new tweet time triggerBody()?['CreatedAtIso'] as I was continually getting syntax errors with when I tried to add 900 seconds to my last tweet time in items('Apply_to_each')?[CreatedAtIso]. Logically both provide the same result so either way is fine.
As part of this process I found that composing values and writing them to an Excel file in OneDrive was a good way to see what was going on with the interpretation of functions and dynamic content.
So now we have a Microsoft Flow that retweets after finding keywords, and is throttled to tweet only once every 15 minutes.
If you would like to automate repetitive processes in your business, please contact us at Within Reach Software to find out how Microsoft Flow could be the solution to your problem.