Skip to content

A telegram bot to interactively check OFFICIAL COVID-19 stats for Romania and other countries.

License

Notifications You must be signed in to change notification settings

andreipradan/telegrambot

Repository files navigation

Welcome to telegrambot 👋

cloud build status coverage status black code style License: LICENCE.md

A Flask project to interactively check OFFICIAL COVID-19 stats for Romania and other countries.

doc

doc

doc

Setup

Prerequisites:

  • Create a new telegram bot by sending the /newbot command to BotFather here

    • give it a name: e.g. MyExtraordinaryBot (does not need to end in "Bot")
    • give it a username: e.g. my_extraordinary_bot (this one does need to end in "bot")
    • write down your token that BotFather gives you at the end. You will need it later on

Steps

  1. Start the Flask local server:

    $ TOKEN=<token_from_BotFather> python flask_app.py
  2. Ngrok

    Telegram bots need a https URL as a callback for sending update events. Details here

    Ngrok is a great utility used for exposing your localhost to a publicly accessible https URL

  3. Set the webhook URL for your telegram bot using the config/webhook.py script

    $ python config/webhook.py --token=1234567890:ABCD-aBsadfASDFasfdb-v
    Current webhook url: is not set up
    
    $ python config/webhook.py --token=1234567890:ABCD-aBsadfASDFasfdb-v --set
    INFO:root:Current webhook url: https://5efg4d21.ngrok.io/1234567890:ABCD-aBsadfASDFasfdb-v
    • replace the host and token with your own
    • your telegram bot should now be pointed to your newly created public URL that is tunneling to your localhost 5000 port
  4. Data source setup

    The telegrambot pull all of its data from mongodb collections

    Configure a MongoDB database:

    • Steps for setting up mongo db locally here
    • Steps for setting up a remote mongo db cluster here
      • set the MONGO_DB_HOST env variable with the MongoDB Atlas connection string
      • set the DATABASE_NAME on the environment (optional => defaults to "telegrambot_db")
  5. Populate database with initial data

    python config/sync_data.py --all
    • python config/sync_data.py --help for the complete list of parameters

Troubleshooting:

  1. Make sure you've set the correct TOKEN when starting the Flask server

    • the callback url contains your bot's token so if the TOKEN environment variable is not set correctly, when using the bot you will see a lot of 404s in the server console from the telegram bot trying to post callbacks (respond to commands) to an invalid URL
  2. Make sure ngrok is tunneling your localhost:

    • you can do this by navigating to the https URL that ngrok provided - directly into your browser
  3. Make sure you've set the correct webhook URL.

    > python config/webhook.py --token=1234567890:ABCD-aBsadfASDFasfdb-v
    Current webhook url: https://5efg4d21.ngrok.io/1234567890:ABCD-aBsadfASDFasfdb-v
    • should be the ngrok provided HTTPS URL + your telegram bot token

Run tests

pytest tests --cov .
  • for html coverage report add --cov-report=html

Upcoming features

  • English keys
  • More data sources
  • Charts and diagrams for historical data, stats based on gender, age, etc.
  • Storing historical data for Global regions/countries (currently only today's statistics)
  • TBD: more google cloud commands

Frontend

https://github.com/afourmy/flask-gentelella

Data sources

Author

👤 Andrei Prădan

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check the issues page

Show your support

Give a ⭐️ if this project helped you!

Buy Me A Coffee


This README was generated with ❤️ by readme-md-generator