Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save a-parida12/5f133ac096df3b5863e789b08eacb9da to your computer and use it in GitHub Desktop.
Save a-parida12/5f133ac096df3b5863e789b08eacb9da to your computer and use it in GitHub Desktop.
AI driven chatbot development guide

AI driven chatbot development guide

Preparations

Download and install

To be able to deploy your chatbot later on and getting the Microsoft Bot Framework code template, we first need an Microsoft Azure Account. Therefore, please go to www.microsoftazurepass.com and login with your existing Microsoft Account or create a new one. If logged in, proceed until you are asked for the Azure Pass Promo Code. Enter your provided promotion code and click on "Claim Promo Code".

Azure Promo Code

Bot Setup

Go to portal.azure.com and log in with your Microsoft Account. You should now see the Azure Portal.

Azure Poral

On the left side you can find the navigation bar. Click on the New button and search for Web App Bot. Click on the entry followed by a click on the Create button (which you can find in the lower left corner). Next you are asked for some basic bot properties.

  • Bot name: should be lowercase without any whitespaces (think about a unique bot name ;))!
  • Subscription: should be something like Azure Pass
  • Resource group: select Create new and enter something related to your bot's name
  • Location: West Europe
  • Pricing tier: S1
  • App name: should be automatically generated by Azure
  • Bot template: Language understanding (NodeJS) (click on entry to select and confirm selection by clicking Select)
  • App service plan/Locations: Click on the entry, select Create New and choose as Location West Europe. You now have to apply those changes by clicking on the OK button
  • Application Insights Location: West Europe

Confirm the checkbox, also check out Pin to dashboard and click on the Create button. Now we need to wait some seconds until Azure has succesfully created out bot. You will see a notification on the upper right corner within the Azure Portal if the bot instance has been successfully created. If so, you should also see a new entry on the Azure Portal Dashboard with your bot's name. Click it! The follwoing view should appear.

Bot Overview

To receive your bot's code, go to Build on the left navigation bar and click on Download zip file.

Download zip file

Unzip the downloaded file open the directory with Visual Studio Code.

Open bot dir

First thing to do after we opened the bot's project in VSCode is to update the package.json file. Therefore click on View -> Integrated Terminal. The terminal window should popup at the bottom of our editor. Next execute the following commands:

npm install

npm install --save mvgapi

Next we need to provide our LUIS credentials. Open app.js file and have a look for the following code:

var luisAppId = process.env.LuisAppId;
var luisAPIKey = process.env.LuisAPIKey;

Extend these two lines of code such that we provide a fallback if no env variables are passed:

var luisAppId = process.env.LuisAppId || '<YourLuisAppId>';
var luisAPIKey = process.env.LuisAPIKey || '<YourLuisAPIKey>';

Replace <YourLuisAppId> and <YourLuisAPIKey> with your personal credentials. You can find them at the Azure Portal! Go back to your browser and navigate to the Application Settings of your bot. By scrolling a little bit down and you will see the environment variables LuisAPIKey and LuisAppId.

Env settings Azure Portal

The same need to be done to provide the microsoft app id and app password. Search for

var connector = new builder.ChatConnector({
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword,
    openIdMetadata: process.env.BotOpenIdMetadata
});

and also provide a fallback

var connector = new builder.ChatConnector({
    appId: process.env.MicrosoftAppId || '<YourMicrosoftAppId>',
    appPassword: process.env.MicrosoftAppPassword || '<YourMicrosoftAppPassword>',
    openIdMetadata: process.env.BotOpenIdMetadata
});

Again, replace <YourMicrosoftAppId> and <YourMicrosoftAppPassword> with your personal credentials which are also provided by Azure Portal Application Settings.

Microsoft AppId and AppPassword

We are nearly done! But before testing, we need to remove some lines of code. Search for

var botbuilder_azure = require("botbuilder-azure");

and remove or comment out this line. Do the same for the following code lines:

var tableName = 'botdata';
var azureTableClient = new botbuilder_azure.AzureTableClient(tableName, process.env['AzureWebJobsStorage']);
var tableStorage = new botbuilder_azure.AzureBotStorage({ gzipData: false }, azureTableClient);
bot.set('storage', tableStorage);

Save your changes and head over to the integrated terminal. Execute the following command to start our bot:

node app.js

If the bot started successfully, there should be something like

restify listening to http://[::]:3978

on the console output.

Next start the BotFramework Emulator and enter the follwoing url http://localhost:3978/api/messages. Furthermore, we need to provide the Microsoft AppID and AppPassword (again you can find them either in the Azure Portal or app.js file). Click connect and test your bot!

BotEmulator connect

BotEmulator testing

Your are now ready to implement your bot conversations and features. For testing purposes, you need to stop and start the bot again by clicking into the integraded terminal window, pressing STRG + C and again executing node app.js.

If your bot is ready for release, you can simpy run

node publish.js

and the bot is automatically uploaded to Azure (don't worry, this process can take 1-2 minutes until changes are deployed).

Further information

Some sample code for a small and easy language understanding bot can be found here.

The official documentation of the Microsoft Bot Framework is also a good reference for a quick look.

MVG API

The documentation of the MVG API can be found here.

Bot Connector Setup

Of course we want to see our bot in action if our core features are implemented. The setup wizard for different bot platforms can be found under the Channels tab in the Azure Portal.

Bot Connector Azure Portal

Just follow the instructions by clicking on a bot platform's entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment