A lightweight, serverless Telegram bot built with grammY and Express, optimized for deployment on Vercel.
- Serverless Ready: Configured to run on Vercel's serverless functions via Express and
@vercel/node. - grammY Framework: Built on top of the powerful and modern
grammyframework. - Webhook Integration: Automatically configures and handles Telegram webhooks on startup.
- Parse Mode Plugin: Pre-configured with the
@grammyjs/parse-modeplugin (MarkdownV2 default). - Environment Driven: Uses
.envfor secure configuration.
- Node.js (v14 or newer)
- A Telegram Bot Token (get it from @BotFather)
- A Vercel account for deployment
-
Clone the repository
git clone https://github.com/ThiruXD/Vercel-JS-TG-Bot.git cd Vercel-JS-TG-Bot -
Install dependencies
npm install
-
Environment Setup Create a
.envfile in the root directory and add the following variables:BOT_TOKEN=your_telegram_bot_token_here BASE_URL=your_vercel_deployment_url_here # e.g., https://your-app.vercel.app
To run the bot locally, use the standard start command. (Note: Since this bot uses webhooks, you may need a tool like ngrok to expose your local server to the internet for Telegram to send updates).
npm startThis project is fully pre-configured for Vercel deployment.
- Push your code to GitHub.
- Import the project into your Vercel dashboard.
- Add Environment Variables: Ensure you add
BOT_TOKENandBASE_URLin the Vercel project settings. - Deploy: Once deployed, the bot will automatically set its webhook URL to
<BASE_URL>/api/webhook.
If you need to manually check or set your webhook status, you can use the following URL patterns (replace <BOT_TOKEN> and <BASE_URL>):
- Set Webhook:
https://api.telegram.org/bot<BOT_TOKEN>/setWebhook?url=<BASE_URL>/api/webhook - Get Webhook Info:
https://api.telegram.org/bot<BOT_TOKEN>/getWebhookInfo
index.js: Main entry point. Initializes the bot, sets up the Express server, configures the webhook, and handles incoming requests.bot/: Directory containing bot logic (e.g.,commands/for command setup).vercel.json: Vercel configuration file specifying routes and build parameters.package.json: Project dependencies and scripts.
Contributions, issues and feature requests are welcome! Feel free to check the issues page.
- Author: ThiruXD
- MKishoreDev
- Otazuki004
This project is open-source and available under the MIT License.