Want to auto-tweet ? Here’s a way to do it with a Flow

1

I figured this one was valuable enough to copy over here 😉

As per my recent blogpost.

While I’m away

The trigger for this post is simple.. I’m heading into a well deserved summer vacation where I want to remain active in some of the social medias while being able to just relax and enjoy life!

So, I figured that building an automated Flow which would capture tweets of interest (based on keyword search) and then retweet them out with a specified delay could well do the job!

This would allow me to put content in my feed, adding value to the original tweets by issuing my message later on, thus maybe appearing on someone’s radar who would not have caught the original post.

Issue

The twitter connector, as of now, doesn’t offer an action to retweet nor does it allow to include direct references to users / authors (@xxx). So in order to point back to the original post I had to build the twitter URL to it. I also included a signature note where I thank the author and notify the readers of this issue.

I’ve added this functionality as one of my project goals. Creating a custom connectors will probably allow me to resolve this. Right now, no time, so let’s just do it in a quick and dirty way and solve this out when I’m back on the saddle after drinking all the margaritas in the world 😉

Flow

Overall, here are the core functions that my Flow will execute:

  • Act on tweets that use predefined keywords, for example:
    • #powerapps
    • #powerplatform
    • #poweraddicts
  • Only process original tweets (I don’t want to overflood the feed by considering RTs)
  • Only process other people’s tweets (that’d be kind of awkward if I’d process my tweets)
  • Manage and process French and English tweets only
  • Keep track of the tweets I re-posted as a reference for later BI / processing

Prerequisite

Since I want to have a log of the tweets I posted with the references to the original post as well as the posted message the Flow generated, I created an entity in CDS.

Flow details

  • Trigger: Twitter – When a new tweet is posted

  • Criteria: set the Search text criteria to
    • #powerapps OR #powerplatform OR #microsoftflow OR #poweraddicts”

  • Initialize variables required in the flow
    • baseMsg : the new message to post (based on the language of the original tweet)
    • linkToTweet : the URL to the original tweet
    • proceedTweet : Boolean flag to allow to stop the Flow if not a supported language

  • Only proceed on original tweets (if RetweetCount = 0)

  • Only proceed with tweets from other authors (if TweetedBy is not equal to ZePowerDiver)

  • Look for tweets in French to adapt the message accordingly (if TweetLanguageCode = fr)

  • Assemble the message and assign it to the baseMsg variable
    • insert the linkToTweet variable for the URL to the original tweet
    • insert the User detail’s full name (Original tweet user full name)
    • insert their tagname too (Tweeted by)

  • If not in French, then validate if it’s in English (if TweetLanguageCode = en)

    • If so, assemble the message and assign it to the baseMsg variable
      • insert the linkToTweet variable for the URL to the original tweet
      • insert the User detail’s full name (Original tweet user full name)
      • insert their tagname too (Tweeted by)

 

  • Otherwise, set the proceedTweet variable to false so the post will not be processed at next step

  • at the outcome of the previous steps, validate that proceedTweet is still True

  • if we can proceed, then inject a delay of (n) hours, as per your preference, then post the tweet using the baseMsg variable as the Tweet text
    • For the injection of the delay, the calculation is based on current time as follow:
    • addHours(utcNow(),1)

  • Last step is to insert a new record in my CDS entity to track history

Last minute modifications

After testing the flow, letting it run for a while I made a few adjustments to ensure the posted tweet would be of a maximum of 280 characters, otherwise an error is thrown by the connector.

  • First modification: I added a call to bit.ly to generate a shorter url to the original tweet

  • Second modification: I shortened the baseMsg in both languages to be right to the point nothing more

  • Third modification: as a safety net, I applied a substring function to the baseMsg variable submitted to the Twitter action
    • substring(variables(‘baseMsg’),1,280)

And then the failure!

After implementing those last minute changes I looked back at the generated tweets and noticed that the preview feature that you normally get with the embedded links disappeared!

So, to quickly resolve this, I’ve removed the bit.ly part of the connector, but left the substring part.

Next step

To resolve the constraints regarding the RTs and tagging, which are due to anti-spam rules from twitter, I will attempt to follow Tomas Poszytek’s blog post (that I’ve seen on my twitter radar yesterday while finishing up the details of this article)

Keep on diving!

Choose your Reaction!
Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.