Skip to content

Telegram bot to improve customer service of private medical clinic.

Notifications You must be signed in to change notification settings

iurii-umnov/medical-clinic-bot

Repository files navigation

Telegram BOT for Medical Clinic 🤖

Description

This bot is developed to improve customer service of private medical clinic.

Client functionality
  • Request a callback
  • Request an appointment in clinic
  • Get an online-consultation with doctor
  • See all contacts and links of the clinic
Admin functionality
  • Manage catalog content (create/delete doctors, update information)
  • See bot usage statistic
  • Manage admins list and their privileges

Features

  • Asynchronous work with ACID database
  • Quick migrations
  • Keeping Finite-State Machine states and state data across bot restarts
  • Caching to reduce load on the main (ACID) database
  • Multi-level administration with different privileges (accesses)
  • Admin actions logging
  • Link generation through parsing a website for online conferences (SberJazz)
  • Daily health check of parser
  • Statistic scheduler which automatically sends statistics to the admin chat every week/month/quarter/year
  • Protection of functionality and content from users who have been deprived of admin privileges
  • Integration with built-in Telegram payment (YooKassa)

Tech

Bot uses a number of open source projects to work properly:

  • Python - the main language of the project
  • Aiogram - telegram bot functionality
  • SQLAlchemy - database interaction
  • Alembic - database migrations
  • MySQL - content storage (main database)
  • Redis - Finite-State Machine storage
  • Memcached - caching
  • Selenium - parsing (video conference link generation)

Migrations

When you set up project you need to initialize the initial version of the database, i.e. create the tables from the scheme.

  1. First of all, you need to create revision file (apply autorevision):
    alembic revision --autogenerate -m 'Init'
    
  2. Secondly, you have to upgrade database to a final version with command:
    alembic upgrade head
    

👍 Done! 👍

Originally, there wasn't migrations/ folder in this project as well as alembic.ini file. They were generated by the command

alembic init migrations

and, then, edited to the current version.

Using PostgreSQL

If you want to use other relational database as a main content storage you need to keep in mind several changes that should be applied. Here are steps you must take to use PostgreSQL instead of MySQL:

  1. Install libraries "asyncpg" and "py-postgresql" to work asynchronously with PostgreSQL:
    pip3 install asyncpg py-postgresql
    
  2. Uninstall libraries related to MySQL:
    pip3 uninstall aiomysql pymysql
    
  3. Change prefix of DB_URL in src/core/secrets.py from "mysql+aiomysql" to "postgresql+asyncpg"
  4. Change function "json_arrayagg" to "array_agg" in src/db/query.py bacause PostgreSQL doesn't support "json_arrayagg" function and vice versa MySQL doesn't support "array_agg" function from SQLAlchemy.
  5. Remove "literal_eval" in src/handlers/admin/show_doctor.py and in src/handlers/admin/update_doctor.py. This thing is closely connected with the previous point and allows to parse array from a string when we use "json_arrayagg" for MySQL.

👍 Done! 👍

About

Telegram bot to improve customer service of private medical clinic.

Topics

Resources

Stars

Watchers

Forks