A bare-bones Node.js Telegram bot template.
📣 Built with Telegraf
⚡ Spun up using Fastify
🚀 Hosted on Vercel as a serverless function
When prompted to provide the BOT_TOKEN
environment variable, paste the token provided by @BotFather
upon creation of the new bot.
├── api
│ └── serverless.js
├── src
│ ├── bot.js
│ └── webhook.js
└── vercel.json
vercel.json
- Funnels requests on any path (/(.*)
) to the handler function exported by/api/serverless.js
./api/serverless.js
- Creates a Fastify app with two functionalities (described below):bot
andwebhook
. It then exports a function accepting requests from Vercel and routes them to the Fastify app./src/bot.js
- Creates a Telegrafbot
object, adds its behavior, and attaches thebot
object to theapp
sowebhook
can access it/src/webhook.js
- Routes POST requests on the secret path to the webhook callback obtained from the Telegrafbot
. This essentially hooks the webhook requests to the bot's behavior.