Skip to content

This is a simple chatbot for Telegram. It is written in Python and uses the aiogram.

License

Notifications You must be signed in to change notification settings

LagrangeH/chat-bot-telegram

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Workflow Status GitHub repo file count Python 3.10

This is a simple chatbot for Telegram. It is written in Python and uses the aiogram. Try it out here

Features

  • The bot can send a random picture with a cute cat. The /cat command is used for this (by TheCatAPI)
  • Currency conversion is available using the /convert command (by Exchange Rates API.io)
  • Using the /weather command, you can find out the weather in any city (by OpenWeatherMap)
  • The /poll command allows you to create a poll
  • All commands are also available in the Telegram groups
  • Throttling is used to save resources and API requests

Installation

  1. Install Python 3.10

  2. Install Poetry and add it to the PATH

    curl -sSL https://install.python-poetry.org | python3 -
  3. Check that Poetry is installed correctly

    poetry --version
  4. Clone the repository

    git clone https://github.com/LagrangeH/chat-bot-telegram.git
  5. Go to the project directory

    cd chat-bot-telegram
  6. Create a virtual environment

    poetry env use python3.10
  7. Install dependencies

    poetry install
  8. Create .env file (copy .env.dist and rename it to .env)

    cp .env.dist .env
  9. Fill in the .env file

    DEBUG=False
    # https://t.me/botfather
    BOT_TOKEN=
    # https://thecatapi.com/ (Optional)
    CAT_API_KEY=
    # https://openweathermap.org/home/sign_up
    WEATHER_API_KEY=
    # https://exchangeratesapi.io/
    EXCHANGE_API_KEY=

Usage

  1. Run the bot

    poetry run python bot.py
  2. Send a message to the bot in Telegram

  3. Use the /help command to see all available commands

Testing

The pytest framework is used for testing. Some unit-tests require parameters to be passed in.

  • Parameters can be optionally passed in command line mode:

    poetry run pytest /tests --cat-api-key="..." --weather-api-key="..." --exchange-api-key="..."

If some parameters were not passed in command line mode, they will be taken from the .env file, otherwise, tests that require these parameters will be skipped.

  • To run tests with parameters passed from .env or without passing parameters, the following command is sufficient:

    poetry run pytest /tests

About

This is a simple chatbot for Telegram. It is written in Python and uses the aiogram.

Topics

Resources

License

Stars

Watchers

Forks

Languages