The Bot.on() method is used in the Node.js Modern Tele graf Bot Framework. This Framework provides various functions to interact with the official Telegram Bot API. This method is executed when a particular event occurs during the conversation with the bot for eg: Events like Sending text, Sending Photo, etc these operations handle by Context function.
TelegrafBot.on(event, Context function)
Parameters: This Method accepts two parameters as mentioned above and described below:
1.Event: Occurrence of particular activity during the conversation with bot.
2.Context function: This function encapsulate telegram update information.
Return Type: The return type of the function is void.
Installing Module: Install the module using the following command:
npm install telegraf
Steps to get the keys:
1.First, get the GET BOT_TOKEN from BOTFATHER in telegram. Just search for BOTFATHER in Telegram and select the verified one as shown below:
2.Type /start and then click on /newbot as shown below:
3.Now type the name of the bot and that must be unique.
4.Now just copy the token From the BotFather. And for deleting the token simply search /delete token in BotFather.
Run bot.js file using the following command: