How to create inline keyboards in Telegram Bot that interacts with a spreadsheet (Part 3 of 3)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys we're finally here at the third and last stage at the tutorial and in this tutorial we're gonna create inline keyboards so that we won't have to type up commands into our BOTS whenever we want to pull up the budget expenses and savings instead what I want to have is a set of of buttons inside a bot that I can just press to give me the values for budget expenses and savings yeah but before that before we start tackling that I just wanna kind of like spend some time cleaning up our current thought one thing that I noticed is that when I was looking at the spreadsheet some of the words that I typed up they get placed inside the sheet as well and we don't want that right so technically the only things are the only items that we want to be processing or we want to be adding up into these sheep are items that were sent to the pot with a dash or with a hyphen because that's the box current way of splitting the text so if it doesn't have a dash or hyphen that probably means that it's not an item it's probably just me or the user testing the the bot etcetera and we don't really want the user to be you know to be sending random words and into the spreadsheet so we want to be able to tell the bot - like filter for anything that doesn't have a dash or whatever whatever symbol you you're gonna want to use or whatever character you're gonna want to use to UM split up your text in which case for this tutorial it's a ok so let's clean it up first okay so I'm just gonna add here else if it's a message I'm gonna put here if the message doesn't have a - I don't want you - oh sorry if a message has a - that's the only kind of message that I want you to put up inside the spreadsheet so I'm gonna say if if text index off index off and what character or whatever character we're choosing right so in this case - it's not equal to negative one so I don't nothing I forgot already how I found I liked how I learned that negative one in Google Apps Script means false but that's how it's currently being interpreted so I'm saying here if the text doesn't have sorry if the text has a - right because like this - will cancel out so this means like not equal to and false so technically that's like true right so I'm just gonna say if it has a - I want you I'm gonna copy this even the append actually so if the info text has a - that's the only time you need to create a date for it reformat the date for it right independent into the spreadsheet otherwise if it doesn't have a - you may return this message and then we're just gonna add up one more message here saying okay added to expenses the only words that has that that has a - or - will be replied to with an okay added to expenses otherwise if it's just random words if you're just like playing with your BOTS what it should return should be you know please send your purchases in this format so let's see if this will work [Music] okay uh-huh what's the name of what's the name of the oh here we go send message all right so after you guys can see I was testing it earlier already so I'm gonna say test it's not working let's see why not sign it hopefully that's it it's not it let's check our settings for deployment this is correct as is correct there why Shane Vendrell returned send message ID else if it's just a normal oh why is third up and Road there all right so it's working it's working as expected so any word without a dash gets replied to with this dialog message now let's say I'm like really putting in the night that I said like milk and I say like two dollars or something okay it says it's been added to the expenses and as you can see it was added but these words the test tests and K whatsoever they're never put into the spreadsheet so let's test that out see there's none if we say like I know like steak or something like 30 bucks there is no okay guys so here comes to pump one part the kids we're gonna start coding the inline keyboard now there's two main keyboards in telegram typically in documentation when when the word keyboard gets mentioned where the documentation is talking about this kind of keyboard where the keyboard is literally we're sorry the buttons are in the keyboard where you typically type things up but this is not a keyboard that we want we want an inline one which is inside inside inside the the message stream right so instead of us typing up the words expenses savings and budget I just want to have like you know small buttons so we can click so that we won't have to type those things up and in order to do that we will be needing a function that can accept three parameters so actually we can still say send message so I want yeah so it should be ID text and keyboard but instead of using this we're gonna use it better way a sexy your way of sending over to data I'm just gonna copy face it whatever I have here for the sake of whoops this is from my old bot where are we send message okay so I'm just gonna copy paste out and let's try to test it one out mmm-hmm okay so let's try it and test it out keyboard not obviously keyboardist not yet the frame so we're gonna try to define that right now and when you're creating a keyboard and lanky board for the matter there's two things that you need to have the first one is the text or the label of the button and the second one is a callback data they and I'll show you where that comes from but you know basically that's what gets sent to the to the API whenever someone pops are fancy in Lang keyboards and I'm just gonna copy paste this and I think the last one is savings I hope this works [Music] think of all I hope it will there you go whoa okay so it worked okay so yeah I want to show you guys what what happens when you click on one of these buttons right so cuz right now we need to type things up for the bot to occur and some values but I want to eliminate that completely and I want to be able to press on these and like get the results that I want order numbers that I want so let's revisit that URL where we can get some updates and pull up exactly what the users are sending so again that's just API that tag on that block and we're I'm just gonna add this in oops okay and then I'm gonna delete the web book for the meantime all right uh-huh why did that and and then I typed out get updates so I'm gonna try to get updates method and it's telling me now that I can you know I'm everything set up I can try sending things out and it should when i refresh this reflect here right so that's the first one so that's me sending a message but let's try clicking on a an inline keyboard what what happened and what would that data structure me there you go so let's look at it closely right so on the first message I sent out a message right so this is the whole contents that we parse I sent out a message it reflects is a message but the second part right the second data that gets gets sent to our okay that gets sent is no longer a message but I called back Cory so you no longer call it a message it's called back worry and a call back data as you can see here called that query data is exactly what the user the user sent so this is your call back data that you know it's part of a keyboard so whenever somebody somebody presses or taps one of those buttons this gets sent over sorry telegram about API just gets carried over okay you okay so back to coding now that we know what the data structure looks like let's turn on the web hook again and then basically so we have to prepare the but for when it receives a callback courier all right a callback data so starting from here right so we're saying there's two types of contents one is a message and one is them called that query so I'm just gonna say if content callback worry right it's just what I'm gonna say so if the contents are a core called back query and then else if that's message and I don't know if there are other kinds of content so I'm just gonna leave that open here so I'm not gonna use the word else so okay all right so now we're just prepping things up so if the client sends in or the user sensitive message we want to repeat or we want to keep on you know but I think the SSID and the sheet should be out here because the that's gonna be needed by our call back home corey code as well sorry okay so if it's a message we still want we still want this two lines here and then we no longer want this right or call buck that's gonna be process on our that's gonna be processed on our callback Cory called but we still want this okay okay so if what me received or what the but receives is a message you want it to flesh out the idea of the user and to flesh out the text of the user and once we have the text let's look at that text if it has like a - or a - and if it does have a - let's get the date well to format it and then let's split the text once the text is platelets appending it to the spreadsheet and send back a message confirming that we've appended it so a little spreadsheet otherwise if it doesn't have the - or the - let's continue sending our instructing the user what the right formatting is as far as like putting things on the spreadsheet is concerned right so what happens what happens when we get a callback query when the bottom receives a callback query pretty easy mm-hmm we basically just want this to happen right we want that you want this but instead we say if data ok so the first part I think is to flush out the ID sometimes call back three the ID and also what bar I need and then also flush out the data or to call back later I'm just going to be content that message that data i bowl sorry call back where death Dana don't and then let's just see okay let's see let's hope that this works from the arms where does not correspond so I guess I'm making sure so this green thing here corresponds to this keyboard this should correspond to the message [Music] let's publish it hope this works okay clicking on a budget perfect it's working okay now let's like send a message perfect and send a message with a - all right it looks like it's working finally so yeah I think that's the step by step process to getting to this point I know that this tutorial was limited but you know I took me a while when I was studying this myself and so you know I hope that you guys find this helpful and good luck on the project that you're doing if you guys have any questions feel free to reach out thank you
Info
Channel: Mars Escobin
Views: 16,236
Rating: undefined out of 5
Keywords: How to create inline keyboards, inline keyboards, bot, telegram, spreadsheet, coding code, programming
Id: 1xr2dZk0vKQ
Channel Id: undefined
Length: 22min 14sec (1334 seconds)
Published: Sat Apr 11 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.