Code Monkey home page Code Monkey logo

cardib-rona-telebot's Introduction

CardiB-Rona-Telebot

I use this mini project to learn how to use telegram bot. Click on this link to test my bot @CardiRonaBot - idea inspired from this video.

The functionalities are simple:

  1. Echoes whatever the user says
  2. Typing /audio sends back a random audio file

Webhook instead of Polling

Much of the source code originates from python-telegram-bot. However, instead of polling, I used webhook instead. This is because polling is inefficient and the data is not real-time while webhook can act as a push notification, removing the need to constantly check for updates on the Telegram server.

Development

  1. Get the Telegram bot API token from BotFather
  2. Download source code and install requirements: pip3 install -r requirements.txt
  • You may also consider creating a virtual python environment.
  1. Create an environment file: touch .env.
  • Copy the contents over, similar to the template below.
  • Use your own credentials. Remember to keep your token information private!
TOKEN=1456236133:BAEMGzl4H-ii69FLhmM799cegl2CnRULffk
URL=https://0511a20g14a3.ngrok.io

Deployment

Local

  1. Download ngrok.
  2. Run ./ngrok http 5000 on one terminal. Copy the link and replace the value for the URL field in the .env file.
  • This opens up your local port to the public, which allows for external requests to be forwarded to your localhost endpoint. This is very useful for quick debugging.
  • localhost should work fine too if you are testing on the same network.
  1. Run python3 bot.py on another terminal.
  • Your bot should be working now.

Cloud

For production, I used heroku instead of ngrok. This way, you don't have to leave your terminal running. And the best part is that heroku is free to use!

  • Make sure to add the Config Vars key-value pairs, namely TOKEN and URL.
  • The value in the URL field will take the form like so: https://cardib-rona-telebot.herokuapp.com.

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.