This tutorial will guide you through the process of creating a simple Telegram bot that greets users. You will be using the language and to write the code and the framework. JavaScript Node.js GrammY Why GrammY? There are several alternatives for the development of Telegram bots in JavaScript like or . The first one is more just a library than a full-fledged framework. The second one is old and mature. But is relatively new, modern, and rapidly gaining popularity. node-telegram-bot-api Telegraf GrammY Furthermore, it has excellent documentation and a supportive community that can assist. And last but not least there is not a single article about on the , so let’s fix it! GrammY HackerNoon Meet the Hello Bot We will develop a simple bot that can greet people in different languages. It’s a great example to learn how to process text messages and commands. Creating a bot and getting token First, you need to create a bot account. To do this you need to use the . As the description says BotFather BotFather is the one bot to rule them all. Use it to create new bot accounts and manage your existing bots. Open the bot, send command follow the instructions, create a bot and get a token. /newbot Project set up As a prerequisite, you have to have installed. The easiest way is to download it from the and install it. Node.js official site The set up is usual for projects. Сreate an empty folder open it in Terminal and run command. Then install the package with . And create an empty file. Eventually, you will get the following project structure. Node.js grammy-hello-bot npm init -y GrammY npm install grammy index.js The source code Put the following code into the file. index.js const { Bot } = require('grammy'); const bot = new Bot(''); // <-- put your bot token here (https://t.me/BotFather) bot.command('help', (ctx) => { ctx.reply(` The bot could greet people in different languages. The list of supported greetings: - hello - English - salut - French - hola - Spanish `) }); bot.hears('salut', (ctx) => ctx.reply('salut')); bot.hears('hello', (ctx) => ctx.reply('hello')); bot.hears('hola', (ctx) => ctx.reply('hola')); bot.on('message:text', (ctx) => ctx.reply(`Greeting "${ctx.update.message.text}" is not supported.`)) bot.start(); Let’s go line by line. First, we are requiring the module and creating an instance of our bot. It’s important to specify the bot token you got from the here. GrammY BotFather const { Bot } = require('grammy'); const bot = new Bot(''); // <-- put your bot token here (https://t.me/BotFather) Now register a middleware to process command and to reply with instructions. Commands are just text messages that start with , like , etc. You can come up with your own commands when you are developing a bot. And middlewares are just functions that process messages. /help / /start /help bot.command('help', (ctx) => { ctx.reply(` The bot could greet people in different languages. The list of supported greetings: - hello - English - salut - French - hola - Spanish `) }); The code above basically says: “If you got a message with command, just call this function and stop processing the message”. Meaning if one middleware processed a message, the other will not get a chance to do it. Middlewares are called one by one in the order they were registered. /help Then, using method we are registering middlewares that process different greetings and reply with it to the user. hears bot.hears('salut', (ctx) => ctx.reply('salut')); bot.hears('hello', (ctx) => ctx.reply('hello')); bot.hears('hola', (ctx) => ctx.reply('hola')); And then a middleware that processes every text message that wasn’t processed by middlewares above. This middleware is necessary for the case when a user sends a greeting that is not supported by the bot. bot.on('message:text', (ctx) => ctx.reply(`Greeting "${ctx.update.message.text}" is not supported.`)) And then we are starting our bot. After that, it will begin to listen for messages from Telegram using a long-polling mechanism. bot.start(); Time to test it. Run the bot with command. Leave it running. Open and send something to the bot. node index.js Telegram Links GrammY documentation GrammY source code GrammY Telegram group Bots: An introduction for developers Telegram Bot API documentation