/cloudflare-telegram-bot-template

A very simple example of using Cloudflare worker to host a Telegram bot with webhook integration

Primary LanguageJavaScriptMIT LicenseMIT

Cloudflare Serverless Telegram bot

Cloudflare provides free serverless function hosting, calls workers, and public accessible URL that can trigger the function very quickly (according to their doc, the startup time is just 200ms). Only limitation are the runtime, rate limit and request size

But this still makes it one of the good options to host a small Telegram bot for FREE!

image

Prerequisie

  1. Use @BotFather to create your own bot and have the API key available

    BotFather
  2. Created an account on Cloudflare and have created a worker and a KV

    worker KV
  3. [Optional] Use @getidsbot or @RawDataBot or other means to get a chat_id for logging

How to use the code

  1. Go to your Cloudflare worker, then go to Settings tab

  2. Add Environment Variables, Telegram bot API_KEY and logging group's chat_id TELEGRAM_LOG_CHAT_ID(optional)

    And KV Namespace Bindings

    settings
  3. Quick edit the worker and copy worker.js to the left panel

    Quick edit
  4. Save & deploy

    Save and deploy
  5. Call the following API https://api.telegram.org/bot{YOUR TELEGRAM API KEY}/setWebhook?url={YOUR WORKER'S DOMAIN}

    webhook
  6. DonešŸ‘