Build your First Bot on Messenger Platform – Messenger ChatBot Developers Group

okay thanks movie for interesting talk are you guys geared up to build a bot okay so it will be a short and quick little boring also okay so we'll start with a basic introduction of what is a you know how to build a bot and what is the basic architecture and then we'll quickly go to you know start building the bot without an even if you do not have any programming knowledge we'll still be able to build about today okay okay so we'll cover the basic concept of chat bot then we'll build you will be able to build your own bot we'll cover some basic concepts of API dot AI and then where we go through how to set up your own development environment and sample code in node.js okay so what is the bottom I mean up I'm sure you guys have gone through all this okay in short if I say my bot is an intelligent application which you know can read your message process and then respond back right so let's divide this into two parts okay so your app should be focused on reading the message and then you know respond back you the most difficult part is the processing of the message which we can you know push it on to an NLP engine which is already quite a few NLP engines available like API dot AI without AI there are some other applications as well but we will only go through API dot AI today okay so a basic overview of how your architecture would be what we need is a no messenger where people are going to you know type their message one when the type then obviously you need to read that message through your app and then send it back to the NLP engine the NLP engine will process and then send it send you what you need to do and then you carry those tasks and then would put your message back to the messenger right okay so I will quickly build a bot you you have a Facebook account okay so the first step is to you know the first step is create a Facebook page okay okay so we'll create a Facebook page first maybe okay you can skip all their steps okay so can we go to the next step okay so well we'll create a facebook app does complete the task here okay so once you come to this page you will see this option called messenger you click on get started and select the page that you created just now this authenticate okay so copy this up to this page it's it's all done yep can I go to the next step okay so we'll go to the NLP engine okay yoke let's go to API dot a I okay if you on the login page you'll need a github account or a Facebook account to log in okay so I'll create a new agent so agent is your NLP engine so whatever logic whatever conversation you want to have you put it everything on this agent and then on your in your code you probably you know have to understand what is action you have to do and then carry out that action in your court okay is that done can I go to next step okay in the domains you will just switch on the small talk um yeah that's it okay so we'll integrate directly with Facebook messenger here okay you go to the edge end settings click on settings are you on this page yeah so they'll just you clear that a page token on Facebook app so just paste it here okay so I'm not copying this copied from here very part organic and even it any string okay and then you will start but so basically API dot I creates an app for you so what we saw is that your app and the bot engine so it created an app for you that will talk to the NLP engine so now it gives you a web book URL so just copied go back to your Facebook app click on set up where books the token you whatever you have given there it just type the same one here okay you must say this green Grenda quit completely you are on which page yeah so you have to select the page that you created just now okay yeah so once you create the token you have to provide that oaken in the API dot ai and the way book section they select the page that you just created okay this one and this page should be same one in this page you know once you select you know it will give you the token you would not have to select again okay every time you select it will generate a new token so you don't have to do that again click on subscribe' here okay all done so your bot is ready you can just type on it right so you can talk anything yeah yeah you go to the messenger yep it's a page ID you can know once you go to messenger let's go present okay now can I change the message I mean if if you say hello the bot would always say you know hi if you want to change you know you can do that as well okay let's go to you know a peridot AI and then you know create an intent okay so just give it a name so you can type you know whatever you want to overwrite that's a for all this messages maybe you know you want so and it for all these messages if you want to change the response just type the response here you know you can give a character to the bot okay so so this is simple but if you if you want to do some stuff like you want to do some booking let's say order booking or something you can create one more intent let's say book hotel okay so I'm gonna going to test that so how do we know which yeah I said what does if you have to give that no intelligence to the bot let's say so instead of bouquet room I would say book a room for today okay so immediately it understands that this is a date or something so you can add the parameter here so let's say so this one is a date let me just say this okay so let's say you want to take this you know date as a parameter so you define this parameter parameter name as date and then this dollar date you can define it in your response here okay this these are the entities that is already defined in the system so you do not have to worry about this if you want if you want to test whether this is working on or you can just test it here let's say yep so to understand that Sunday is 29th May so it so it booked a room for you for 29th May right okay now if I think how do we how what do you need to do in your code you need to figure out this parameter and what is your action you have not specified any action you can just specify that you know this is a photo so next time you okay so in your code you need to look for this action and then the parameter and you should be able to provide a query to the backend API and complete the process and then once the come the booking is complete then you send this message back to your messenger right you will get this in your code okay so I'll explain you how how do you do that in your code right now we are just building the bot so when we did an integration with Facebook it automatically created an app for you so you do not have to we do not have to go through the code but you have to integrate the SDK and then within your SDK you call the API AI service and you will get this JSON in your code okay so once you get this JSON so for conversation you don't need anything but for your back-end processes you wouldn't need because if you need if you want to develop a bot to book a room then you would need this information so that you can complete your back-end processes right so how do you get the parameter you just the moment you select this you will be able to it will automatically create or sometimes it does not create so you can you know pass this and create this parameters okay so let's say you want to if the person does not you know provide this date so you can prompt you can define this as a required parameter and then this so and then you define a so when somebody says booked a room then your engine will get this thin tent as you understand that you the person wants to book a hotel and then it will you know run through this actually let's say may I book a room for tomorrow yeah so you'll have to define those in the intense that if somebody says many I book then obviously you know that you can divide that intent into two things one is directly you one is you can define that if somebody says booked a room then it has to go to the booking intent somebody says you know do you have a room then you can put it onto a question let's say you know enquiry for room and then your conversation can be different so if it is not defined here then you yeah probably yeah okay and no it should ask for this date maybe we have not saved this one as long as there is book and room then it will work so yeah you can you want to change the reply okay so you have to write it in the code you have to write it in the code like this yeah so in the code you are allowed to when you pass the message data so it will have to define that it's the structured message and you can pass those data okay so let me just go through a sample code yes I mean this you need to know multiple things about person okay so you can define let's say there are ways to do it like that is one one way you define the required parameters here and you put the prompt here okay if the user does not provide those parameters or you collect it from here right so now we saw that if the user does not provide date then you you can leave it prompts you again the other way is also let's say we want we can define like you know entities we can define the room type let's say maybe I'll just quickly go through what we have already developed yeah are you are you sending it to the same page what are you yeah so you have to make her an admin for your Facebook app as well as she has to like the pill and probably love yes yes yes so in the new app in the developer console you have to make her an admin of that app yeah admin or other developer tester there are quite a few other rules as well cancel it so you go here so you can define you know all these roles will be able to test your app I had applied one bought for approval but it got rejected then that was almost a month back because it's I mean I developed that using with dotty I and I don't think with dotty is no mature enough I mean if compared to a bed or day I I found that it still lacks a lot of functionality API dot in FBI dot a I can quickly build all your conversation here but if you go to V dot AI to build this what I developed right now it probably will take few us but yeah yeah so what they do is they when you up put for approval you know they will go through your app or whatever you have shown in your video so when you send it for approval you have to create a video and then you submit and then they will go through that everyone will understand what what Mesa just no you have to they have to type and if it works well if the bot is able to answer those queries they will approve if it does not then they may not approve then people will complain and then then they might come to know maybe there they would be monitoring now I don't know but we had applied for this one so this is okay so you develop an app and make all your friends as developers and testers so they will be able to access you do not have the if you if you make them tester they will not be able to do it you can make them tester so they cannot do another yeah okay so I was going through this right so basically I have defined an entity of room type okay so these are three different types of rooms okay so you can define an intent called book hotel and then define two parameters okay room type and the date and then the parameter section you type if somebody does not give the date so you ask him what is the date somebody does not provide the room type so you can ask what is the room type so maybe you can just you should ask you which date so you say Sunday so what what is what room type you say okay now if you look at the JSON you will have action incomplete false and your action name if you go back one step previous the action incomplete will be true that means your action is not complete yet so you you just you know allow the bot to send the next message okay right so I will show you the sample code it's equal to excess or like detail light use a dater like me yeah now you can get that in your inner core yep API to API taught AI you can pass the information when you know your face your own code you will be able to get that information right okay so we saw that the API dot AI created an app for you right and then it gave us a way book URL and we put that in the Facebook app so what you have to do is you you do not have to do that you you know host your application on your server and so this is a sample code that is given by a pair of AI what you have to do is you have to install API AI and then pass on this information to to this code and then no so you so when you run this you will get your URL and you put this URL into a facebook app right if you want to want me to go through again so when we did the integration it actually created an app and we got this web URL so we have to we have to stop this and create our own app we have to stop this and create our own app okay so how do we do that we so this is a sample code that you can use you can run this and then whatever we did right now it would be able to do that okay if you want to know I mean this is on my github I can share that with you and it's also there on the API AI SDK just download the node.js SDK will be able to get this okay so just quickly run through what what it is so you'll have a ab dot post where you get the message okay and once you get the message then you send it to process event in process event you get the sender information and the text message that you know user is going is or is sending then you send that in send that text and the sender information to API I service and the API service will send you all the no it can give you all that data that you can pass okay so it'll be then the response dot result object and you can pass all that information and do or you can preview the booking application you do the booking and then and send the response back to the user but how do you deal with please I'm sorry that your hope is not overloaded your body is not over ordered but the your booking will be handled by a separate application right so when when you come to this you understand that the action is booked room or book hotel then you are going to call your booking API right so once your booking API sends you a confirmation then you send this information back to back to the Facebook so you need to have a call back here so once you get the information from your API and so that has to be written in your court so either you write it here or you write it in your you know API service I think there's an easy way to start with probably because you probably have a conversation ID yeah you have a sender ID here is a guy you know yep so you can do it here or you can do it right over there oh you know I appear service that you've developed so for your booking application will have your own ap right so if you can do that there yeah this is your mate no this is your gate this is your gate right this app is your this app gets all the data from the messenger and then it sends to the NLP engine so you have you can stop it here so you can figure out how many you know you can write a code that will log how many data it's getting from a particular send us if it is more than when I can define if it is 10 second power 10 messages per second you can throttle it here so the that residual Facebook gets to the FD a– maybe 1040 an LPN gene gets back yes yep let me just numbers so you you get the missus in your app then you send it back send it to NLP engine the NLP engine sends you a response then you decide what to do I don't know based on the action and based on the parameters you can decide so there are three things that you have to notice that there is action there's action incomplete and then the parameters if the action incomplete is true then that means you you do not do anything you just send the message back that means the user has not sent a required parameter like date or room type or something then obviously in your NLP engine handles that so that your message would be like what date or which room so you just pass send that message back to the messenger and get that input again your NLP engine will be able to understand that conversation and when it gets the date and room type then so on the second or third step your action incomplete will be false and then you can process the action so you can define the your function name in the action so if your action is booked hotel or book room you can complete your book room with and then you will have those parameters Hey is there a way to speak the conversation back to the NLP so that you can learn let's say in the past one month you answer is there a possibility thanks to that you've noticed all your conversation you get it in your logs so you can figure out what type of message people are sending and then you can if the message when engine is not able to figure out then it will have it'll ask you to know define here now when we said book carome then the engine has figured out that your engine type is booked hotel if some if we type something like you know switch on this light so obviously we have not defined anything for that so it will not be able to figure out so either you can create a new intent for this so this is a manual work if you want the bot to understand learn new things automatically that one I know I don't think they have that either you know probably you need you can build your own model for that you can build your own model that every message that the bot has not understood you pass it on to that model and that that model understands then probably you can deploy create a new domain for that if I know the user is under my deed how can I start a conversation if you already know the sender ID yes send a message later right you store that in your database and then probably you can have one more function where you can define that that function would run not you know a six o'clock in the morning or seven o'clock in the morning and then it will just send a message right so your application you should write a separate service for that get the get all those users and then just send send message to everyone everyone yeah there is a function called F bees send FB message so you can use that send epi message function to send so this is very simple send every message you need to pass the yo pays access token your sender ID and message data so your message data is actually a JSON so if you want to send a structured message data structure message then you can define this JSON can pass additional parameters like image URL and euro URL okay any other questions if I say the parties are chatting with you zone is when I mean is use the box there will be no settle for phone might continue chatting pencil over you can define that you can have a UI and then define you can create a lesser list item which all users are talking right now and then probably stop that particular person and then start conversing so so you have to develop that your own UI where you can get all the current active users that are talking to your board and then maybe stop a particular user so you have to write that logic if the flag is false then you know it will not send any message I think you can define a standard message i I do not have a sample code for that but you can define a standard message that you can send for the first time in the myth when the user clicks on your messenger you can send it standard message template that would be all it will be for the first time it will send and will not send after that no no it has to be no code yeah not an API okay okay any other question so these are some of the parameters that you need to understand from JSON so the indent named action parameters and the fulfillments dot space so these are the few of the parameters that you need to understand I mean we'll be able to deal with when you develop an app how do you create a development environment because it requires a HTTP URL so you download ng rock and then it will be able to create a HTTPS tunnel for your localhost I put the sample code at this location I can share this URL on the Meetup second download or you can also download from API dot AI so this code is same so these are some of the other platforms on I found the API dot AI as you know much more easy to learn and easy to implement compareto with dot ai there are some other platforms also available with you do not have to learn programming to you know create BOTS yeah talking about the domain that you saw there there are quite a few domains so those domains provide ready-made intent and entities that you would require so let's say home automation system so it will have all the ready-made entities over there and all the you know intents already built in over there so you do not have to know create so there are domains for whether there are or there is a domain for booking booking hotels and booking restaurants there quite a few other domains also available so but you have to pay pay for that so that's that becomes relaxed how do you collect the payment I I think you need to get Facebook's approval for that before you even develop I would suggest you talk to Facebook and then probably there you can yeah yeah Facebook doesn't have any payment of a right now but they insist that you if you want to develop anything if you want to collect payment then you better talk to them first yeah you know if you if you know the user beforehand if you have there then that is Facebook right so this this is so here we have a book now button but you know if you click corner then it will go outside Facebook but there is nowhere to collect payment inside Facebook now yep okay thank you for that that's all for today

Post Tagged with ,

Leave a Reply

Your email address will not be published. Required fields are marked *