Advanced | Flow of the Week: Using Flow in a LiveTiles Bots approval bot
Hey Flow Fans!
This week's Flow of the Week article comes from Daniel Laskewitz, Business Productivity Consultant & Microsoft Business Solutions MVP at Sogeti in the Netherlands!
For this blog post, I’m going to create a fairly simple bot with LiveTiles Bots and Flow. Users will be able to request a laptop through a bot. When the user has answered all questions from the bot, a Flow will get triggered and an approval will start. At the end of the approval, the user will get a response through the bot.
Let’s start with setting up the Bot…
Setting up the LiveTiles Bot
I skipped the process of creating a bot because I think clicking the button ‘new bot’ is probably not something that needs explaining. Oh, snap! Now I did it anyway. LiveTiles Bots is all about abilities. LiveTiles created this to make it easier for companies to create chatbots. One of the abilities is the Flow ability.
As a LiveTiles Bots user, you are able to add one or more Flow abilities to your bot. This is a great scenario for an HR bot which will trigger multiple Flow abilities for different HR processes.
You are able to set a welcome message for your bot which could explain all different options. In this scenario, we will only one Flow ability, which will run a Flow for a laptop request.
Getting to know the Flow ability
When you are in your bot, make sure to add an ability by clicking the ‘add an ability’ button. A panel on the side will appear. To add the Flow ability to your bot, select the add ability button as you can see in the GIF below.
Next, you will get a screen with a lot of options. I won’t mention all the options, but only the ones that are really interesting in this case:
- Flow Endpoint
Here, you will be able to paste the URL from the ‘When an HTTP request has is received’ action we will configure in the Flow later.
- Success message & Display success message
You are able to set a message when your Flow has been triggered successfully. It’s also possible to hide a success message. You only have to uncheck the checkbox below display success message then.
- API key
Your API key will appear when you have saved your Flow ability. You will need this to make sure Flow can send a message back to your bot when you want to send an update to the user.
- Targets & keywords
With targets & keywords, you can make sure your Flow ability will get triggered. LiveTiles Bots uses LUIS and if the keywords and targets aren’t unique enough, it could happen that your Flow won’t start. If you use multiple Flow abilities in one bot, it’s even more important.
- Conversational parameters
It’s possible to add conversational parameters to your Flow ability. This is an excellent way for you to ask some questions to the users. You can set a variable as required, set a type and use labels for it. For every parameter, it’s also possible to set a prompt.
- Flow ability base URL
This setting is being used to make sure you have the right URL for getting a message back to the user.
- JSON payload
The JSON payload field makes it easy for you to start creating your Flow. You can copy & paste this into the trigger of your Flow. But more on that later.
Implementing the scenario in LiveTiles Bots
Now that we know a little bit more about the Flow ability, let’s implement the scenario:
I already talked a bit earlier about the welcome message that the Bot has. I have set this to ‘Welcome to the laptop request bot. If you want to request a laptop, please type 'request laptop' in the box below and click send.’
When the Flow ability is triggered, we will start an approval. I think it’s a good idea to set the success message to ‘Your approval request is currently being handled by your manager’.
Next, let’s set the targets and keywords. I have set these settings to the following:
This will make it possible to trigger the Flow ability when a user will enter the following commando’s:
- request Laptop
- start laptop request
Remember, LiveTiles is powered by LUIS so other options will be possible too.
As the conversational parameters, I will ask for two variables:
- Laptop (to make sure they will request one of the available models)
- Reason (to make sure they will include a reason)
Take a look at the screenshot above and pay attention to the parameter prompt. I already give the user a choice in the question. This will make it easier for the user and it will make it less error-prone.
We still have an empty Flow endpoint field, but we will come back to that later. First, let’s start building our Flow.
Building the Flow
We are really lucky because the LiveTiles Bots team already created an approval scenario in Microsoft Flow. And one of these scenarios is going to give us a kickstart.
For the sake of this blog post, I will not explain all differences between my Flow and the one the LiveTiles team created. But for me, it was really easy to have a kickstart. Let’s dive into the Flow now!
In the following screenshot you will see the complete Flow.
We start the Flow with the ‘When an HTTP request is received’ trigger.
You should copy the HTTP post URL and paste it into your Flow ability in the Flow endpoint field.
This will make sure the right Flow will get called when you trigger the Flow ability in the bot.
Next, we need a Request Body JSON Schema. Luckily, LiveTiles helps us out here. They have a field for that in the Flow ability called ‘JSON payload’. Copy and paste that field into the Request Body JSON Schema.
After creating the trigger action for the Flow, we have to set some variables. We have to initialize the following variables:
The conversationSession ID is needed when you want to send a message back to the user. It will make sure the message will end up at the right conversation.
You can grab the API key from the Flow ability. If you have saved the Flow ability once, it will generate the API key.
Copy this from the Flow ability and paste it into this apiKey variable in Flow.
We need this variable to make sure the right amount of money will be used in the approval for the manager. We will initialize it here, but we will change it later in a switch case.
This variable is to make sure we get consistency for the laptop parameter. We wrap the toLower() expression to convert laptop to lower case. Later in the Flow, we will use this variable for our switch case. Because of this step it doesn’t matter if a user types HP, Hp or hp. The result will be the same. Remember: typos will still lead to bad results. We can use the default case in the switch case to make sure that the user will get a response back from the Flow when the laptop brand has been filled in incorrectly.
After setting the variables we will add the following switch case:
In this switch case we have three cases and a default case:
- Case 1: if the laptopLower variable equals apple
- If case 1 is true add an action to set the laptopPrice variable to 2000
- Case 2: if the laptopLower variable equals dell
- If case 2 is true add an action to set the laptopPrice variable to 1500
- Case 3: if the laptopLower variable equals hp
- If case 3 is true add an action to set the laptopPrice variable to 1000
- Default: all the other scenarios
- Terminate the Flow. A better scenario would be to send a message back to the user, but for now I chose to use the terminate action
After the switch case, we are going to build up to the point of starting the approval. In this case, we will get the user profile, which is a great action from the Office 365 Users connector. We will use the userID property from the trigger to get the profile properties for the user who triggered the Flow ability in the chatbot.
To get the manager of the user who triggered the Flow, we use the get manager action from the Office 365 Users connector after the get user profile action. If you have the manager field properly filled it’s a great scenario to get the manager here.
The next step is to start the approval.
Fill in the different properties but take a good look at the details field. You can style this in a minimal kind of way with markdown, but I really like this. If you want more details about this, click on this link.
After we got a reaction to the approval, we will initialize some other variables and start building our message back to the user. We will use a condition to make sure a different message will be posted when an approval was approved or rejected.
After that, we will initialize another variable (commentsMessage) which will add comments (if there are any) to the message back. We use another condition to check if the comments are empty or not and change the value of variable commentsMessage if there are comments.
Below the condition, we initialize a variable called responseMessage. This variable will have both approvalMesage and commentsMessage as the value.
The last action will be the HTTP action, which will post back the results (the variable responseMessage) to the chat of the user who triggered the Flow.
How does this look in the chatbot?
How does the approval look?
I really like the fact that I can use my Flow knowledge to build chatbots. I – of course – have a wish list for more features on the LiveTiles side, but I think Power Users or light devs will be able to build bots easily with this tool. Especially when you see that LiveTiles gives you an example. I hope more and more products will leverage Flow to make sure we keep on innovating!