TeleBot bootstrap for Vercel
A simple bootstrap for TeleBot that will help you quickly develop or migrate your Telegram bot to Vercel
Both Serverless and Edge functions are supported !
How to use
Webhook receiver function:
import TeleBot from "telebot"
import {start} from "telebot-vercel"
const bot = new TeleBot(/* TELEGRAM_BOT_TOKEN */)
bot.on('text', msg => msg.reply.text(msg.text))
export default start({bot}) // Instead of bot.start()
Webhook setup function:
import TeleBot from "telebot"
import {setWebhook} from 'telebot-vercel'
const bot = new TeleBot(/* TELEGRAM_BOT_TOKEN */)
const path = 'api/webhook.mjs' // Receiver function path
export default setWebhook({bot, path}) // Instead of bot.setWebhook()
If you use plugins (including built-in ones), then you need to import them manually:
import TeleBot from "telebot"
import "telebot/plugins/shortReply.js"
import "telebot/plugins/regExpMessage.js"
... or specify them in vercel.json:
{
"functions": {
"api/**": {
"includeFiles": "node_modules/telebot/plugins/**"
}
}
}
Complete usage example
additional options:
You can also use- Multiple environments
- Default hostname
- Error output
Made with