- Grammy - Hosting: Cloudflare Workers (Node.js)
- Grammy - Hosting: Cloudflare Workers (Deno)
- Cloudflare Environment Variables
- Cloudflare Secrets Variables
- Install dependencies.
npm install- Edit
package.json, repalcename,version, anddescriptionwith your bot's information. - Edit
wrangler.toml, replacenameto your workers app name, andaccount_idwith your Cloudflare account ID. Access it at Cloudflare Workers Dashboard. - Edit
.dev.vars, replace:BOT_TOKENwith your bot's token. (See Grammy - Getting Started).BOT_INFOwith your json bot info, make it one line like below. Get it by accessinghttps://api.telegram.org/bot<BOT_TOKEN>/getMe.
{"id": 1234567890,"is_bot": true,"first_name": "BotName","username": "BotNameBot","can_join_groups": true,"can_read_all_group_messages": false,"supports_inline_queries": false} - Edit
.gitignore, uncomment the line# .dev.varsandwrangler.tomlto exclude the file in the repository.
- Open
index_dev.ts. - Compile the TypeScript file
npx tsc. - Run the
index_dev.tsfile. It will use long polling to get updates from Telegram by calling bot.start().
- Open
index.ts. - Compile the TypeScript file
npx tsc. - Run the command line
npm run start. - From VS Code panel (
Ctrl + `orCtrl + J), open PORTS tab. - Click Forward a Port, then enter the port number from 3rd step, example:
8787. - Right click the row, then change the port forwarding to Public.
- Set webhook by accessing
https://api.telegram.org/bot<BOT_TOKEN>/setWebhook?url=https://<PORTS_FORWARDING_LINK>from your browser. - Test by sending message to Bot.
- If you want to stop the server, press
Ctrl + Cin the terminal. Don't forget to private the port forwarding. - If you want to remove the webhook, access
https://api.telegram.org/bot<BOT_TOKEN>/setWebhookfrom your browser. Blank url will delete the webhook.
- Open
index.ts. - Compile the TypeScript file
npx tsc. - Run the command line
npm run deploy. - Set webhook to deployed URL by accessing
https://api.telegram.org/bot<BOT_TOKEN>/setWebhook?url=https://<MY_BOT>.<MY_SUBDOMAIN>.workers.dev/from your browser. - Test by sending message to Bot.
Good Luck!