AI-102 Microsoft Azure AI – Create a bot by using the Bot Framework Composer
- Overview of Bot Composer
So let’s talk about the Bot Framework composer. The Bot Framework Composer is actually a UI, an integrated development environment for constructing bots. And it’s graphical and it lets you quickly and easily build sophisticated conversational bots without code. It’s available in GitHub, which is is in the GitHub. com, the Microsoft repository. And this is a bot framework hyphen Composer. And if we go under the latest releases, we can see that the latest release is a 2. 0 release. So we want to make sure that we’re running on the 20 release. So we’re going to pick the version for our operating system. In my case, it is Windows, but it does support Linux and Mac and we can download the source code even.
All right, so let’s install it and go through the pretty standard process of installing an application. Now, I love how it’s installing the Visual Cistributable library as if it isn’t 2021 and everyone in the world has it already. All right, so it’s installed and we’re going to start it up. So what we’re expecting here is a user interface that we can start to create our own friendly bots. We do have to allow this program to access the Internet. So make an exception through my software firewall, and I’m not ready to allow it to collect my data. So we haven’t got any bots yet. So I’m going to say create new. It says a node JS is required. All right, let’s assume it knows what it’s doing and allow that.
And I have to do this myself, I guess. So with Nodejs installed, it says we do have to restart the Bot Composer. So I’m going to exit this and start it over. All right, so I’ve restarted and now I can say create new. And I have the choice between C Sharp and Node, and I can choose from any one of these templates. I’m just going to use the empty bot and I’m going to call this Learn Azure No Spaces. And we’ll create it as an Azure Web app. And it does need to be stored into a folder, and that folder has to already exist. All right, so created a new folder for that. And I’m going to say create. Okay, it took a little while to download this template.
I’m going to close out the onboarding tour, the Getting Started tour. And here we are with our basic bot. So I zoomed in a little bit so that we can see a little bit better. And the first thing we’re going to look at is the greeting.So the greeting is an activity that happens when the user begins a new conversation with the bot. So any user that gets added is basically going to be presented with the greeting. Right now it says we can sort of see this has got a sort of a graphical interface. And for any time that a user member is added, it’s going to say, welcome to your bot. And that’s the greeting.
So when we first get into the bot, this is what we’re going to see. So let’s start by renaming this and we can call this the welcome Activity. Give a name of whatever you wish. And inside the canvas here, we can change the words that are sent and I can say hi there. So happy that you are here. Very friendly greeting. Maybe a little bit unnatural, but that’s what it is. Now we can extend this welcome. So if all you want to say is just hello, that’s great, but perhaps we might want to ask them a question. So we’ve got this sent and maybe we want to add another message and we get these actions that we can choose from.
In this case, I want to ask a question and get a text response. So going down here, it says prompt for text. We can say the response is, what name do you prefer I call you? Doesn’t sound too too awkward, does it? Now we need to then basically assign a property with this result and so we can say we want the property to be user name. And so now we’ve got a property within this dialog that we can then refer to them by user name. We can even see user name is assigned to input text and you can see we haven’t written any code yet. Right? So this is sort of doing the work of creating a bot for us.
So the final thing that we can do here is to say hello, right? So hi there. And then we’re going to you see the curly braces represent a variable so I can say user dot name. I do have to start that with a dollar sign. Hi there, user name. So we’ve got our welcome activity and it says hi there. Happy that you’re here. What name do you prefer I call you? It takes in a variable and then it’s going to say hi there, user name. Now we haven’t really gotten into the bot part yet. Actually there’s this cool show code. So you can see there’s a JSON that’s related to the set up of this bot. So if you really modify this, I guess we go back to the UI version.
- Test a Bot Composer Chat Bot
Now we do have this start bot in the top right that’s going to take my bot. It’s going to compile it and it’s going to start the bot. So let’s do that. Now I do have to allow you can see a compiled at learn Azure. Exe is actually asking for access to the internet. We do have to allow the application that we created access to the Internet. And now it says running that’s pretty quick. So maybe we want to in this case test it using web chat. So we got the welcome activity. Hi there. So happy that you’re here. What name do you prefer I call you? You can call me boss. Hi there, boss. And so we’ve created a basic bot using the bot composer.
Now we could actually again, those types of bots are programmable. We haven’t really explored too much into various dialogues, asking a question, some type of if then else statement, or being able to switch on multiple options. All of your typical programming metaphors looping are here. Okay. And then we’ve got variables and properties and things like that and then being able to access external resources. So if we need to make an Http request or connect to Q and et cetera. So there is a number of actions we can take again looping, parallelism, et cetera. So there’s some things to check out to make a more complicated bot.
- Add Additional Dialogs in Bot Composer
Now these chat bots are based on understanding user intent. So this was the welcome activity. The rest of this task is going to be creating various intents like what is it that the user wants from us? Where are you located? So the user now can ask a question. And we haven’t created an intent that is a location intent in here. So what you would expect to happen is that it just falls into this unknown intent which is a you can see there’s no conditions to get into that. So if we were to continue on with this example, we could basically start a it’s called Add dialogue. And you could say that Get location is the dialogue. And there’s two parts to this.
One is that this is what happens when the bot recognizes that somebody is asking for the location so we can close this out. We want to say we are located in Toronto, Canada. Now how does this person get into this location dialogue? So we go back to our Learn Azure bot and we’re going to change this to a regular expression recognizer. And then we can add a trigger and we’re going to say, let’s say we want to know the intent. Now this trigger can be called the Location trigger and it says please input reg x pattern. And so in the regx pattern we’re going to put in like the word location. So if they ask location, then this is going to trigger our bot here.
So the location trigger and with the Location trigger we’re going to say begin dialog management, begin a new dialog and we’re going to point them to this Get Location dialogue. So we’re taking the Learn Azure welcome dialog and getting over to the Get Location dialogue. Once they use the word location so we can retry this, restart it, open web chat. Let’s restart the conversation with a new user ID. We get the welcome. What name do you prefer to call you? I’m going to say boss. Hi there boss. Now at this point I can say how are you? And it’s going to say I didn’t get that because the intention is unknown and I can say what is your location?
And you’ll see that it’s triggered on the reg x to say we are located in Toronto, Canada. Now we could tie this bot into the language understanding service Lewis and then have that basically pick out the intention of the user. So we know that Lewis can determine what kind of intention somebody has based on natural language. But right now we’re doing a regx which doesn’t require any intelligence other than pattern matching. So here we are, we created a very simple bot using the bot composer. And yeah, we can basically build upon this and make a chat bot that we can then of course publish into Azure and use this in a chatbot setting.
- Test a Bot using Bot Emulator
Now, the WebCat option is not the only way to test a bot. So there is this thing called a Bot Framework emulator. And again, it is a desktop application for Windows Osx and Linux that you can download to test your bots. So with the Bot Composer, obviously it tests bots that were created in Bot Composer bot emulator can test any bot and can even test bots that have been deployed into Azure or built using the Bot Framework SDK. This is like emulating the front end, okay? So you can go here, download it again with the releases, and get the latest release of this for your operating system and install it. Now, built into the Bot Composer is the ability to test a bot using the bot emulator. So I’m going to say start the bot because it stopped right now.
It’s compiling my same bot that we were just testing in the web chat interface. And you can see there is a test in emulator. And now the URL for this bot, since it is running, it’s a program that’s compiled and it’s running on my computer. There is a local host URL. And I could use this in my own applications. Even if I had a net application calling out to this bot, I could do that. Or I can click on Test in emulator. And what that’s doing is it’s going to start the Bot Framework emulator and it’s going to connect to the local host. Here we have the hi there. So happy you are here. What name do you prefer I call you? All right, so let’s call me you can call me Scott this time.
And we can see here on the right basically the transcript of what messages were posted to the URL and what message was received. So hi there. So happy you’re here. Was a message received and then I post to get the next message. And then you can see when I filled it in, it was posted back, et cetera. How are you? I’m expecting it to be confused. And your location? Tell me right now. And again, it’s triggered on the word location. We are located in Toronto, Canada. So this is another way of debugging your bot, especially if the bot is a Rest API based and you just want to see what’s going on behind the scenes. So this is the Bot Framework emulator can be used to test any bot, not just Bot Composer, but your Bot Framework SDK, whether it’s on your local or it’s even posted into Azure.
- Publish a Bot
So let’s say that we are happy with our bot. We’ve built a fairly complicated bot and we’re ready to get this off our machine and into Azure. Well, there is a Publish button here on the left menu. And I’m going to click publish. This is the bot I want to publish. I don’t have any published profiles yet, so I have to click click Manage Profiles. Now we’re using Bot framework. Composer 2. 0 So we’re going to then have to create a new publishing profile. This is called Azure Bot. This is a good game as anything. And the only choice we have at this point is to push this bot to Azure. And then we’re going to have to connect our Azure account.
We’re going to have to sign into Azure in order to connect our Azure account with this bot. Composer do we want to create all new resources in Azure? So we’re going to create the app and the app registration. It’s going to be hosted in a web app, obviously, things like that. Do we want to have existing resources or do we want an administrator to take over? So, like, we’re a developer, we’re ready to publish, but we are not the ones that are provisioning the resources. And so there’s this hand off to Admin button to handle that. Now, this step is rather interesting is what you’re doing is you’re basically requesting resources and you’re going to then share that to an administrator.
They’re going to fill out the Json template, send the Json template back to you, and then you can continue publishing once the administrator has done their part. So again, this is specifically if you don’t have permission to use it, or maybe you’re not even using the main Azure public cloud, you’re using a government cloud or Azure China or something like that. So I’m going to say create new resources. Let me say next you can see the steps here in terms of what to do. So first off, I have to sign in. So I will sign in using my Portal account and provide my password. So it’s connected to my account. I’ve chosen my default active directory, my subscription. I’m going to create a new resource group. I’m going to call this my new bot, composer Bot.
Now, this new resource name is quite important because it’s the resource name given to almost all your resources. So Azure is going to deploy eight or nine resources with the exact same name. So make sure it’s absolutely unique across Azure. And the Language understanding service only appears in a couple of regions, west Europe, Australia, West US. And I believe also Switzerland, which I might not even have access to. So it goes into the West US.Group. But I’m going to put this also in West US. Just to keep everything together. It’s not mandatory, obviously, but something that you can do. So when I click next, it’s going to ask me what kind of resources that I want with this.
Now, you’ll notice that only three of them are required and the rest of them are marked as optional. Right now, I don’t have language Understanding service with this. It’s just not using it. And we’re also not using any Conversational Q and A maker stuff. Application Insights is kind of optional. And Cosmos. DB is used for bot state. But we’re not really using this. We’re using only the default bits. Right? So I’m just going to transcript logs back in recovery. I’m just going to disable all the optional stuff. We’re trying to make this so you can see here it’s only asking for three resources. The app registration, the hosting and the channel registration.
So I’m going to create that profile by clicking Create and it’s going to go and create the resource group. It’s going to go and create the app, all of the things that it needs to do. So we’ll let that run. All right, so it says all the resources were provisioned correctly. We still should. Well, it does say the publish was successful. So we can now go into Azure and look at our bot. So we can see the new Bot Composer bot and it’s got the app service in this. And there’s also the bot itself, which is Global Resource. So the bot itself is here. We can see there’s a messaging endpoint. We can go into channels. We can see that it is hooked up to the web chat channel and then we can actually test it.
So now, instead of testing this on our local using a local app, we are going to be testing this that is published into Azure using the Azure Portal. And there we are. So not sure if publishing a second time fixed it or if it would have fixed itself anyways if I was a bit more patient. But I’ve got my Chat bot and I can do my usual answers, get my usual responses. There we go. So in this video, we created a publishing profile in the Bot Composer. Published it, had to publish it twice because of errors. And now at least we saw where you go if your body isn’t working. The health issues is telling you different messages in here, but it did work, right? There we go.