{"id":15357591,"url":"https://github.com/cvzi/telegram-bot-cloudflare","last_synced_at":"2025-04-05T17:03:29.655Z","repository":{"id":146248977,"uuid":"539510087","full_name":"cvzi/telegram-bot-cloudflare","owner":"cvzi","description":"A minimal example of a Telegram Bot on Cloudflare Workers","archived":false,"fork":false,"pushed_at":"2024-07-13T21:13:33.000Z","size":59,"stargazers_count":368,"open_issues_count":1,"forks_count":56,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-29T16:03:03.769Z","etag":null,"topics":["bot-template","cf-worker","cloudflare-worker","cloudflare-workers","minimal","minimal-example","telegram","telegram-bot"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cvzi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-21T13:44:12.000Z","updated_at":"2025-03-27T15:16:16.000Z","dependencies_parsed_at":"2024-10-16T04:01:04.955Z","dependency_job_id":null,"html_url":"https://github.com/cvzi/telegram-bot-cloudflare","commit_stats":{"total_commits":19,"total_committers":4,"mean_commits":4.75,"dds":"0.42105263157894735","last_synced_commit":"d1c15e840fa259f34c39fd0eb3fc52f6c84c8e9b"},"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cvzi%2Ftelegram-bot-cloudflare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cvzi%2Ftelegram-bot-cloudflare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cvzi%2Ftelegram-bot-cloudflare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cvzi%2Ftelegram-bot-cloudflare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cvzi","download_url":"https://codeload.github.com/cvzi/telegram-bot-cloudflare/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247369953,"owners_count":20927928,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot-template","cf-worker","cloudflare-worker","cloudflare-workers","minimal","minimal-example","telegram","telegram-bot"],"created_at":"2024-10-01T12:36:49.830Z","updated_at":"2025-04-05T17:03:29.622Z","avatar_url":"https://github.com/cvzi.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Telegram Bot on Cloudflare Workers\n\nA minimal example of a Telegram Bot running on a Cloudflare Worker.\n\n## Setup:\n\n1. Get your new bot token from [@BotFather](https://t.me/botfather): https://core.telegram.org/bots#6-botfather\n2. Sign up to Cloudflare Workers: https://workers.cloudflare.com/\n3. In the Cloudflare Dashboard go to \"Workers\", then click \"Create application\" and then \"Create worker\"\n4. Choose a name and click \"Deploy\" to create the worker\n5. Click on \"Configure worker\" -\u003e \"Settings\" -\u003e \"Variables\"\n6. Add a new variable with the name `ENV_BOT_TOKEN` and the value of your bot token from [@BotFather](https://t.me/botfather)\n7. Add a new variable with the name `ENV_BOT_SECRET` and set the value to a random secret. See https://core.telegram.org/bots/api#setwebhook\n8. Click on \"Quick Edit\" to change the source code of your new worker\n9. Copy and paste the code from [bot.js](bot.js) into the editor\n10. Optional: Change the `WEBHOOK` variable to a different path. See https://core.telegram.org/bots/api#setwebhook\n11. Click on \"Save and Deploy\"\n12. In the middle panel append `/registerWebhook` to the url. For example: https://my-worker-123.username.workers.dev/registerWebhook\n13. Click \"Send\". In the right panel should appear `Ok`. If 401 Unauthorized appears, you may have used a wrong bot token.\n14. That's it, now you can send a text message to your Telegram bot\n\n## Bot behaviour\n\nThe bot will send the original message back with `Echo:` prepended.\nIf you want to change it, look at the function `onMessage()`. It receives a [Message](https://core.telegram.org/bots/api#message) object and sends a text back:\n\n```javascript\n/**\n * Handle incoming Message\n * https://core.telegram.org/bots/api#message\n */\nfunction onMessage (message) {\n  return sendPlainText(message.chat.id, 'Echo:\\n' + message.text)\n}\n```\n\n## bot2.js\n\nThe file [bot2.js](bot2.js) contains an improved bot, that demonstrates how to react to commands,\nsend and receive [inline buttons](https://core.telegram.org/bots/api#inlinekeyboardbutton),\nand create [MarkdownV2](https://core.telegram.org/bots/api#markdownv2-style)-formatted text.\n\n## bot3.js\n\nThe file [bot3.js](bot3.js) contains an improved version that replies inline queries with voice messages.\nThe voice messages should be stored in OPUS format and .ogg in the cloud you most like.\nThe audio files are listed in a JSON array with the following structure in a KV namespace called `NAMESPACE` and with following content under the key `input_files`.\n\nGo to *Workers \u0026 Pages* -\u003e *KV* and create a new namespace. Add a new key `input_files` and store the JSON structure from below with your own audio files.\n\nNow in *Overview* -\u003e your-worker -\u003e *Settings* -\u003e *Variables* -\u003e *KV Namespace Bindings* bind the namespace to a variable called `NAMESPACE`.\n\n```javascript\n [\n    [\n      \"File Name\",\n      \"URL\",\n      duration,\n      \"\u003ctg-spoiler\u003e caption \u003c/tg-spoiler\u003e\"\n    ],\n    [\n      \"test\",\n      \"https://example.com/my_file.ogg\",\n      5,\n      \"\u003ctg-spoiler\u003eDescription in a spoiler\u003c/tg-spoiler\u003e\"\n    ],\n  ]\n```\n## bot4.js\nThe bot4 is a bot that randomly reacts to messages received. It demostrates how to use big reactions when the 🎉 emoji gets chosen.\n\n\n## License\n\nThe source-code is licensed under the CC0-1.0 license. If you need a different license, there are also branches with the [MIT](https://github.com/cvzi/telegram-bot-cloudflare/tree/mit) and [GPL 3](https://github.com/cvzi/telegram-bot-cloudflare/tree/gnu-gpl-v3-or-later) license.\n\n---\n[![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcvzi%2Ftelegram-bot-cloudflare","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcvzi%2Ftelegram-bot-cloudflare","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcvzi%2Ftelegram-bot-cloudflare/lists"}