|
|
|
|
@ -1,305 +1,128 @@
|
|
|
|
|
# bot_message.py
|
|
|
|
|
import re
|
|
|
|
|
import json
|
|
|
|
|
import qrcode
|
|
|
|
|
from ai_agent.api_common import get_ai_agent, call_ai_agent, get_contact_meta
|
|
|
|
|
from max_bot.max_api import *
|
|
|
|
|
from max_bot.models import PromoCode
|
|
|
|
|
from max_bot.models import Client, Contact, PromoCode
|
|
|
|
|
from restoran_max_bot.bot_started import check_registration
|
|
|
|
|
from restoran_max_bot.common import *
|
|
|
|
|
from restoran_max_bot.iiko_api import customer_info, customer_create, customer_wallet
|
|
|
|
|
from restoran_max_bot.rkiper_api import rkiper_customer_info, rkiper_customer_create
|
|
|
|
|
from restoran_max_bot.common import common_get_data, common_set_contact, common_check_registration
|
|
|
|
|
from restoran_max_bot.message_sender import send_text, send_image, send_menu, send_feedback_buttons, send_booking_people_buttons, send_link_button
|
|
|
|
|
from restoran_max_bot.command_handlers import handle_standard_command, handle_ai_response
|
|
|
|
|
from restoran_max_bot.ai_handler import process_with_ai
|
|
|
|
|
from restoran_max_bot.settings import STATICFILES_DIRS, BASE_URL
|
|
|
|
|
from restoran_max_bot.utils import has_key, is_json
|
|
|
|
|
from restoran_max_bot.utils import is_json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- вспомогательные функции ----------
|
|
|
|
|
def send_booking_to_crm(client: Client, date, time, people, phone, name):
|
|
|
|
|
# реализация бронирования столика
|
|
|
|
|
msg = f'Бронирование столика:\nНа дату: {date}-{time} \nКоличество: {people}\nКонтакт: {phone}\nИмя: {name}'
|
|
|
|
|
send_message_all_manager(client, msg)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def send_contact_to_admin(client: Client, phone, contact_method, question, preferred_time, name):
|
|
|
|
|
# реализовать отправку администратору
|
|
|
|
|
msg = (f'Гость попросил связаться:\n {contact_method}\nВопрос: {question}\n'
|
|
|
|
|
f'Удобное время: {preferred_time}\nКонтакт: {phone}\nИмя: {name}')
|
|
|
|
|
send_message_all_manager(client, msg)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def send_feedback_to_crm(client: Client, rating, feedback_text, name, phone):
|
|
|
|
|
# реализовать отправку отзыва в CRM
|
|
|
|
|
msg = f'Отзыв от {name} (тел. {phone}):\nОценка: {rating}/5\nТекст: {feedback_text}'
|
|
|
|
|
send_message_all_manager(client, msg)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- получение бонусов ----------
|
|
|
|
|
def get_bonus(client: Client, phone: str, default_bonus: float, contact: Contact):
|
|
|
|
|
integration = common_get_integration(client=client)
|
|
|
|
|
bonus = 0
|
|
|
|
|
date = contact.field1
|
|
|
|
|
if len(date) < 2:
|
|
|
|
|
date = '0' + date
|
|
|
|
|
month = contact.field2
|
|
|
|
|
if len(month) < 2:
|
|
|
|
|
month = '0' + month
|
|
|
|
|
|
|
|
|
|
if integration:
|
|
|
|
|
if integration.partner.slug == 'iiko':
|
|
|
|
|
config = json.loads(integration.setting)
|
|
|
|
|
customerinfo = customer_info(config['token'], phone, config['id_org'])
|
|
|
|
|
if not customerinfo:
|
|
|
|
|
birthday = f"1990-{month}-{date} 00:00:00.000"
|
|
|
|
|
dt = customer_create(api_key=config['token'], phone=phone, name=contact.name,
|
|
|
|
|
organization_id=config['id_org'], birthday=birthday)
|
|
|
|
|
dt = customer_info(config['token'], phone, config['id_org'])
|
|
|
|
|
customer_wallet(api_key=config['token'], iiko_wallet_id=dt['walletBalances'][0]['id'],
|
|
|
|
|
customer_id=dt['id'], organization_id=config['id_org'],
|
|
|
|
|
bonus=default_bonus)
|
|
|
|
|
bonus = default_bonus
|
|
|
|
|
else:
|
|
|
|
|
bonus = customerinfo['walletBalances'][0]['balance']
|
|
|
|
|
|
|
|
|
|
if integration.partner.slug == 'rkeeper':
|
|
|
|
|
config = json.loads(integration.setting)
|
|
|
|
|
rs = rkiper_customer_info(rkiper_server=config['url'], rkiper_token=config['token'], phone=phone)
|
|
|
|
|
if len(rs):
|
|
|
|
|
rs = rs[0]
|
|
|
|
|
if has_key(rs, 'card_use'):
|
|
|
|
|
bonus = int(rs['card_use']['sum1']) / 100
|
|
|
|
|
else:
|
|
|
|
|
birthday = f"1990-{month}-{date}"
|
|
|
|
|
rs = rkiper_customer_create(rkiper_server=config['url'], rkiper_token=config['token'], phone=phone,
|
|
|
|
|
name=contact.name, birthday=birthday, bonus=config['bonus'],
|
|
|
|
|
discount=config['discount'])
|
|
|
|
|
bonus = 0
|
|
|
|
|
return bonus
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- получение вложений ----------
|
|
|
|
|
def get_attachments(message: dict):
|
|
|
|
|
if 'attachments' in message['message']['body']:
|
|
|
|
|
if 'vcf_info' in message['message']['body']['attachments'][0]['payload']:
|
|
|
|
|
match = re.search(r'TEL;TYPE=cell:(\d+)',
|
|
|
|
|
message['message']['body']['attachments'][0]['payload']['vcf_info'])
|
|
|
|
|
if match:
|
|
|
|
|
phone_number = match.group(1)
|
|
|
|
|
return {'attachments_type': 'vcf_info', 'data': phone_number}
|
|
|
|
|
return {'attachments_type': False, 'data': ''}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- основной обработчик ----------
|
|
|
|
|
def bot_message(client: Client, message: dict, settings_max: dict, message_type):
|
|
|
|
|
def bot_message(client: Client, message: dict, settings_max: dict, message_type: str) -> bool:
|
|
|
|
|
"""
|
|
|
|
|
Основной обработчик входящих сообщений от Max бота.
|
|
|
|
|
"""
|
|
|
|
|
chat_id = message['message']['recipient']['chat_id']
|
|
|
|
|
attachments = get_attachments(message=message)
|
|
|
|
|
|
|
|
|
|
# регистрация по vcf
|
|
|
|
|
if attachments['attachments_type'] == 'vcf_info':
|
|
|
|
|
common_set_contact(client=client, uid_client=chat_id, name=message['message']['sender']['name'],
|
|
|
|
|
phone=attachments['data'])
|
|
|
|
|
token = settings_max['token']
|
|
|
|
|
|
|
|
|
|
# 1. Обработка вложений (контакт из vcf)
|
|
|
|
|
attachments = _get_attachments(message)
|
|
|
|
|
if attachments['type'] == 'vcf_info':
|
|
|
|
|
common_set_contact(
|
|
|
|
|
client=client,
|
|
|
|
|
uid_client=chat_id,
|
|
|
|
|
name=message['message']['sender']['name'],
|
|
|
|
|
phone=attachments['data']
|
|
|
|
|
)
|
|
|
|
|
# Подменяем текст на системную команду регистрации
|
|
|
|
|
message['message']['body']['text'] = 'system_registration'
|
|
|
|
|
|
|
|
|
|
# 2. Проверка регистрации
|
|
|
|
|
contact = check_registration(client=client, chat_id=chat_id, message=message, settings=settings_max)
|
|
|
|
|
if not contact:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
# ---------- проверка и запрос имени ----------
|
|
|
|
|
meta = get_contact_meta(contact)
|
|
|
|
|
|
|
|
|
|
# ---------- обработка стандартных команд (меню, бонусы и т.п.) ----------
|
|
|
|
|
data = None
|
|
|
|
|
if message_type == 'message_created':
|
|
|
|
|
data = common_get_data(client=client, key=str(message['message']['body']['text']).lower())
|
|
|
|
|
elif message_type == 'message_callback':
|
|
|
|
|
data_payload = json.loads(message['callback']['payload'])
|
|
|
|
|
data = common_get_data(client=client, key=str(data_payload['data']).lower())
|
|
|
|
|
|
|
|
|
|
if data:
|
|
|
|
|
for dt in data:
|
|
|
|
|
if dt.title == '##bonus##':
|
|
|
|
|
img = qrcode.make(contact.phone)
|
|
|
|
|
img.save(f"{STATICFILES_DIRS[0]}/client_qr/{contact.phone}.png")
|
|
|
|
|
url = f"https://maxbot.telefon-ip.ru/static/client_qr/{contact.phone}.png"
|
|
|
|
|
maxbot_send_img_message(chat_id=chat_id, max_token=settings_max['token'], img=url,
|
|
|
|
|
message='QR-код для начисления, списания бонусов.')
|
|
|
|
|
bonus = get_bonus(client=client, phone=contact.phone, default_bonus=float(dt.price), contact=contact)
|
|
|
|
|
maxbot_send_text_message(chat_id=chat_id, max_token=settings_max['token'],
|
|
|
|
|
message=f"💰 Ваш бонусный баланс: {bonus} руб")
|
|
|
|
|
|
|
|
|
|
elif dt.title == '##feedback##':
|
|
|
|
|
maxbot_send_feedback_button(client=client, message='👇', chat_id=chat_id,
|
|
|
|
|
max_token=settings_max['token'])
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
elif dt.title == '##booking##':
|
|
|
|
|
maxbot_send_booking_count_people_button(client=client, message='👇',
|
|
|
|
|
chat_id=chat_id, max_token=settings_max['token'])
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
# сложные кнопки
|
|
|
|
|
if is_json(dt.title):
|
|
|
|
|
data_json = json.loads(dt.title)
|
|
|
|
|
if 'type' in dt.title and data_json.get('type') == 'linkbutton':
|
|
|
|
|
maxbot_send_link_button(text=dt.descr, title_button=data_json['button'], link=dt.url,
|
|
|
|
|
chat_id=chat_id, max_token=settings_max['token'])
|
|
|
|
|
|
|
|
|
|
if dt.img:
|
|
|
|
|
url = f"https://cdn.telefon-ip.ru/{dt.img}?thumb=600"
|
|
|
|
|
maxbot_send_img_message(chat_id=chat_id, max_token=settings_max['token'], img=url, message=dt.descr)
|
|
|
|
|
|
|
|
|
|
if '##' not in dt.title and not dt.img and not is_json(dt.title):
|
|
|
|
|
maxbot_send_text_message(chat_id=chat_id, max_token=settings_max['token'], message=dt.descr)
|
|
|
|
|
|
|
|
|
|
if dt.url and not is_json(dt.title):
|
|
|
|
|
maxbot_send_text_message(chat_id=chat_id, max_token=settings_max['token'], message=dt.url)
|
|
|
|
|
|
|
|
|
|
maxbot_send_menu_button(chat_id=chat_id, max_token=settings_max['token'], message='👇 Выберите раздел',
|
|
|
|
|
client=client)
|
|
|
|
|
# 3. Получение текста запроса
|
|
|
|
|
user_query = _extract_query(message, message_type)
|
|
|
|
|
if not user_query:
|
|
|
|
|
send_menu(chat_id, token, client)
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
# если при нажатии на кнопку небыл найден контент, тогда для AI передаем имя кнопки
|
|
|
|
|
if message_type == 'message_callback':
|
|
|
|
|
message['message']['body']['text'] = str(data_payload['data']).lower()
|
|
|
|
|
|
|
|
|
|
# ---------- обработка через AI ----------
|
|
|
|
|
# Проверяем, есть ли AI-агент у клиента
|
|
|
|
|
ai_agent = get_ai_agent(client)
|
|
|
|
|
if not ai_agent.get('ai_agent'):
|
|
|
|
|
maxbot_send_menu_button(chat_id=chat_id, max_token=settings_max['token'],
|
|
|
|
|
message='👇 Выберите раздел', client=client)
|
|
|
|
|
# 4. Обработка стандартных команд (меню, бонусы и т.п.)
|
|
|
|
|
data = _get_command_data(client, message, message_type)
|
|
|
|
|
if data:
|
|
|
|
|
handled = handle_standard_command(client, chat_id, token, data, contact)
|
|
|
|
|
if handled:
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
# 5. Если не стандартная команда — пробуем AI
|
|
|
|
|
response = process_with_ai(client, chat_id, user_query, contact)
|
|
|
|
|
if response:
|
|
|
|
|
handle_ai_response(client, chat_id, token, response, contact)
|
|
|
|
|
send_menu(chat_id, token, client)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
real_name = contact.name.strip()
|
|
|
|
|
# Вызываем AI-агента через универсальную функцию, передавая реальное имя
|
|
|
|
|
response = call_ai_agent(
|
|
|
|
|
client=client,
|
|
|
|
|
session_id=str(chat_id),
|
|
|
|
|
user_query=message['message']['body']['text'],
|
|
|
|
|
contact_name=real_name # передаём имя для персонализации
|
|
|
|
|
)
|
|
|
|
|
# 6. Если AI недоступен — просто меню
|
|
|
|
|
send_menu(chat_id, token, client)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
# ---------- обработка ответа AI ----------
|
|
|
|
|
intent = response.get('intent')
|
|
|
|
|
message_text = response.get('message', '')
|
|
|
|
|
entities = response.get('entities', {})
|
|
|
|
|
status = response.get('status', 'complete')
|
|
|
|
|
|
|
|
|
|
if intent == 'general':
|
|
|
|
|
maxbot_send_text_message(chat_id, settings_max['token'], message_text)
|
|
|
|
|
def _get_attachments(message: dict) -> dict:
|
|
|
|
|
"""Извлекает информацию о вложениях (например, vCard)."""
|
|
|
|
|
attachments = message.get('message', {}).get('body', {}).get('attachments', [])
|
|
|
|
|
for att in attachments:
|
|
|
|
|
payload = att.get('payload', {})
|
|
|
|
|
if 'vcf_info' in payload:
|
|
|
|
|
match = re.search(r'TEL;TYPE=cell:(\d+)', payload['vcf_info'])
|
|
|
|
|
if match:
|
|
|
|
|
return {'type': 'vcf_info', 'data': match.group(1)}
|
|
|
|
|
return {'type': None, 'data': ''}
|
|
|
|
|
|
|
|
|
|
elif intent == 'booking':
|
|
|
|
|
if status == 'need_more_info':
|
|
|
|
|
maxbot_send_text_message(chat_id, settings_max['token'], message_text)
|
|
|
|
|
elif status == 'complete':
|
|
|
|
|
date = entities.get('date')
|
|
|
|
|
time = entities.get('time')
|
|
|
|
|
people = entities.get('people')
|
|
|
|
|
phone = entities.get('phone')
|
|
|
|
|
if date and time and people:
|
|
|
|
|
success = send_booking_to_crm(client, date, time, people, phone, real_name)
|
|
|
|
|
if success:
|
|
|
|
|
confirm_msg = (f"✅ Бронирование на {date} в {time} на {people} чел. принято! "
|
|
|
|
|
f"Администратор свяжется с вами.")
|
|
|
|
|
else:
|
|
|
|
|
confirm_msg = "❌ Не удалось забронировать. Попробуйте позже."
|
|
|
|
|
maxbot_send_text_message(chat_id, settings_max['token'], confirm_msg)
|
|
|
|
|
else:
|
|
|
|
|
maxbot_send_text_message(chat_id, settings_max['token'], "⚠️ Не хватает данных для бронирования.")
|
|
|
|
|
else:
|
|
|
|
|
maxbot_send_text_message(chat_id, settings_max['token'], message_text)
|
|
|
|
|
|
|
|
|
|
elif intent == 'contact_admin':
|
|
|
|
|
if status == 'need_more_info':
|
|
|
|
|
maxbot_send_text_message(chat_id, settings_max['token'], message_text)
|
|
|
|
|
elif status == 'complete':
|
|
|
|
|
phone = entities.get('phone')
|
|
|
|
|
contact_method = entities.get('contact_method')
|
|
|
|
|
question = entities.get('question', '')
|
|
|
|
|
preferred_time = entities.get('preferred_time', '')
|
|
|
|
|
if phone and contact_method:
|
|
|
|
|
success = send_contact_to_admin(client, phone, contact_method, question, preferred_time, real_name)
|
|
|
|
|
if success:
|
|
|
|
|
confirm_msg = f"✅ Ваш запрос передан администратору. Способ связи: {contact_method}. Скоро с вами свяжутся."
|
|
|
|
|
else:
|
|
|
|
|
confirm_msg = "❌ Не удалось отправить запрос. Попробуйте позже."
|
|
|
|
|
maxbot_send_text_message(chat_id, settings_max['token'], confirm_msg)
|
|
|
|
|
else:
|
|
|
|
|
maxbot_send_text_message(chat_id, settings_max['token'],
|
|
|
|
|
"⚠️ Не хватает данных для связи с администратором.")
|
|
|
|
|
else:
|
|
|
|
|
maxbot_send_text_message(chat_id, settings_max['token'], message_text)
|
|
|
|
|
def _extract_query(message: dict, message_type: str) -> str:
|
|
|
|
|
"""Извлекает текст запроса из сообщения или callback'а."""
|
|
|
|
|
if message_type == 'message_created':
|
|
|
|
|
return message.get('message', {}).get('body', {}).get('text', '')
|
|
|
|
|
elif message_type == 'message_callback':
|
|
|
|
|
payload = message.get('callback', {}).get('payload', '{}')
|
|
|
|
|
try:
|
|
|
|
|
data = json.loads(payload)
|
|
|
|
|
return data.get('data', '')
|
|
|
|
|
except json.JSONDecodeError:
|
|
|
|
|
return ''
|
|
|
|
|
return ''
|
|
|
|
|
|
|
|
|
|
elif intent == 'feedback':
|
|
|
|
|
if status == 'need_more_info':
|
|
|
|
|
maxbot_send_text_message(chat_id, settings_max['token'], message_text)
|
|
|
|
|
elif status == 'complete':
|
|
|
|
|
rating = entities.get('rating')
|
|
|
|
|
feedback_text = entities.get('feedback_text', '')
|
|
|
|
|
if rating and feedback_text:
|
|
|
|
|
success = send_feedback_to_crm(client, rating, feedback_text, real_name, contact.phone)
|
|
|
|
|
if success:
|
|
|
|
|
confirm_msg = "✅ Спасибо за ваш отзыв! Мы учтём его."
|
|
|
|
|
else:
|
|
|
|
|
confirm_msg = "❌ Не удалось отправить отзыв. Попробуйте позже."
|
|
|
|
|
maxbot_send_text_message(chat_id, settings_max['token'], confirm_msg)
|
|
|
|
|
else:
|
|
|
|
|
maxbot_send_text_message(chat_id, settings_max['token'], "⚠️ Не хватает данных для отзыва.")
|
|
|
|
|
else:
|
|
|
|
|
maxbot_send_text_message(chat_id, settings_max['token'], message_text)
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
maxbot_send_text_message(chat_id, settings_max['token'], message_text)
|
|
|
|
|
def _get_command_data(client: Client, message: dict, message_type: str):
|
|
|
|
|
"""Получает данные команды (контент) по ключу."""
|
|
|
|
|
key = _extract_query(message, message_type)
|
|
|
|
|
if not key:
|
|
|
|
|
return None
|
|
|
|
|
return common_get_data(client=client, key=str(key).lower())
|
|
|
|
|
|
|
|
|
|
# всегда отправляем меню после ответа
|
|
|
|
|
maxbot_send_menu_button(chat_id=chat_id, max_token=settings_max['token'],
|
|
|
|
|
message='👇 Выберите раздел', client=client)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
# ==================== bot_promo ====================
|
|
|
|
|
|
|
|
|
|
def bot_promo(client: Client, message: dict, settings_max: dict):
|
|
|
|
|
def bot_promo(client: Client, message: dict, settings_max: dict) -> bool:
|
|
|
|
|
"""Обработчик промокодов (QR-коды)."""
|
|
|
|
|
chat_id = message['chat_id']
|
|
|
|
|
promo = message['payload'].lower()
|
|
|
|
|
messenger = 'max-bot'
|
|
|
|
|
client_id = client.id
|
|
|
|
|
|
|
|
|
|
# Проверяем, существует ли промокод в системе (через common_get_data)
|
|
|
|
|
data = common_get_data(client=client, key=promo)
|
|
|
|
|
if not data:
|
|
|
|
|
# Если промокод не заведён – ничего не отправляем (скрываем факт)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
# Пытаемся найти или создать запись в БД
|
|
|
|
|
promo_obj, created = PromoCode.objects.get_or_create(
|
|
|
|
|
promo=promo,
|
|
|
|
|
chat_id=chat_id,
|
|
|
|
|
client=client,
|
|
|
|
|
defaults={
|
|
|
|
|
'messenger': messenger,
|
|
|
|
|
'used': False,
|
|
|
|
|
}
|
|
|
|
|
defaults={'messenger': messenger, 'used': False}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Если запись уже существовала
|
|
|
|
|
if not created:
|
|
|
|
|
if promo_obj.used:
|
|
|
|
|
# Уже использован – уведомляем
|
|
|
|
|
maxbot_send_text_message(
|
|
|
|
|
chat_id=chat_id,
|
|
|
|
|
max_token=settings_max['token'],
|
|
|
|
|
message="⚠️ Этот промокод уже был использован."
|
|
|
|
|
)
|
|
|
|
|
send_text(chat_id, settings_max['token'], "⚠️ Этот промокод уже был использован.")
|
|
|
|
|
else:
|
|
|
|
|
# QR-код уже был отправлен ранее – напоминаем
|
|
|
|
|
maxbot_send_text_message(
|
|
|
|
|
chat_id=chat_id,
|
|
|
|
|
max_token=settings_max['token'],
|
|
|
|
|
message="ℹ️ QR-код уже был отправлен."
|
|
|
|
|
)
|
|
|
|
|
send_text(chat_id, settings_max['token'], "ℹ️ QR-код уже был отправлен.")
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
# Если запись создана впервые – генерируем QR-код
|
|
|
|
|
# Генерируем QR
|
|
|
|
|
base_url = f"{BASE_URL}/promo/status/"
|
|
|
|
|
url_promo = f"{base_url}{promo}/{chat_id}/{client_id}"
|
|
|
|
|
img = qrcode.make(url_promo)
|
|
|
|
|
@ -307,21 +130,16 @@ def bot_promo(client: Client, message: dict, settings_max: dict):
|
|
|
|
|
img.save(f"{STATICFILES_DIRS[0]}/client_qr/{file_name}")
|
|
|
|
|
qr_url = f"{BASE_URL}/static/client_qr/{file_name}"
|
|
|
|
|
|
|
|
|
|
maxbot_send_img_message(
|
|
|
|
|
chat_id=chat_id,
|
|
|
|
|
max_token=settings_max['token'],
|
|
|
|
|
img=qr_url,
|
|
|
|
|
message='Ваш QR-код.'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Отправляем дополнительный контент, если есть
|
|
|
|
|
for dt in data:
|
|
|
|
|
if dt.img:
|
|
|
|
|
img_url = f"https://cdn.telefon-ip.ru/{dt.img}?thumb=600"
|
|
|
|
|
maxbot_send_img_message(chat_id=chat_id, max_token=settings_max['token'], img=img_url, message=dt.descr)
|
|
|
|
|
if dt.title:
|
|
|
|
|
maxbot_send_text_message(chat_id=chat_id, max_token=settings_max['token'], message=dt.descr)
|
|
|
|
|
if dt.url:
|
|
|
|
|
maxbot_send_text_message(chat_id=chat_id, max_token=settings_max['token'], message=dt.url)
|
|
|
|
|
send_image(chat_id, settings_max['token'], qr_url, 'Ваш QR-код.')
|
|
|
|
|
|
|
|
|
|
# Отправляем дополнительный контент
|
|
|
|
|
for item in data:
|
|
|
|
|
if item.img:
|
|
|
|
|
img_url = f"https://cdn.telefon-ip.ru/{item.img}?thumb=600"
|
|
|
|
|
send_image(chat_id, settings_max['token'], img_url, item.descr)
|
|
|
|
|
if item.title and not item.img:
|
|
|
|
|
send_text(chat_id, settings_max['token'], item.descr)
|
|
|
|
|
if item.url:
|
|
|
|
|
send_text(chat_id, settings_max['token'], item.url)
|
|
|
|
|
|
|
|
|
|
return True
|