top of page

Using Bot Framework Composer to pass variables back to Power Virtual Agents




Hey,


How are you doing?


In this blog post, I am going to show you how to extend Power Virtual Agents with a simple dialog built inside Bot Framework Composer.


Contents:


8 - Publish


1 - Use Case


I want to be able to provide a choice to a customer, if they want to provide the first line of their address, if they do, I will store it and pass that information to the chat bot, if they say no, then I will store "N/A" and pass that back to the chat bot.


2 - Install Microsoft Bot Framework Composer


Please follow the instructions here to install Microsoft Bot Framework Composer


3 - Open Bot Framework Composer from Power Virtual Agents


From within side the Power Virtual Agents application, go to Topics and then hit the "New topic" drop down and select "Open in Bot Framework Composer"


If using Google Chrome and popup will appear:

Click "Open Bot Framework Composer". Bot Framework composer will open, and the chat bot will be downloaded from Power Virtual Agents into the Bot Framework Composer application:




Provide your sign-in details if required.


Next, you can leave the import details as per the defaults and click "Create":





Bot Framework Composer is now downloading and saving the whole of the Power Virtual Agent chat bot on the local machine.


4 - Creating a New Dialog

A dialog is a conversational flow like a Topic in Power Virtual Agents. We create one now.


Click on the "PVATest" section at the top of the pane on the left-hand side, click the ellipses and choose "Add a dialog":



Give the dialog a name, and click OK:




A new dialog has been created called "TestChoice", if we then click on "BeginDialog", we can see the canvas of the dialog in the main part of the screen.


5 - Create Output variables as part of the dialog.result scope


To be able to pass variables back to Power Virtual Agents, we need to create output variables that are part of the "dialog.result" scope.


To do this, click on the "TestChoice" dialog parent, above "BeginDialog", on the right-hand side expand "Dialog interface" and then click on "Add new" under "Output":




For this example, we are going to ask the customer if they want to provide the first line of their address, so in the "Key" field, I have entered "firstline" and changed the "Type" to "String":




Now click back to "BeginDialog" underneath the "TestChoice" dialog


6 - Continue with Dialog Creation


Now we are going to be able to continue building out the dialog. First of all, click on the plus button and select "Ask a question" > "Multi-Choice".


On the right-hand side type in "Would you like to provide the first line of your address?":



Next click on the "User input (Choice)" step and we will assign this choice a property value of "user.FirstLineYesNo", then scroll down inside the "User Input" section and click on "Add New" under "Array of Choices". We will add Yes and No:



7 - Branch: Switch condition

What we want to do next is have a condition whereby if the "user.FirstLineYesNo" value is Yes then we want to ask the customer for the first line of their address and then set the output variable value to that address value, if they answer no, then we are going to set the output variable to N/A.


Click the plus button underneath the "User Input (Choice)" step and choose "Create a condition" > "Branch: Switch (multiple options)". The condition is going to be based on the value inside the "user.FirstLineYesNo" property, so we set this inside the "Condition" field on the right-hand side:


Under the Yes switch case, click the plus button and then choose "Ask a question" > "Text". Here we ask the customer what the first line of their address is and store that value in "user.FirstLine" property:




In the no branch, click the plus sign and choose "Manage Properties" > "Set A property". This allows us to set the output variable we defined above. With this step selected, in the Property field write "dialog.result.firstline" and set the value to "N/A":



If the customer clicks no, then the output variable will be set to N/A.


Now we need to go to the end of the Yes switch branch and add a new step "Manage Property" > "Set a Property", and this time we are setting the "dialog.result.firstline" property to "user.FirstLine" which has been captured in the step above this in the Yes branch:

8 - Publish

Now that we have made the changes we need, we can publish the dialog back to the Power Virtual Agent chatbot. Do this by clicking on the "Publish" icon on the left-hand side, selecting the "PVATest" bot and then clicking "Publish selected bots":

You may be asked to sign in again, click ok and the publication will start:




When complete, you will see this message:




9 - Back to Power Virtual Agents

Let's now jump back to Power Virtual Agents and use this dialog we have just created. If you already have Power Virtual Agents open in a browser window, refresh the page.


You will see a new topic at the top of the topics list, the icon under the Type column indicates that this Topic has been built in Bot Framework Composer:


To use this, we need to create another topic inside Power Virtual Agents to call this dialog.


Click on "New topic".


As this is just for testing, inside the trigger phrase, type in the word "address", this will then trigger this topic when we type the word "address" to the chatbot in the test pane on the left-hand side:



Delete the Message node, and then click the plus to add a new node, click on "Redirect to another topic" and choose "TestChoice" from the list. This adds this dialog to this topic:



Next add a message node, and populate that with the "firstline" variable from the Test choice step, the Topic should look like this:





10 - Test the topic

We are now ready to test the topic, hit the "Track between topics" toggle so it is on, and then type the word "address" in the chatbot test pane:


We are asked if we want to provide the first line of our address, let's say yes:



We provide the address of 123 High Street:



Add because we have set up the Topic to return what we entered back to us; it is repeated back in the conversation proving that what we have supplied has been saved in the "firstline" variable.


Test again, but this time say no:



The bot responds with N/A as that is what we set to the "firstline" output variable in Bot Composer Framework, if the customer did not want to provide their first line of their address.


Thanks for reading, I hope this helps you.




Recent Posts

See All

Comments


bottom of page