GithubHelp home page GithubHelp logo

guardianangelww / telegram-bot-cloudflare-fav Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cvzi/telegram-bot-cloudflare

0.0 0.0 0.0 10 KB

A minimal example of a Telegram Bot on Cloudflare Workers

License: Creative Commons Zero v1.0 Universal

JavaScript 100.00%

telegram-bot-cloudflare-fav's Introduction

Telegram Bot on Cloudflare Workers

A minimal example of a Telegram Bot running on a Cloudflare Worker.

Setup:

  1. Get your new bot token from @BotFather: https://core.telegram.org/bots#6-botfather
  2. Sign up to Cloudflare Workers: https://workers.cloudflare.com/
  3. In the Cloudflare Dashboard go to "Workers" and then click "Create a Service"
  4. Choose a name and click "Create a Service" to create the worker
  5. Click on "Quick Edit" to change the source code of your new worker
  6. Copy and paste the code from bot.js into the editor
  7. Replace the TOKEN variable in the code with your token from @BotFather
  8. Optional: Change the WEBHOOK variable to a different path and the SECRET variable to a random secret. See https://core.telegram.org/bots/api#setwebhook
  9. Click on "Save and Deploy"
  10. In the middle panel append /registerWebhook to the url. For example: https://my-worker-123.username.workers.dev/registerWebhook
  11. Click "Send". In the right panel should appear Ok. If 401 Unauthorized appears, you may have used a wrong bot token.
  12. That's it, now you can send a text message to your Telegram bot

Bot behaviour

The bot will send the original message back with Echo: prepended. If you want to change it, look at the function onMessage(). It receives a Message object and sends a text back:

/**
 * Handle incoming Message
 * https://core.telegram.org/bots/api#message
 */
function onMessage (message) {
  return sendPlainText(message.chat.id, 'Echo:\n' + message.text)
}

The file bot2.js contains an improved bot, that demonstrates how to react to commands, send and receive inline buttons, and create MarkdownV2-formatted text.


JavaScript Style Guide

telegram-bot-cloudflare-fav's People

Contributors

cvzi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.