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!
-
Use @BotFather to create your own bot and have the API key available
-
Created an account on Cloudflare and have created a worker and a KV
-
[Optional] Use @getidsbot or @RawDataBot or other means to get a
chat_id
for logging
-
Go to your Cloudflare worker, then go to
Settings
tab -
Add Environment Variables, Telegram bot
API_KEY
and logging group's chat_idTELEGRAM_LOG_CHAT_ID
(optional)And KV Namespace Bindings
-
Quick edit the worker and copy
worker.js
to the left panel -
Save & deploy
-
Call the following API
https://api.telegram.org/bot{YOUR TELEGRAM API KEY}/setWebhook?url={YOUR WORKER'S DOMAIN}
-
Done👍