1.0.1 • Published 2 years ago
telebot-vercel v1.0.1
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
You can also use additional options:
- Multiple environments
- Default hostname
- Error output
Made with 💜 by Vladislav Ponomarev