Create and Deploy Bot On Azure
Prerequisites:
- Download Visual Studio
- Download Bot Framework v4 SDK Templates for Visual Studio
- Download BotFramework-Emulator
- Azure subscription
- Download NET Core 3.1 Windows Hosting Bundle
Creating And Deploying Azure Bot on Web Chat channel
To create and deploy an Azure bot you will need four main things:
- Create bot itself (we will use a template for this).
- Create an Azure App Service.
- Create an App Service Plan.
- Create an Azure Bot.
Creating The Bot
Open Visual Studio and select a template.
I selected “Echo Bot”
Run your project and it will say to download Emulator to test bot.
If at this point you received a “500.31”, remember to download .NET Windows Hosting bundle 3.1
Open the Emulator > “Open Bot” > set your URL plus “api/messages”
Test your bot:
Now let us publish this bot to Azure
Select “Azure > Azure App Service (Windows)” and create a new App Services instance if necessary.
Click “Publish”
You will see these new resources in you Azure Portal:
Go to your App Service and browse to the given URL
URL: “https://echobot120220608222659.azurewebsites.net/”
Now we have the endpoint exposed to the public, but we still need to test it.
Go to your Azure Portal and create an Azure Bot
New Azure Bot resource in our portal:
Go to your Azure Bot > Configuration > Messaging endpoint: set to the URL that you App Service gave you + “api/messages”
We can even test it here ,in the same Azure Bot. However, we first need to edit “appsettings.json” of the project and republish it.
We nee set the correct value for the following attributes:
{
“MicrosoftAppType”: “”,
“MicrosoftAppId”: “”,
“MicrosoftAppPassword”: “”,
“MicrosoftAppTenantId”: “”
}
MicrosoftAppId => Azure Bot > Configuration >Microsoft App ID
Copy Microsoft App ID and have it it notepad.
Click “Manage”.
Create a new client secret and copy the value and have it in your notepad. This will be your MicrosoftAppPassword.
By now, you should have in your notepad : “MicrosoftAppId”, “MicrosoftAppPassword” and now we are missing “MicrosoftAppTenantId”.
Go to your Azure Active Directory and copy and paste the “Tenant ID” into your notepad.
Go to your Visual Studio and set these values in “appsettings.json” plus the AppType that you set when you created the Azure Bot.
Go back to your Azure Bot and click “Test in Web Chat”.
Now we need to publish it onto a web channel.
Go to Azure bot > Channels >Web Chat > Default Site > copy the html
Create an html file and paste the <iframe> tag and replace the secret key with one of the “Secret keys” in the “Configure the site” section.
Open it and test your bot!