 Thanks Vivi for interesting talk. Are you guys geared up to build a bot? Yes. Okay, so it will be a short and quick little boring also. Okay, so we will start with basic introduction of what is, 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, and even if you do not have any programming knowledge, we'll still be able to build a bot today. Okay, okay, so we'll cover the basic concept of chat bot, then we'll build, you'll be able to build your own bot. We'll cover some basic concepts of api.ai and then we'll go through how to set up your own development environment and per sample code in Node.js. Okay, so what is a bot? I mean, I'm sure you guys have gone through all this. Okay, in short, if I say a 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.ai, vid.ai. There are some other applications as well, but we will only go through api.ai today. Okay, so a basic overview of how your architecture would be. What we need is a, you know, messenger where people are going to, you know, type the message. When they 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 you what you need to do and then you carry those tasks and then put your message back to the messenger. Right. Okay, so we'll quickly build a bot. Do you have a Facebook account? Okay, so the first step is to, you know, the first step is create a Facebook page. Okay, so we'll create a Facebook page first. Maybe, you know, okay, you can skip all the steps. Okay, so can we go to the next step? Okay, so we'll create a Facebook app. Just complete the task here. Okay, so once you come to this page, you will see this option called messenger. You click get started. Okay, and select the page that you created just now. Just authenticate. Okay, so copy this up to this page. It's all done. Yep. Can I go to next step? Okay, so we'll go to the NLP engine. Okay, let's go to api.ai. Okay, if you are on the login page, you need a GitHub account or a Facebook account to login. 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 the action you have to do and then carry out that action in your code. Okay, is it done? Can I go to next step? Okay, in the domains, you just switch on the small talk. Okay, and yeah, that's it. Okay, so we'll integrate directly with Facebook Messenger here. Okay, you go to the agent settings. Click on settings. Are you on this page? Yeah. So you just, you create a page token on Facebook app. So just paste it here. Okay, if you are not copied, just copy it from here. Verified token, you can give any string that, okay. And then you start. Right, so basically API dot AI 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 copy it, go back to your Facebook app, click on setup webhooks, the token, whatever you have given there, just type the same one here. Okay, you must see this green tick with complete. You are on which page? Yeah, so you have to select the page that you created just now. Okay. Click on setup webhooks. Yeah, so once you create the token, you have to provide that token in the API dot AI. And the webhooks section, just select the page that you just created. Okay, this one and this page should be same. This page, once you select, it will give you the token. You do 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 one little, right? So you can talk anything. So this is the same thing that you see in the messenger app as well. So it's tied to the messenger. Yeah, you go to the messenger. Can I have a unique ID to the bot now? Yep, it's your page ID. You can know once you go to messenger. Okay, now can I change the message? I mean, 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 API dot 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. Let's say for all these messages, maybe, you know, you want to. So for all these messages, if you want to change the response, just type the response here. Maybe, you know, you can give a character to the bot. Okay, so this is simple. But 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 mean, you can test that. So how do we know which room and where is to be booked? Yeah, so the bot, you have to give that, you know, intelligence to the bot. Let's say, so instead of book a room, I would say book a room for today. Okay, so immediately it understands that this is, you know, a date or something. So you can add a parameter here. So let's say, so this one is a date. Let me just save this. 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, these are the entities that is already defined in the system. So you do not have to worry about this. If you want to test whether this is working or not, you can just test it here. Okay, let's say, yep. So it understand that Sunday is 29th May. So it booked a room for you for 29th May, right? Okay, now if you think how do we, 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. Specify that, you know, this is a portal. So next time, okay, so in your code, you need to look for this action and then the parameter. And you should be able to fire a query to the backend API and complete the process. And then once the, the booking is complete, then you send this message back to your messenger. Right. This is a callback to some of the links from here? 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 do not need anything, but for your backend processes, you would 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 backend processes. Right. So how do you get the parameter? You just, the moment you select this, you will be able to, it will automatically creates, but sometimes it does not create, so you can, you know, pass this, 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, you know, this, and then you define a, so when somebody says book a room, then your engine will get this intent as a, you know, you will understand that you, the person wants to book a hotel and then it will, you know, run through this, this action. So what happens is we now put it to the messaging, we, we do something like, may I book a room, do you have a room for tomorrow? Yep. No, let's say. No, no, that's, that's what I asked. Yeah. What if you use more nature language, so instead you will say, may I, may I book a room for tomorrow? Yes. Yeah, so you'll have to define those in the intents that, if somebody says may I book, then obviously, you know, you can divide that intent into two things. One is directly, you, one is, you can define that, if somebody says book a room, then it has to go to the booking intent. If somebody says, you know, do you have a room, then you can put it on to a question, let's say, you know, enquiry for room and then your conversation can be different. It's not defined here, right? Yeah. If it is not defined here, then you. If you type may I book a room, what happens now? Yeah, probably it will book. But does the domain take over? Yeah. Okay. No, it should ask for this date. Maybe we have not saved this one yet. As long as there is a book and room in the working. As long as there is book and room, then it will work. So, yeah. We can ask all pictures instead. Yeah. You can. You want to change the reply? I want to reply with some pictures. Like how tech crunch does it? It replies with a card. The structure message. The structure message. Yeah. 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 will have to, when you pass the MSS data, you will have to define that it's the structure message and you can pass those data. Well, do you access the code? Okay. So, let me just go through a sample code. So, before we go there. Yeah. How do you do a continued conversation as in where the board actually remembers what you talked about? As in, here it's like book and room for Sunday. It's like just, I mean, it's a small piece of thing, right? Right. It's one accent. Yes. So, how about you go things where predict you? Yeah. I mean, there's, you need to know multiple things about a person before you actually. Okay. So, you can define, let's say, there are ways to do it. Like, there is one way is you define the required parameters here and you put the prompt here. Okay. If the user does not provide those parameters, so you collect it from here. Right. So, now we saw that if the user does not provide it, then you can, it prompts you again. The other way is also, let's say we can define like, entities, we can define the room type, let's say. Maybe I'll just quickly go through what we have already developed. Yeah. Right now, two of us are messaging the same bot, but I get the bot response because she doesn't get a bot response. But when she messaged the bot, I get a prompt from the page and say something to the message. Yeah. Are you sending it to the same page, both of you? Yeah. So, you have to make her an admin for your Facebook app as well as she has to like the page and probably will have. Yes. Yes. Yes. So, in the developer console, you have to make her an admin of that app. Right. Yeah. Admin or developer tester, there are quite a few other roles as well. Okay. So, you go here. So, you can define, you know, all these roles will be able to test your app. Yeah. What's your experience with this success rate of approval? I had applied one bot for approval, but it got rejected and that was almost a month back because it's, I mean, I developed that using with.ai and I don't think with.ai is, you know, mature enough. I mean, compared to api.ai, I found that it still lacks a lot of functionality. In api.ai, you can quickly build all your conversation here, but if you go to with.ai to build this, what I developed right now, it probably will take few hours. But yeah, I had. So, do you by now know what's the criteria of approval? Yeah. So, what they do is they, when you put for approval, you know, they will go through your app, whatever you have shown in your video. So, when you send it for approval, you have to create a video and then probably you submit and then they will go through that video and will understand what messages 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. Well, you can submit and get approved and then you change your bot to do that. Maybe, yeah, but then probably people would complain and then they might come to know. Or maybe they would be monitoring now, I don't know. But yeah, we had applied for this one. So, this is. We had applied for this one, but it's not approved yet. Okay, so. So, is it possible to exercise the bot with few of your friends, say for a very small page without a profile? Or is it always something public? So, you have three or four friends. Yeah. You just want to provide the answering service when you are abroad. Can you somehow? Yeah, so you develop an app and make all your friends as developers and testers. So, they will be able to access. So, you do not have to. If you make them testers, they will not be able to do it. You can make them testers so they cannot do anything. 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 in 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 know, you can just ask you which date. So, you say Sunday. So, what is what room type? You say. Okay, now if you look at the JSON, you will have action in complete false and your action name. If you go back one step previous, the action in complete will be true. That means your action is not complete yet. So, you just, you know, allow the bot to send the next message. Okay. Right. So, I will show you the sample code. What looks like. Aka.ai able to access like data, like user data, like the name and email and stuff. Yeah, you can get that in your inner code. So, we have to do it ourselves? Yeah. Now, to api.ai, you can pass the information. When you get it from Facebook, you can pass it on to the api.ai. So, if I'm getting the user data myself, how do I link the JSON that api.ai gives me the conversation? How do I know who I'm talking to? Does JSON tell me who I'm talking to? No, no, no. Your face, your own code, you'll be able to get that information. Right. Okay. So, we saw that the api.ai created an app for you, right? Yeah. And then it gave us a WebHook URL and we put that in the Facebook app. So, what you have to do is 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 api.ai. What you have to do is you have to install api.ai and then pass on this information to this code and then you know, so your, so when you run this, you will get your URL and you put this URL into your 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 WebHook 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? So, this is a sample code that you can use. You can run this and then whatever we did right now, it will be able to do that. Okay. If you want to know, this is on my GitHub, I can share that with you and it's also there on the api.ai SDK. You just download the Node.js SDK you will be able to get this. Okay. So, I will just quickly run through what it is. So, you will have a app.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 user is sending. Then you send that text and the sender information to api.ai service. And the api.ai service will send you all the, it can give you all that data that you can parse. Okay. So, it will be there in the response.result object and you can parse all that information and do if it is a booking application, you do the booking and then send the response back to the user. Right. How do you deal with limits? Sorry. That your bot is not overloaded. Your bot is not overloaded. Yeah. So, you say, you know, somebody spawns 1000 requests and the booking can take like half a month or a month. But your booking will be handled by a separate application. So, when you come to this, you understand that the action is book room or book hotel, then you are going to call your booking api. So, once your booking api sends you a confirmation, then you send this back to the Facebook. So, you need to have a call back here. So, once you get the information from your api and then... How do you prevent one user from spamming your bot? So, that has to be written in your code. So, either you write it here or you write it in your api service. Right. I think there is an easy way to throttle because you probably have a conversation ID. The sender ID here. You know that that is the sender ID and then you keep the guys consistently making the same calls and you start to throttle them. Yep. So, you can do it here or you can do it at your api service that you develop. So, for your booking application, you will have your own api. So, you can do that there. So, I think normally it is better to... that's why I was interested more in this code. Yeah, this is your gate. This is your gate, right? Yeah. This app gets all the data from the messenger and then it sends to the NLP engine. So, 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 you are getting from a particular sender if it is more than you know can define if it is 10 seconds 10 messages per second you can throttle it here. So, the architecture is that the message on Facebook gets to the app, the app basically then the NLP engine gets back. Yes. Yes. So, you get the message 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 either based on the action and based on the parameters you can decide. So, there are three things that you have to notice. There is action there is action in complete and then the parameters. If the action in complete is true then that means 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 your NLP engine handles that. So, your message would be like what date or which room. So, you just 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 on the second or third step your action in complete will be false and then you can process the action. So, you can define your function name in the action. So, if your action is book hotel or book room you can complete your book room and then you will have those parameters. All your conversation you can get it in your logs. So, you can figure out what type of message people are sending and then you can if the message engine is not able to figure out then it will have it will ask you to define your. Now, when we said book room then the engine has figured out that your intent type is book hotel. So, if you type something like 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 don't think they have that either 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 model understands and probably you can deploy create a new domain for that. Yep. So, if I know the user ID sender ID how can I start the conversation? If you already know the sender ID. Yeah. You wrote me hi. Yes. And then I want to send you a message later. Send you a message later right. You store that in your database probably you can have one more function where you can define that function would run at 6 o'clock in the morning or 7 o'clock in the morning and then it will just send a message. So, your application you should write a separate service for that get all those users and then just send message to everyone. So, can you just send FD message the call that was there in your process event? Yeah. Okay. Is it the same library that can be used? Yeah. There is a function called send FD message. So, you can use that send FD message function to send. So, this is very simple message you need to pass your page 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 structured message then you can define this JSON you can pass additional parameters like image URL and your URL. Any other questions? If I say the talk is chatting with user is when the admin is viewing the board right is there a way to intercept the talk from like chat continue chatting can you help admin want to take over? You can define that you can have a UI and then define okay you can create a let's say list item which all users are talking right now and then probably stop that particular person and then start conversing. 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. Yeah. I think you can define a standard message. I do not have a sample code for that but you can define a standard message that you can send for the first time when the user clicks on your messenger you can send a standard message template that will be all it will be for the first time it will send and it will not send after that. No, no, it has to be in a code not an API. Okay. Any other question? So, these are some of the parameters that you need to understand from JSON. So, the intent name, action parameters and the fulfillment dot speed. So, these are the few of the parameters that you need to understand I mean you will be able to deal with when you develop an app. How do you create a development environment because it requires a HTTPS URL. So, you download ngrock and then it will be able to create a HTTPS tunnel for your local host. I put the sample code at this location and I can share this URL on the meetup. Second download or you can also download API.ai. So, the code is same. So, these are some of the other platforms. I found API.ai as much more easy to learn and easy to implement compared to with.ai. There are some other platforms also available you do not have to learn programming to create bots. Yep, that's it. One question on API.ai. Why can we do it free compared to I don't make it right with a great one because it seems that the domain can only be reused when you are great and multi-thing is popular. Are you talking about the domain that you saw there? Yeah. There are quite a few domains. So, those domains provide readymade intent and entities that you require. So, let's say home automation system. So, it will have all the readymade entities over there and all the, you know, intents already built in over there. So, you do not have to, you know, create So, there are domains for weather. There is a domain for booking, hotels and booking restaurants. There are quite a few other domains also available. But you have to pay for that. So, that becomes really important. How do you collect the payment? Yeah. I think you need to get Facebook's approval for that before you even develop it. I would suggest you talk to Facebook and then probably you can Yeah. Yeah, Facebook doesn't have any payment to pay right now. But they insist that if you want to develop anything, if you want to collect payment, then you better talk to them first. Yeah. No, if you know the user beforehand, if you have their wallet information or something, or credit card information, and you know how to charge them, you will be able to do that immediately. If you, there is Facebook probably does not have a payment API now. I think what you can do is you can provide a secure link on the messenger. Yeah. Yeah. I mean, you can technically just ask secure, right? So that's not good. Yeah. So this is I think they will give a link. So here, you know, we have a book now button, but if you click on it, then it will go outside Facebook, but there is no way to collect payment inside Facebook now. Yep. Okay. Thank you for that. That's all for today.