Chatbot project with Django Admin and plugins
Modules are implemented in plug-ins:
/data- Getting information on phones and Organizations (You need a user key https://dadata.ru/api/)/chinese- For those who learn Chinese. Search for the etymology of hieroglyphs and translate into English (Using the playwrite library and website https://www.archchinese.com/)
Chatbot project with Django admin panel and with plug-ins and application configuration via Dynaconf
Currently, plugins are supported:
/chat- An interlocutor with a Gigachat model (you need a developer key)/chat_list- Chats with models from Ollama (you need the Ollama platform installed on the local network)/iris- Monitoring of IRIS servers from Intersystems/gitlab- Task reporter from GitLab projects (you need a token to read from the project)/weather- Weather forecast /weather_list- list /weather_Moscowin Moscow for a day and 7 days based on the weather service https://open-meteo.com/en/docs#location_and_time and the reverse geocoding service https://nominatim.openstreetmap.org/reverse/wiki- A service for getting articles from Wikipedia. For example,/wiki_Snowor/wiki_- enter the word/news- is an rss news aggregation service./news_list- list of feeds/inet- Internet search service/inet_ddg_- currently only in the DuckDuckGo search engine/admin- Group administration module- deleting system information about entering and exiting groups
- removing a user from a group for writing prohibited words
- receiving reports on users and changes in the CSV
/code- Module format for obtaining information from regional code directories of the Russian Federation and searching for a country at the beginning of the code
git clone https://github.com/SergeyMi37/telebot-plugins
cd telebot-pluginspython3 -m venv env-lin
source env-lin/bin/activate
# Create virtual environment for Windows
python -m venv env-win
source env-win/Scripts/activate
# Install all requirements:
pip install -r requirements.txtCreate .env file copy-paste this or just run cp doc/env_example .env
Create dynaconf.yaml file copy-paste this or just run cp doc/dynaconf.example.yaml dynaconf.yaml, don't forget to change tokens:
python manage.py makemigrations
python manage.py migratepython manage.py createsuperuseror
# .env DJANGO_SUPERUSER_PASSWORD=demo
python manage.py createsuperuser --noinput --username adm --email adm@localhost.compython run_polling.pyIf you want to open Django admin panel which will be located on http://localhost:8000/tgadmin/:
python manage.py runserver-
Статистика всех моделей Django:
python manage.py model_stats
-
Детальная информация о конкретной модели:
python manage.py check_model users.updates
-
Экспорт модели в файл json:
python manage.py model_import --model django_celery_beat.PeriodicTasks --file test.json --format json --import 0
или
python manage.py model_import --model django_celery_beat.PeriodicTasks --file test.json --format json
-
Экспорт модели в файл csv (по умолчанию):
python manage.py model_import --model django_celery_beat.PeriodicTasks --file sysotiom.csv --format csv
-
Импорт модели из файла json в режиме --dry-run - сухой запуск, без реального импорта:
python manage.py model_import --model users.User --file users.json --format json --import 1 --dry-run
-
Импорт модели из файла json:
python manage.py model_import --model users.User --file users.json --format json --import 1
If you want just to run all the things locally, you can use Docker-compose which will start all containers for you.
To run all services (Django, Postgres, Redis, Celery) at once:
docker-compose up -d --builddocker ps -adocker-compose ps --servicesdocker exec -it dtb_bot bashpython manage.py createsuperuseror
python manage.py createsuperuser --noinput --username adm --email adm@localhost.com # .env DJANGO_SUPERUSER_PASSWORD=demodocker logs -fdocker logs -f botСоздайте A-запись: bot.example.com → IP_сервера
BOT_MODE=webhook
DOMAIN=bot.example.com
DJANGO_DEBUG=Falsedocker-compose --profile pooling up -dsudo apt install caddy/etc/caddy/Caddyfile:
bot.example.com {
reverse_proxy localhost:8000
}sudo systemctl reload caddydocker-compose exec web python manage.py webhook setdocker-compose exec web python manage.py webhook info- Удалить вебхук:
docker-compose exec web python manage.py webhook delete
Замените <TELEGRAM_TOKEN> и <YOUR_DOMAIN> на свои значения:
# Установка вебхука
curl -F "url=https://<YOUR_DOMAIN>/<WEBHOOK_SECRET_PATH>/" \
https://api.telegram.org/bot<TELEGRAM_TOKEN>/setWebhookcurl -F "url=https://telega.example.com/<TELEGRAM_TOKEN>/" \
https://api.telegram.org/bot<TELEGRAM_TOKEN>/setWebhook
#Получить информацию о текущем вебхуке
curl https://api.telegram.org/bot<TELEGRAM_TOKEN>/getWebhookInfo
# Пример вывода
{
"ok": true,
"result": {
"url": "https://telega.example.com/<TELEGRAM_TOKEN>/",
"has_custom_certificate": false,
"pending_update_count": 0,
"max_connections": 40
}
}🗑 Удаление вебхука
# Удалить вебхук (переключиться на polling режим)
curl -F "url=" https://api.telegram.org/bot<TELEGRAM_TOKEN>/setWebhookПри установке вебхука можно указать дополнительные параметры:
# Ограничить типы обновлений
curl -F "url=https://<YOUR_DOMAIN>/<WEBHOOK_SECRET_PATH>/" \
-F "allowed_updates=[\"message\", \"callback_query\"]" \
https://api.telegram.org/bot<TELEGRAM_TOKEN>/setWebhook
# Установить максимальное количество соединений
curl -F "url=https://<YOUR_DOMAIN>/<WEBHOOK_SECRET_PATH>/" \
-F "max_connections=100" \
https://api.telegram.org/bot<TELEGRAM_TOKEN>/setWebhook

