Publishing Bot to Facebook Messenger

Let us continue with our previous posts on using Microsoft Bot Framework for writing a simple bot.

In our previous post, we published the bot app to Azure and also tested using Skype which is already configured.

In this post, we will be deploying the Bot to Facebook Messenger.

Sign in to Bot Developer Framework site

https://dev.botframework.com/

and open the bot application deployed.

Scroll down and we can see Facebook Messenger as one of the Channel available.

Click on Add.

Here we can see the guidelines and all the steps we need to do follow to configure the Facebook messenger

As a first step, we need to create a Facebook page for the bot

Click on the link and create a Facebook page

https://www.facebook.com/bookmarks/pages

Next step is to create a Facebook App for the bot

Click on the below link to create the Facebook app.

https://developers.facebook.com/quickstarts/?platform=web

Next step is to copy App ID and App Secret

Go to App Dashboard and copy these values. These values be used in the last step where we need to enter the credentials to authorize the app.

Next step is to enable the Messenger

Go to Dashboard and select Add Product.

Click on Get Started for Messenger.

Select the page from the dropdown and copy the token generated.

Next step is to set the Web Hook

Go to Messenger – Settings in Facebook App Dashboard.

And click on Setup
Webhooks.

Go back to Configure Facebook Messenger page and copy the url and token from there.

Copy these values and paste it to New Page Subscription. Check the required subscription fields and click on Verify and Save.

It will show the status as complete on successful verification.

Now as a last step we need to enter our credentials

  • Facebook Page Id –

i.e. 403898986632435

All other values we had already copied earlier. So just passt those values.

And Click on Resubmit.

Once the credentials are validated. Click on “I’m done with configuring Facebook Messenger”.

Click on Message Us to start the conversation.

Hope it helps..

Publishing Bot to Azure and adding it to Skype (Microsoft Bot Framework)

Let us continue with our previous posts on using Microsoft Bot Framework to create a simple bot application that creates a lead in CRM.

In this post, we will be publishing our Bot application to Azure and also test it on Skype. Skype is one of the channel already configured for us.

Open the Azure Portal (Create a free trial if you do not have an account)

https://portal.azure.com

Right click on the application and select Publish.

Select Microsoft Azure App Service as the publish target.

Create the app service

Validate the connection and on successful connection click on Publish.

The published Bot Application –

Now to register our bot go to bot framework developer site

https://dev.botframework.com/

Sign in and Click on Register a bot

Enter all the required details.

Here URL will be the Destination URL of Azure where the Bot Application was published.

Click on Manage Microsoft App ID and Password

Click on Generate an Microsoft App ID and password.

Save the password and app id which will be used for configuration later.

Enter the App Id and click on Register to register the Bot.

We will get the message “Bot created” on successful registration.

Back in our bot application, open its web.config and specify value for app id and password and republish the app.

Once it is published successfully, inside our bot we can click on Test to check the connection.

We’d get the message “Endpoint authorization succeeded”.

Scrolling down we can see two channels web and skype already configured.

Click on Add to Skype to add the bot as a contact to skype.

Click on “Add to Contacts”

Sign in with your Skype Credentials.

Launch Skype.

We can see the Bot added to our contacts.

This is how we can easily publish the Bot to azure and add it to Skype.

Hope it helps..

Using LUIS AI in Microsoft Bot Framework – Part 2

Let us continue with our previous posts on using Microsoft Bot Framework

In our previous post we had configured, tested and trained our LUIS application.

Here we will update our bot application code and see how it works.

Add a new Dialog class named LUIS Dialog

The class implements LuisDialog interface and has attribute Serializable to it.

We also need to add an attribute LuisModel that takes in model id and subscription key.

To get the model id and subscription key, open the LUIS application we had created. (https://www.luis.ai/)

Get App Id from the Dashboard.

And API key from My Keys section.

Now one by one we will implement logic for each of our Intent, for this we will use LuisIntent Attribute.

Here we have wrote a method for each of the intent that we had configured earlier.

We would need to make following changes to our ModelController.cs to call the LUISDialog

Let us look at the Intent one by one

For Luis Intent – None :-

i.e. when no Intent found or Intent is None.

Here bot will reply with Sorry I do not understand if the intent is none.

Here the work meeska (utterance) is associated to None Intent.

Inside Bot emulator –

For Luis Intent – Greeting :-

If the user types in Hi or Hello the bot will respond with “Please let me know…” as it will figure out that the intent is Greeting.

For Luis Intent – QueryProduct:-

If the user types in “Do you have product1?” the Bot associates it to our Query Product intent as we had trained our LUIS app for this. Here if user asks for Product1, Product2 or Product3 the bot responds that it has those products else it responds with “Sorry we do not have that product”.

QueryProduct Intent associated to Product Entity –

Inside Bot Emulator –

For Luis Intent – Interest:-

For Intent Interest, we call our Form Dialog that we had created in the following post Using FormFlow in Microsoft Bot Framework.

It basically asks user about the product he is interested in, name and description and creates a lead record in CRM.


Interest intent –





The lead record created in CRM.


In the next post, we will see how to publish the application to Azure.

Hope it helps..

Using LUIS AI in Microsoft Bot Framework – Part 1

Let us continue with our previous posts on using Microsoft Bot Framework

In this post, we will add natural language processing to our Bot Application through LUIS i.e. Language Understanding Intelligent Service.

LUIS intercepts the User requests and converts it to comparable action for the bot.

The 3 most important aspects of LUIS Framework are

  • Intents – Identifies what actions you want your bot to take.
  • Entities – What things your bot is taking action on.
  • Utterances – Identifies phrases that links intents and entities.

Go to LUIS web site and Sign in

https://www.luis.ai/

After completing the sign up and finishing other details. Click on My apps link and select New App to create and register the app.

Provide the Name and culture as English and click on Create button.

Now as our app is created, we will now create the intent.

Go to the Dashboard of the app and select Create an intent.

Here we will create “Interest” as our first intent. Next, we define Utterances that points/associates to our intent.

Here we have defined want, interested and like as utterances associated to Interest.

So, for e.g. if we have following statement or response it will all point to the Interest intent.

  • I am interested to know about the product.
  • I want to know about the product
  • I like to know about the product.

Let us create a new Intent named Greeting and associate 2 utterances Hi and Hello to it.

Once we are done specifying our Intents the next important step is to Train and Test the application.

Select Train and Test and click on Train Application button.

Once the training is completed, we can make use of Interactive Testing interface to do the testing of our utterance and their score.

For e.g. hi utterance had full score i.e. 1 with Greeting intent and 0.19 and 0.13 with the other intent like Interest and None respectively.

Similarly, with “want” utterance we had .77 score for Interest intent.

Next, we test with meeska utterance for which we get the score of .66 with None Intent as this utterance is not associated to any of the intent we had defined nor it is understood by the application.

Now as we are done with testing let us publish it.

Once published, it will provide us with Endpoint URL.

We can append the text to the query string q in the above URL to get the JSON result. (as testing)


Now let us play around with Entity.

Select Entities link and click on Add custom entity button.

Here we are adding an entity named Product.

Now create one more intent that we will associate to this Entity Product named QueryProduct.

Let us add a new utterance, “do you have product1?” and here we will associate the product1 word with the Product entity.

To do so left click on the Product1 word, and select Product from the drop down.

This associates “Do you have [[xyz]]?” with Product entity.

We can quickly test it. Type any utterance like “Do you have x?” and in the result, we can see it being associated to QueryProduct1 intent with full score (1).

Now as we are done with all our configuration, training and testing, we need to train and publish the application again to have all the changes reflected.

In the next post we’d update our bot application to incorporate LUIS AI to it.

Hope it helps..