This content originally appeared on HackerNoon and was authored by Alexander Nekrashenko
\ Hi there, my name is Alex Nekrashenko, you can think of me as an software-architect or fullstack developer. Eventually this arcticle isn’t about it. It’s about how I create my own telegram bot first time. I wanna share with you how I was choosing stack and why I decided to write my own telegram API library on NestJs.
\ Let’s start this story consistently, may be this article will be content from several parts. Here I will try to explain the base moments about the structure or architect as well and some others important things.
\
How does Telegram Bot API work?
To make it clarify, telegram bot is just an API. Create it is extremly simple. You just need to find the offical telegram bot with funny name the BotFather and setup you bot in it, using them command.
\
After you set your bot up, you will have gotten special key. Exactly this key you can use in your future API, that will controll all the conversation in bot chat.
\ \
Start working with NestJs
Let’s begin with creating a skeleton for our future application, the base functionality for the standart commands.
To make it easier I just copy/paste commands from the official website NestJs documentation, you just need to install CLI and execute the command
\
Project map
Well done, almost all the work is done! Now take a look at my project map
\
It must be easy, you see two folders:
\
telegram - there is nothing special with this folder, I just thought that all existence library about the telegram API for the NestJs weren’t so suit for me because either they are very compilcated or irrelevant. And I decided to make my own, that may be will be released soon.
\
bot - the folder with exactly all bot API functionality, like commands, botUpdates, utils etc…
\ What is commands and botUpdates you’re asked, well, I’ll try to be consice, this is what we can find on the official Telegram API documentation here https://core.telegram.org/bots/api#getupdates
As you can see, telegram will be reacted on every event related with your bot and then it will aware you about it with this method. All the info from telegram we get from this method.
\ Getting back to my constructions in bot folder
\
If we have one method getUpdates from telegram, that’s what I thought about: I will define the special event that I need, and make realisation for it and that’s exactly what I do. I define event in botUpdates and if it is consistent with the command that I also define by myself I direct it to the commands folder and make realization there.
Database service
\n
\ \n
This content originally appeared on HackerNoon and was authored by Alexander Nekrashenko
Alexander Nekrashenko | Sciencx (2024-06-20T20:27:28+00:00) How I Created My Own Telegram Bot – Pt. 1. Retrieved from https://www.scien.cx/2024/06/20/how-i-created-my-own-telegram-bot-pt-1/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.