fix: PostgreSQL compatibility and Telegram bot token validation
- Fixed PostgreSQL 18+ compatibility by using postgres:17 image - Added token validation for Telegram bot - Improved error handling in telegram_bot.py - Added scripts for bot token management - Cleaned up old QR codes and added new utility files
@@ -14,12 +14,35 @@ class TelegramBot:
|
||||
def __init__(self):
|
||||
# Получение настроек бота из базы данных
|
||||
bot_settings = TelegramSettings.objects.first()
|
||||
if bot_settings:
|
||||
TELEGRAM_BOT_TOKEN = bot_settings.bot_token
|
||||
self.bot = telebot.TeleBot(TELEGRAM_BOT_TOKEN)
|
||||
logging.info("[TelegramBot] Бот инициализирован с токеном.")
|
||||
if bot_settings and bot_settings.bot_token:
|
||||
TELEGRAM_BOT_TOKEN = bot_settings.bot_token.strip()
|
||||
|
||||
# Проверяем валидность токена
|
||||
if self._validate_token(TELEGRAM_BOT_TOKEN):
|
||||
self.bot = telebot.TeleBot(TELEGRAM_BOT_TOKEN)
|
||||
logging.info(f"[TelegramBot] Бот инициализирован с токеном для {bot_settings.bot_name}.")
|
||||
else:
|
||||
logging.error(f"[TelegramBot] Токен невалиден: {TELEGRAM_BOT_TOKEN[:10]}...")
|
||||
raise Exception(f"Невалидный токен Telegram бота. Обновите токен в базе данных.")
|
||||
else:
|
||||
raise Exception("Telegram bot settings not found")
|
||||
raise Exception("Telegram bot settings not found or token is empty")
|
||||
|
||||
def _validate_token(self, token):
|
||||
"""Проверяет валидность токена через Telegram API"""
|
||||
url = f"https://api.telegram.org/bot{token}/getMe"
|
||||
try:
|
||||
response = requests.get(url, timeout=10)
|
||||
result = response.json()
|
||||
if result.get('ok'):
|
||||
bot_info = result.get('result', {})
|
||||
logging.info(f"[TelegramBot] Токен валиден. Бот: @{bot_info.get('username', 'unknown')}")
|
||||
return True
|
||||
else:
|
||||
logging.error(f"[TelegramBot] Ошибка Telegram API: {result.get('description', 'Unknown error')}")
|
||||
return False
|
||||
except requests.RequestException as e:
|
||||
logging.error(f"[TelegramBot] Ошибка при проверке токена: {e}")
|
||||
return False
|
||||
|
||||
def start_bot_polling(self):
|
||||
logging.info("[TelegramBot] Бот начал работу в режиме polling.")
|
||||
|
||||
|
After Width: | Height: | Size: 69 KiB |
BIN
smartsoltech/media/static/img/project/3.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
smartsoltech/media/static/img/services/1_j0npR4p.png
Normal file
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 135 KiB |
|
After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 119 KiB |
@@ -29,9 +29,11 @@ SECRET_KEY = config('SECRET_KEY')
|
||||
DEBUG = True
|
||||
|
||||
# Allowed hosts and CSRF trusted origins
|
||||
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='').split(',')
|
||||
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='localhost').split(',')
|
||||
CSRF_TRUSTED_ORIGINS = config('CSRF_TRUSTED_ORIGINS', default='').split(',')
|
||||
|
||||
print(f"ALLOWED_HOSTS: {ALLOWED_HOSTS}")
|
||||
print(f"CSRF_TRUSTED_ORIGINS: {CSRF_TRUSTED_ORIGINS}")
|
||||
|
||||
# Application definition
|
||||
|
||||
|
||||
BIN
smartsoltech/static/qr_codes/request_3.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
BIN
smartsoltech/static/qr_codes/request_4.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.2 KiB |
BIN
smartsoltech/static/qr_codes/request_5.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
smartsoltech/static/qr_codes/request_6.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
@@ -7,7 +7,7 @@
|
||||
<div class="row mb-5">
|
||||
<div class="col-md-8 col-xl-6 text-center mx-auto">
|
||||
<h2>Contact us</h2>
|
||||
<p class="w-lg-50">Curae hendrerit donec commodo hendrerit egestas tempus, turpis facilisis nostra nunc. Vestibulum dui eget ultrices.</p>
|
||||
<p class="w-lg-50"></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row d-flex justify-content-center">
|
||||
@@ -28,7 +28,7 @@
|
||||
</svg></div>
|
||||
<div class="px-2">
|
||||
<h6 class="mb-0">Email</h6>
|
||||
<p class="mb-0"><a href="mailto:a.choi@smartsoltech.kr">a.choI@smartsoltech.kr</a></p>
|
||||
<p class="mb-0"><a href="mailto:a.choi@smartsoltech.kr">a.choi@smartsoltech.kr</a></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex align-items-center p-3">
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
<link rel="manifest" href="/static/manifest.json">
|
||||
<script src="{% static 'assets/js/modal-init.js' %}"></script>
|
||||
<link rel="stylesheet" href="{% static 'assets/css/modal-styles.css' %}">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
|
||||
|
||||
<script src="{% static 'assets/js/modal-init.js' %}"></script>
|
||||
<title>{% block title %}Smartsoltech{% endblock %}</title>
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
<a class="nav-link" href="{% url 'home' %}">Главная</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">Услуги</a>
|
||||
<a class="nav-link" href="{% url 'services' %}">Услуги</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">Контакты</a>
|
||||
<a class="nav-link" href="{% url 'about' %}">Контакты</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -6,9 +6,8 @@
|
||||
</svg></span><span>SmartSolTech</span></a><button class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navcol-5"><span class="visually-hidden">Toggle navigation</span><span class="navbar-toggler-icon"></span></button>
|
||||
<div id="navcol-5" class="collapse navbar-collapse">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<li class="nav-item"><a class="nav-link active" href="/services/">Услуги</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#">Наши проекты</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="/about/">О нас</a></li>
|
||||
<li class="nav-item"><a class="nav-link active" href="{% url 'services' %}">Услуги</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="{% url 'about_view' %}">О нас</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||