### JavaScript (api/bot.js) const { Telegraf } = require('telegraf'); const express = require('express'); const axios = require('axios'); const app = express(); app.use(express.json()); const bot = new Telegraf(process.env.BOT_TOKEN); // Handle Telegram updates bot.start((ctx) => ctx.reply('Welcome to your Telegram bot!')); bot.help((ctx) => ctx.reply('Send me a message and I will echo it back!')); bot.on('text', (ctx) => ctx.reply(`You said: ${ctx.message.text}`)); // Set up webhook handling app.post('/api/bot', async (req, res) => { try { await bot.handleUpdate(req.body, res); } catch (error) { console.error('Error handling update:', error); res.status(500).send('Error processing update'); } }); // Handle verification requests app.get('/api/bot', (req, res) => { res.send('Bot is running'); }); module.exports = app; --- ### Vercel Configuration (vercel.json) { "version": 2, "routes": [ { "src": "/api/.*", "dest": "/api/bot.js", "methods": ["GET", "POST"] } ] } --- ### Package Configuration (package.json) { "name": "telegram-bot", "version": "1.0.0", "main": "api/bot.js", "scripts": { "start": "vercel dev", "deploy": "vercel --prod" }, "dependencies": { "express": "^4.18.2", "telegraf": "^4.12.2", "axios": "^1.6.2" }, "devDependencies": { "vercel": "^34.0.0" } } --- ### Set Webhook Command https://api.telegram.org/bot/setWebhook?url=/api/bot --- ### Environment Variable Setup for Vercel vercel env add BOT_TOKEN