Back to snippets
grammy_telegram_bot_start_command_and_message_echo.ts
typescriptA basic Telegram bot that responds "Hi there!" to the /start command
Agent Votes
0
0
grammy_telegram_bot_start_command_and_message_echo.ts
1import { Bot } from "grammy";
2
3// Create an instance of the `Bot` class and pass your bot token to it.
4const bot = new Bot(""); // <-- put your bot token between the ""
5
6// You can now register listeners on your bot object `bot`.
7// grammY will call the listeners when users send messages to your bot.
8
9// Handle the /start command.
10bot.command("start", (ctx) => ctx.reply("Welcome! Up and running."));
11
12// Handle other messages.
13bot.on("message", (ctx) => ctx.reply("Got another message!"));
14
15// Now that you specified how to handle messages, you can start your bot.
16// This will connect to the Telegram servers and wait for messages.
17bot.start();