Creating bots in seconds!
Published: 2019-11-02 19:14:12

Halloween has been and gone, which means Christmas is coming!! And I wanted to be the first blogger on DEV to release a Christmassy blog 🤣 &mdash; much to the annoyance of the scrooges out there!

Recently I've been doing a tonne of bot development both at home and at work and been absolutely loving it &mdash; bots that integrate with Alexa, Google Home, Luis.ai and more.

During this time I've done quite a bit of research into the best and quickest methods to create bots and was pretty shocked when I bumped into [Microsoft Flow.](https://www.google.com/search?q=microsoft+flow&oq=microsoft+flow&aqs=chrome.0.69i59j35i39j69i60l3j69i65.2863j0j7&sourceid=chrome&ie=UTF-8) Microsoft flow is cloud-based software that allows you to easily automate workflows and tasks across multiple applications and services. For me, the ability to really quickly auth with multiple apps instantly has made the process so much more enjoyable allowing me to spend more time on what I want the bot to do.


# Let's create a twitter bot!

I've just created a new twitter account [@GrinchEndOfFilm](https://twitter.com/GrinchEndOfFilm) because we want our bot to love Christmas and spread as much Christmas cheer as possible!

![The Grinch Bot](https://i.imgur.com/g2Gy5XS.png)

The first thing we need to do is sign up to Microsoft Flow which can be done [here!](https://emea.flow.microsoft.com/)

Once we're all set up we can create a new flow:
![Image of the flows](https://i.imgur.com/YMocL3F.png)
There are 4 types of flow to choose from, the two that we're going to look at in this blog are:
- Automated Flow: Triggered by an event &mdash; our trigger is going to be when somebody tweets about Christmas!
- Scheduled Flow: So you choose when and how often your flow runs &mdash; we're going to create a flow that tweets how many days until Christmas and it's going to do that every day.


# Creating an Automated flow! (Super Simple)

 **Goal**: Create a bot which retweets lovely Christmas tweets

So our bot flow is going to be called *SpreadChristmasCheer* with a trigger of when somebody tweets.

![Creating an automated flow](https://i.imgur.com/FJiXrVH.png)

When you click create you'll be presented with a lovely UI view of your bot flow so far. I want my bot to trigger when somebody tweets with the words "I" "love" "Christmas" in them:

![https://i.imgur.com/zYYRpYI.png](https://i.imgur.com/zYYRpYI.png)

And I want to just simply retweet them. So I click the + New Step button under the flow and create another twitter step with the action of *Retweet*.

![Retweet step too](https://i.imgur.com/BNNPgUc.png)

I then need to choose the tweet id of the tweet I want to retweet, luckily Microsoft Flow provides you with a list of related variables.
![Tweet id](https://i.imgur.com/mof21fq.png)

A quick save and test and it should be running!

![A nice tweet about christmas](https://i.imgur.com/hUhC7n5.png)

And there we have it, our Grinch (At the end of the film) has retweeted a pretty lovely tweet about Christmas 😄.


There is so much more you could do with this flow, for instance, you could easily implement some sentiment analysis on the tweet to be sure that it's actually a positive tweet about Christmas &mdash; that could easily be done by integrating the bot flow with Text Analytics which has an option for sentiment analysis.


# Creating a Scheduled Flow

 **Goal**: Create a bot that tweets every day the number of days until Christmas.

This one is going to be a little more complicated, not because creating a schedule flow is any more difficult than an automated one I'm just going to add a few pointless steps to show some features of Microsoft Flow!

![The number of days until Christmas bot flow](https://i.imgur.com/rAhPV6J.png)

The first step is going to be getting a Calendar event from my google calendars account, this event is Christmas &mdash; This is a pointless step as I am literally only going to use this event's name  (Christmas) as an output to the tweet). It's just purely to show how quickly you can integrate other accounts and services, having to code this up would take ages, well, for me, it would.

![https://i.imgur.com/NjmmW7K.png](https://i.imgur.com/NjmmW7K.png)

Next, I want to call an endpoint I've created using Nodejs which will return the number of days until Christmas. Microsoft Flow has an action called HTTP
![https://i.imgur.com/jIK3mVb.png](https://i.imgur.com/DDeovzp.png)

My endpoint returns some JSON, and in that JSON one of the values is the number of days until Christmas, I want to grab that value &mdash; luckily Microsoft Flow has an action which parses JSON for us and pops the values into variables we can use in other steps.


![https://i.imgur.com/dPY2RWi.png](https://i.imgur.com/dPY2RWi.png)

It asks for the content, which is the data we get in the body of the http request:

![](https://i.imgur.com/2VgxPib.png)

You can use an example payload to generate the Schema:

![](https://i.imgur.com/QQtfFbY.png)

Lastly, let's add a step to post a tweet.

The `current` variable is the store value from the JSON which has the number of days until Christmas in it! And the `Event Title` is event from the Google Calendar integration.
![](https://i.imgur.com/YGEOyXz.png)

Let's save this and get it running!

![](https://i.imgur.com/21ZKjqi.png)

# Conclusion
And there we have it! This is just a very basic introduction to what you can do with Microsoft Flow, there are hundreds of actions and integrations available. Pretty much any kind of flow you want there will be some way to create it.

Like I said, I'm new to this too but am finding it very, very fast and effective. 

Thank you, if you like my rambling check out my personal blogging site at https://codeheir.com/