Written in collaboration with Sushil Shaw
How to create a Telegram Bot API key and Connect with Node.js
Telegram: Telegram Bot API is used to send data programmatically.
Create a new bot with BotFather.
First, we go to the telegram search bar and search Botfather.
Then Click Start.
To get a token, send BotFather a message using the command “/newbot”.
Telegram will ask you to give a name for your new bot and choose something that ends with the word “bot”. For example, “my_first_bot”.
If your chosen name is available, BotFather will send you a token. It’s important that you save this token.
Then BotFather will give you an API Key. Do not share this API key with another person, maybe he or she can take control of your Telegram bot.
First message: Hello “User name”
Ok now you’re ready to go. Create a node project and install bot-api:
npm install — save node-telegram-bot-api
Create a file hello.js (or any other name) and inside the file use “require node-telegram-bot-api”:
const TelegramBot = require(‘node-telegram-bot-api’);
Then you need to assign the token you received earlier from BotFather:
const token = ‘YOUR_TELEGRAM_BOT_TOKEN’;
And now create a new bot :
const bot = new TelegramBot(token, {polling: true});
Let’s try out our bot and do some real world things. We need to get messages that user sends us, to do so we would use following code:
bot.on(‘message’, (msg) => {
//Hello username
});
Let’s create simple code here.
After that now open up your command prompt and type:
node hello.js
Go to your bot and hit on /start and then type “Hello” to it:
So, now that you know how to send and receive messages in your bot .
Ten articles before and after
How to create a Telegram bot with Swift using Vapor – Telegram Group
Introducing zilWatchBot. We are proud to introduce zilWatchBot… – Telegram Group
Stream Tweets to a Telegram channel – Telegram Group
Django Telegram Bot. В данной статье я расскажу о том как… – Telegram Group
data-rh=”true”>Telegram Bot for Lazy – Max Makhrov – Medium – Telegram Group
How I Connected with 10,000 people over a couple of weeks – Telegram Group
python Telegram bot pytelegrambotapi telegram bot simple – Telegram Group
Bot sederhana dengan menggunakan python! – Telegram Group
Telegram Secret Chat — Enable Now to be Secure – Telegram Group
Create Telegram Chatbot. In January 2021, Telegram announced… – Telegram Group