Skip to content

ThiruXD/Vercel-JS-TG-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

113 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vercel JS Telegram Bot

A lightweight, serverless Telegram bot built with grammY and Express, optimized for deployment on Vercel.

🚀 Features

  • 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 grammy framework.
  • Webhook Integration: Automatically configures and handles Telegram webhooks on startup.
  • Parse Mode Plugin: Pre-configured with the @grammyjs/parse-mode plugin (MarkdownV2 default).
  • Environment Driven: Uses .env for secure configuration.

🛠️ Prerequisites

  • Node.js (v14 or newer)
  • A Telegram Bot Token (get it from @BotFather)
  • A Vercel account for deployment

📦 Installation

  1. Clone the repository

    git clone https://github.com/ThiruXD/Vercel-JS-TG-Bot.git
    cd Vercel-JS-TG-Bot
  2. Install dependencies

    npm install
  3. Environment Setup Create a .env file 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

💻 Local Development

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 start

☁️ Deployment to Vercel

This project is fully pre-configured for Vercel deployment.

  1. Push your code to GitHub.
  2. Import the project into your Vercel dashboard.
  3. Add Environment Variables: Ensure you add BOT_TOKEN and BASE_URL in the Vercel project settings.
  4. Deploy: Once deployed, the bot will automatically set its webhook URL to <BASE_URL>/api/webhook.

Useful Telegram API Endpoints for Debugging

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

🗂️ Project Structure

  • 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.

🤝 Contributing

Contributions, issues and feature requests are welcome! Feel free to check the issues page.

©️ Credits

📝 License

This project is open-source and available under the MIT License.

About

A lightweight, serverless Telegram bot built with grammY and Express, optimized for deployment on Vercel.

Topics

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors