realByg / cfworker-telegrambot-template

Host your Telegram bot on Cloudflare workers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ€– cfworker-telegrambot-template

Host your Telegram bot on Cloudflare workers

πŸƒβ€β™€οΈ Setup

  1. Install wrangler and login with your Cloudflare account.
    $ npm i @cloudflare/wrangler -g
    
  2. Install ngrok for local port forwarding.

🎴 Getting started

  1. Generate your project and install the dependencies.
    $ wrangler generate my-project https://github.com/zayabighead/cfworker-telegrambot-template --type=webpack
    $ npm i
    
  2. Rename bot.config.example.js to bot.config.js and setup your bot configuration.
    // bot.config.js
    module.exports = {
        token: '', //get your bot token from @botfather
        webhookPath: '/wefwefwefe', // a random string
    }
    
  3. Rename wrangler.example.toml to wrangler.toml and setup your wrangler configuration.

πŸ‘‰ Development

The main idea is to set up a local dev port and use ngrok to forward the port after setting the ngrok temporary url as the bot's webhook.

  1. Run npm run ngrok to start ngrok local port forwrading.
  2. Run npm run webhook to set the webhook for the bot.
  3. Run npm run dev to start wrangler dev.

πŸ“’ Deployment

  1. Run npm run webhook to set the webhook for the bot.
  2. Run npm run publish to publish to a Cloudflare worker.

🀨 Limitations

πŸ“˜ Useful docs

About

Host your Telegram bot on Cloudflare workers


Languages

Language:JavaScript 82.5%Language:TypeScript 17.5%