- Create
.env
file from.env.example
and fill in the secret. docker-compose up -d --build
to start the server.- Go to @EVNCommUnion_bot and send
/start
to start the bot.
Bot is described in telegram_bot_app/bot.py
. With a simple class with start
method to demonstrate some workflows.
Add database related code are in telegram_bot_app/redis_tools.py
. The database is Redis.
I've created a simple wrapper for Redis, so you can use it like a dictionary.
if not redis_tools.check_if_user_exists(redis_connection, database_user_key, redis_tools.ALL_USERS):
redis_tools.add_user_to_group(redis_connection, database_user_key, redis_tools.ALL_USERS)
To check if user exisis in built in key ALL_USERS
and add user to it if not.
Telegram username is used as a user key in database.
For my own keys I use _{key}_
format. To avoid collision with telegram usernames. For example:
ALL_USERS = "_telegram_users_"
GLOBAL_DATABASE_LOCK = "_global_database_lock_"
For storing some user data you can use {user}_conversation
as a key for conversation with a user. For example, if user with id 123
is in conversation with bot, you can store his data in 123_conversation
key.
- Install Docker and Docker Compose.