How to build a Telegram BOT to suggest you pizza
Last night I was about to order pizza with my sister, and we had the same, never-ending problem. What pizza should I get?
Didn’t I already told you? I’m Italian. This means that pizza here is a ritual. We have so much choice. That’s why we still struggle deciding the perfect ingredients match. There’s too much offer, moreover we have a very bad memory.
So we had an idea: we should code a Telegram bot that suggest us the more delicious pizza, so we don’t struggle anymore!
First step: create a bot
This is a very easy step. Open Telegram and search for the BotFather. Yes, this story is full of stereotypes about Italy.
The BotFater is a bot as well, so it responds to some commands, like /newbot, which starts the creation of a bot. Follow the instruction provided from the BotFather and you will be good to go.
At the end of the questions about you and your bot the BotFather will give you an API key.
Save the key somewhere safe and don’t share it with anyone. That’s the key to access your bot from any programming language and give him instructions.
Let’s give instructions to the bot
Since I’m studying Java for a college exam I decided to use Java as programming language for the bot. You can use anything else you are handy with.
I found this useful library: https://github.com/pengrad/java-telegram-bot-api which provides an handy API in Java for Telegram. Awesome! Add it via Maven to your project and you are good to go.
I’m using NetBeans to do that and you can find the option to add it in the Dependencies folder.
I created a Main java file and I added an instruction for the bot: say “I love Pizza” on a public channel I created.
public class Main {
public static void main(String[] args) {
//create a new Telegram bot object to start talking with Telegram
TelegramBot bot = TelegramBotAdapter.build(“HERE YOUR API KEY”);
bot.sendMessage(“@pizzaciaopizza”, “I love Pizza”);
}
}
This worked. Good start. Thankfully my bot loves pizza.
I wanted to enable my bot to answer a command like “/recommendPizza” and to answer something. This sounds trivial, but it’s not, and I’m still looking into a simple server engine to do that. Therefore the tutorial ends here.
Do you have any suggestion? Maybe there’s a better language or environment to do what I’m trying to do.
Let me know!
Related Tags :
Ten articles before and after
How to code a Telegram Bot to get stock price updates in pure Python – Best Telegram
How to create a Telegram-RAT (Remote Access Trojan)-2020 – Best Telegram
How hackers are getting access to 1000s of Telegram accounts – Best Telegram
ParaState — Telegram AMA — April 04 – Best Telegram
BlockBank — Telegram AMA — April 02 – Best Telegram
Crypto Trading Bots — Are They Good For Telegram Messenger? – Best Telegram
Migrating to Slack Community to Telegram – Best Telegram
Release – PooCoin Price Bot – Best Telegram
How to be safer while using Telegram in Russia and Ukraine – Best Telegram
Bots, grupos, canales de Telegram y otros automatismos adorables – Best Telegram