 While solving some problem in our journey in the startup, we encountered one use case where we need interactive user interface. So we wanted to take input from the user in an interactive way so that they don't feel difficult. So one use case was gathering complaints from a user. So if you take any CRM, so people mostly get a ticket and they are later emailed or something like that. So they are followed up on my email. So if you have a phone application where you have like WhatsApp or Telegram and you use a Dane, you don't need to install any particular application again. So if we can take leverage of this application and we build it a bot on top of this, then user will feel like it's the same thing and you are not moving outside of what you are using today. So you are in the same way. So the vendor and the user, the merchant and the user are connected by a common app which is installed by many people. So that's how we figured out. So Telegram is one of the open source apps and they have an open API. So we figured out one bot. We created one bot and we started taking complaints from the users. So today I will discuss how to create a bot, how to send requests and how to store the information collected from the users on the server. For that, I think I will share this screen. You can actually increase the font size a little bit. It's easier to read. Yeah, this is my website. It's visible, right? Yes. That's my website. You can visit it at kandikiran.in. I will share this screen. First requirement is Python. So check the Python version. It should be at least 2.7. And one of the library we are going to use is Python Telegram bot. So it's available here. So this is the bot we will be using to create automated replies to the users. So the requirements here is pip. So in order to install pip, you need to use this command. Since pip is already there, it says it's already the newest version. Then pip install and also need virtual environment. So Python virtual environment is also already installed. So we will be creating a virtual environment. So what virtual environment does is basically it will create a clone of your Python installation into one of the folders where you will be working on. So that you will be having same... You can keep track of your packages and you can collaborate with others also. And also you can have different versions of the same library for different projects. So in order to activate your virtual environment, we need to use the activate command. So in order to confirm that you are in the virtual environment, you can see your virtual environment name in the parenthesis before you use the name. So once you are inside the virtual environment, you need to install Python Telegram bot. You need to install Python Telegram bot. And we also will be using a flash server to relay our data received from the users to the server. So pip install flask. When you type pip phrase, you will know what all packages have been installed. So we have flask and these are the recursive requirements from the first flask. And two important things are flask and the Python Telegram bot. So we will be writing our first Telegram bot. You can open your favorite editors. So in order to see the debugging messages, we need to log in. We will give the format here once you are done with this. So in the previous version of the library, we used to have telegram.bot where we give the token. So now the library has been updated and we have an updater which all has the calls. Something like we have these functionalities. So you can call updater.bit.me, updater.sendmessage, power message and all these functions are written with updater class now. So it's easy to have your encapsulation and less cluttered way of writing them. Just ask a question. Did you have to set up an account with the telegram first before you did this? Yeah, we need to have an account on the telegram. So your potentials for that will be something including this? Yeah, so actually there is a web interface for telegram. You can use this here. Web.telegram.org. So in order to create your account, you can directly go to web.telegram.org. It will ask you for your phone number. You need to give your phone number, you need to get one password. So once you are in, you can use it either through your app or we have built up this. But if you have more than one, so you have to have more than one. So it's like the phone that you are using. So you cannot have a second one or third one. No, you can create bots. You can use this bot further. So there is something called a bot further where you can create bots. So if you are using the telegram bot LA, you can see this console. So this is how bots look like in telegram. So this is how the welcome screen for any bot will be like. So when you enter a bot for your search bar there, you can see this screen something like this. And you press start. It will give you all the commands and options which it has. And now if I want to create a new bot, I go for a new bot. All right, a new bot, how are we going to call it? Please choose the name for your bot. Say, POSAsia. That is my bot. And good. Now let's choose a new name for your bot. It must end in bot like this for example. So whatever name you give, you have to append it with bot or underscore bot. So let's say POSAsia. I don't want to take up the names here. So if you want to create a POSAsia bot, so that you can create it. I want to just enter tg, tg means telegram workshop. So I'm going to give this name. Let's see if it's not taken up. It's not taken up. So done. And you get a token here. So you need to notify, take care of this token, save it somewhere or you can get it again. Maybe later. You can generate a new token in case you forgot it. So you can use slash token command. And you can cancel your bot. You can revoke permissions. You can set name, description. There are many options available here. You can go through that. And set commands. So we'll come again to this topic in set commands. And for now I'll take the token from here. What basically it does is, an updater will look for any updates from the user. So if user sends a message, you get an update. That's an update for the bot. So the bot keeps on checking in intervals 0.1 second or 110 seconds like that. And using that it will again, so based on the command it sends, it will run some handler. So it's the same event handling mechanism here. So we'll start with basing the function. So I'm going to write one function where if we send a command like start, you might have seen when the welcome screen has come. I've pressed the button start. So when we press that button start, what should happen? So I'm going to print and also... So in this, when we send a message, we need to take care of to whom we are replying. So we get updates from many users. So the bot can be used by many users. So each chat has a unique ID. So we have to reply to that specific unique ID. So we need to send that parameter. So in the parameter of update.message.chat.id and the message. So message is text. Hi. I am for cishia.eji.com. So command name is start and I'm assigning that start command to this method. Keep polling it. So this is our basic script for making a small start telegram automated board. Now I'm going to... What's the default in the other kinds of checks? 0.1, 100 ms. Would there be a portal in case you need it? Yeah, you can change that speed. Would there be an assign? Would there be a telegram portal in case? Telegram has volumes. They have scaled the servers so they don't have any trouble in it. But that can be a delay or a service again? They can be actually. So if we keep on requesting and I have been using the bot. So sometimes I have been kicked out like after one or two hours of continuous updates, pooling updates, I have been kicked out sometimes. So I think we need to use some cron job or something again here to keep that running forever. Dispatcher does this. So every telegram bot, we have some event handling mechanism, right? So dispatcher, we can use it to assign your commands and say if you have... In routing, in web applications, you have four or four handlers. You have controllers to do. So similarly, you have your dispatcher where unknown commands can be handed, where eco commands can be handed or where you can have your own specified commands and inline queries. So we will go to inline queries next. So dispatcher is used to basically handle your message, set your handlers. So we have added a telegram handler. So it says, this is the logger. So telegram updater debug one has started and entering the set web. So it goes to the api.telegram.org slash bot slash your token. So it authenticates itself and it starts pooling itself now. So if we go here, go back here, we have created a bot. Now we go to the bot. So since we haven't set any description or any about text or any help text, we won't get anything, just a starter. So click on the start. So you have got a message saying, hi, I am possession tgpoin. So this is basically your start method being executed. And we have written print hello. Let's go back to console and see what's happening there. So here it says, so as I said, it keeps on pooling. It takes from updates. If it gets any update, then it goes to the particular handler and executes it. So here, before entering senders, it has got an update object. The update object has been in that it has seen the start command. So it goes to entering send message. We've got the whole information of the bot, say possession tgpoin, and from where the request has already been sent. So my user name is Krantikinum01. And my name, first name, last name, type. So it's a private account, not a public account, and ID. So this is the chat ID and date and the message ID. So again, there's no message, so it keeps on pooling and says there are no updates on. So let's stop this. Go back. At this point, your bot is a public bot. Yeah, it's a public bot. Anyone can actually connect with now. Yeah, you can go to web.eleagram.org. So while you're testing and building this, is there a way to say, I'm not ready yet, I want to just keep it private first before I reset an option when you start this. I think there is one in the bot further where you can set option. So you have something called set privacy here. What message will tell your bot seeing groups and what it's presence like? It can get an attesting mode or it can be public or private. Only the ones who have the link or the user name of the bot can access it. And actually, since we are automating everything, we can use actually tokens to talk to each other. If a user has to talk to the bot, send a token. Then the bot that indicates you, then you can have services aware from the bot. So let's write one more eco bot where we send some message and it echoes. If you look, we have written a hello world in that. So this is a hello world printed here. That is not part of the debugger. So this is just a print command coming from the Python input for your eco bot. So for the start command, you don't have any arguments. If you give an argument, it will be from your URL. So say you have any bot has your own something similar to this. Web.elignant.org. At the rate, your bot name. Slash, if you give something like a get parameter, that can be taken as an argument here. So in your start, you can retrieve it as an argument. Then you can set, say, if some user is giving, my name is x or y, you can get the name from there. So for eco bot, I'm going to take a text. So any message you send, it can be handled by this function. So whatever method you give, it will be handled by that. So any message you type without any command, say if you do not give any slash equals slash something, this method is going to take care of that. Sorry. In eco bot, you don't need to give an argument here. So since we are taking the text whatever is entered, we just need to eco the text received by the updater. So the text received is, so what updater receives is, it receives a message update, which is a JSON string. So if you go back to telegram API, you can, I'll show you the JSON string, how the format is like. It has, the format is like this. It has from, and first name all the user details and also the date message ID. In here, we have message.txt. So we are passing the same message back to it. So if I say slash eco, which is not a command date which we did not write, slash echo hello world. So this should basically give us back the same slash echo hello world back, not just hello world. Which one? Same one. I'm not able to write it. It's pausasia.tg underscore word. Yeah. This is waiting for them to accept. It's still running, it's running in the back. It's running. I think you can send a message maybe. Are you able to find it on the? Yeah. Are you able to find it? Yeah. Sudeesh has sent it one. I got it. It's fosasia.tg underscore word. I'm trying to do a secret check. Secret check. With the bots, it's not working. Yeah. Handle command exists or you command not for. So it is similar to your handle underscore for not for function or any Django. If you have used Django or Plasma or any other web application, you might have written a route where you handle your for not for it. So this is similar to that. Any command which is not projects with the pre-registered bots or commands, it will throw an error saying command not. Let's convert some text to cap and return it. Captains. So we will take an argument here. We need to add the relevance this handler. So we call it caps. We got a reply from makeitcaps. So this is the argument we have taken. And it has converted into cap. And if you want to throw some HTML. Caps comes in. You might have. So shadow is working. I think you need to be there because of the camera. I will add all the new stuff here. Using HTML, you are trying to make a bold output. So if you use some process, you can throw a bold argument. So what do we say? Possession here should be tax. And we should be able to see that as strong. Let's try. This is how you get bold results. So you can use anything in HTML. So very few syntaxes like strong italics and font size you can play around with. You can even send emojis. As such in the library there is no validation. So you need to use validate as library. You can check the message size. So that's entirely up to the robot itself. And in telegram you have video upload limit of 50 MB. So even someone sends you a file. You can know the file header length and check the length of the payload you are getting. And if you think it is correct, then only receive or don't download. These are the emojis available for the telegram work. You can use any of this. So let's say if you want to use ant, you give telegram what emoji you got. And I am not writing any argument. I just want to see if it works. I got an emoji back. How you send your photo. So you can load it from your local disk using the open command. Or you can even specify a URL. So you are in here or you can specify your... You have to open your file and you send it. The command here is send photo. You can replace the photo with voice and video to send video and voice. Till now we have been... So there is no command option here. You can only just type in the messages. So in order to make the user experience better, so we have to go here and go down to set commands. It will say choose a bot to change the list of commands. Pause it, set the reward. So you need to give some... In the specified format here. So what all command do we have? We have start, make it caps, make it bold, emoji and photo. We don't need to specify start and default, make it caps. This is our entire... Telegram doesn't accept any capital letters in your commands. So all should be small case and no other special characters. You can use one to use those. This bot for father has no automatic. So if it's on a telegram and maybe they are in a couple of updates, you will get there. Maybe they will release an API for this also. Command list is updated. So when you go back to the bot, you see something like command slash. So when you click on this, you get all the options. It doesn't, you know, have a hit prediction as to what it does. It does. Say if you have... It does predictions. For the commands only. Why? If you didn't define the command as now, you already defined it. So now we try to get data from the user and save it on different services. So whenever a user comes to a bot, so what businesses require is, you want to know who has come to you so that you can contact them later back. Either through telegram or different means of communication. So let's try to build a feedback bot for this workshop. And we will be using a Plasma for that. We'll be creating a file in the same directory. Basic class. We'll be doing that in Plasma. Plasma app. For publication, you might be having something called a login attempt. So whenever a user tries to log in, you record it. So we'll have a start attempt here. Whenever a user clicks on the start button, we'll record it. This is recorded. This is recorded on the suffering database. So this is a different server. The script keeps on running. It checks for the updates from the user. And it sends a request to this server whenever the user connects to that. Is there any more for this? For the bot assistant administrator, more for the bot that you can check? Is it not recorded for problems? How many users have used it? I don't know. It's not there on the telegram. Request library. So I've installed request library. So people install request library. You'll send a request. Then retrieve the username as. Let's carry the ones which I'm trying right now. It's not working. So previously I've created one bot. So I'm showing the example from that. So this is the password which I created last night. So when you press start, what it does is take the username. And this is a text document. And we send a request to this class server with a start attempt. And we send the parameter username, start at the end time. So this is basically the log which we need to store. And if we have received a particular response, then send the text message as, it is a successful response. I'll say our class server is down. Then we have to say that our server is down. Please try it in data. So on the server side, if you see the console, so they have been a post request sent from our telegram bot. So we have a 200 and that means a success. And that post request had a user name. So from the bot it has been sent, and the chat ID and the time. So this is basically how you log, create records of the user. So similarly you can send any parent, any argument taken by the user, say it takes something, or some text has been here. Send it to the server, store it on server, analyze whatever you want to do. Or on the server you can search on different, or we can use another API to use with data. I guess you can close down this thing. Thanks.