Skip to content

Node.js Telegram bot template. Built with Telegraf and deployable as a serverless function in Vercel.

License

Notifications You must be signed in to change notification settings

galiarmero/telegraf-bot-vercel-serverless

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

telegraf-bot-vercel-serverless

A bare-bones Node.js Telegram bot template.

📣 Built with Telegraf
⚡ Spun up using Fastify
🚀 Hosted on Vercel as a serverless function

Deploy to Vercel

Deploy with Vercel

When prompted to provide the BOT_TOKEN environment variable, paste the token provided by @BotFather upon creation of the new bot.

How it works

├── api
│   └── serverless.js
├── src
│   ├── bot.js
│   └── webhook.js
└── vercel.json
  1. vercel.json - Funnels requests on any path (/(.*)) to the handler function exported by /api/serverless.js.
  2. /api/serverless.js - Creates a Fastify app with two functionalities (described below): bot and webhook. It then exports a function accepting requests from Vercel and routes them to the Fastify app.
  3. /src/bot.js - Creates a Telegraf bot object, adds its behavior, and attaches the bot object to the app so webhook can access it
  4. /src/webhook.js - Routes POST requests on the secret path to the webhook callback obtained from the Telegraf bot. This essentially hooks the webhook requests to the bot's behavior.

About

Node.js Telegram bot template. Built with Telegraf and deployable as a serverless function in Vercel.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published