@ -1,4 +1,5 @@
import re
import re
from deepseek_bot . api_deepseek import *
from max_bot . max_api import *
from max_bot . max_api import *
import qrcode
import qrcode
from restoran_max_bot . bot_started import check_registration
from restoran_max_bot . bot_started import check_registration
@ -9,6 +10,15 @@ from restoran_max_bot.settings import STATICFILES_DIRS
from restoran_max_bot . utils import has_key , is_json
from restoran_max_bot . utils import has_key , is_json
# отправка сообщения в группу администраторв по бронированию
def send_booking_to_crm ( chat_id , date , time , people , contact ) :
return True
def send_contact_to_admin ( chat_id , phone , contact_method , question , preferred_time , contact ) :
return True
# получение информации по интеграции с терминалом ikko, rkeeper
# получение информации по интеграции с терминалом ikko, rkeeper
def get_bonus ( client : Client , phone : str , default_bonus : float , contact : Contact ) :
def get_bonus ( client : Client , phone : str , default_bonus : float , contact : Contact ) :
integration = common_get_integration ( client = client )
integration = common_get_integration ( client = client )
@ -76,7 +86,7 @@ def get_attachments(message: dict):
return { ' attachments_type ' : False , ' data ' : ' ' }
return { ' attachments_type ' : False , ' data ' : ' ' }
def bot_message ( client : Client , message : dict , settings : dict , message_type ) :
def bot_message ( client : Client , message : dict , settings _max: dict , settings_deepseek : dict , message_type ) :
chat_id = message [ ' message ' ] [ ' recipient ' ] [ ' chat_id ' ]
chat_id = message [ ' message ' ] [ ' recipient ' ] [ ' chat_id ' ]
attachments = get_attachments ( message = message )
attachments = get_attachments ( message = message )
@ -86,7 +96,7 @@ def bot_message(client: Client, message: dict, settings: dict, message_type):
phone = attachments [ ' data ' ] )
phone = attachments [ ' data ' ] )
message [ ' message ' ] [ ' body ' ] [ ' text ' ] = ' system_registration '
message [ ' message ' ] [ ' body ' ] [ ' text ' ] = ' system_registration '
contact = check_registration ( client = client , chat_id = chat_id , message = message , settings = settings )
contact = check_registration ( client = client , chat_id = chat_id , message = message , settings = settings _max )
if not contact :
if not contact :
return False
return False
@ -103,20 +113,20 @@ def bot_message(client: Client, message: dict, settings: dict, message_type):
img = qrcode . make ( contact . phone )
img = qrcode . make ( contact . phone )
img . save ( f " { STATICFILES_DIRS [ 0 ] } /client_qr/ { contact . phone } .png " )
img . save ( f " { STATICFILES_DIRS [ 0 ] } /client_qr/ { contact . phone } .png " )
url = f " https://maxbot.telefon-ip.ru/static/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 [ ' token ' ] , img = url ,
maxbot_send_img_message ( chat_id = chat_id , max_token = settings _max [ ' token ' ] , img = url ,
message = ' QR-код для начисления, списания бонусов. ' )
message = ' QR-код для начисления, списания бонусов. ' )
bonus = get_bonus ( client = client , phone = contact . phone , default_bonus = float ( dt . price ) , contact = contact )
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 [ ' token ' ] ,
maxbot_send_text_message ( chat_id = chat_id , max_token = settings _max [ ' token ' ] ,
message = f " 💰 Ваш бонусный баланс: { bonus } р у б " )
message = f " 💰 Ваш бонусный баланс: { bonus } р у б " )
if dt . title == ' ##feedback## ' :
if dt . title == ' ##feedback## ' :
maxbot_send_feedback_button ( client = client , message = ' 👇 ' , chat_id = chat_id , max_token = settings [ ' token ' ] )
maxbot_send_feedback_button ( client = client , message = ' 👇 ' , chat_id = chat_id , max_token = settings _max [ ' token ' ] )
return True
return True
if dt . title == ' ##booking## ' :
if dt . title == ' ##booking## ' :
maxbot_send_booking_count_people_button ( client = client , message = ' 👇 ' ,
maxbot_send_booking_count_people_button ( client = client , message = ' 👇 ' ,
chat_id = chat_id , max_token = settings [ ' token ' ] )
chat_id = chat_id , max_token = settings _max [ ' token ' ] )
return True
return True
# для более сложных функций
# для более сложных функций
@ -124,28 +134,97 @@ def bot_message(client: Client, message: dict, settings: dict, message_type):
data = json . loads ( dt . title )
data = json . loads ( dt . title )
if ' type ' in dt . title :
if ' type ' in dt . title :
if data [ ' type ' ] == ' linkbutton ' :
if data [ ' type ' ] == ' linkbutton ' :
maxbot_send_link_button ( text = dt . descr , title_button = data [ ' button ' ] , link = dt . url , chat_id = chat_id ,
maxbot_send_link_button ( text = dt . descr , title_button = data [ ' button ' ] , link = dt . url ,
max_token = settings [ ' token ' ] )
chat_id = chat_id ,
max_token = settings_max [ ' token ' ] )
if dt . img :
if dt . img :
url = f " https://cdn.telefon-ip.ru/ { dt . img } ?thumb=600 "
url = f " https://cdn.telefon-ip.ru/ { dt . img } ?thumb=600 "
maxbot_send_img_message ( chat_id = chat_id , max_token = settings [ ' token ' ] , img = url , message = dt . descr )
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 ) :
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 [ ' token ' ] , message = dt . descr )
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 ) :
if dt . url and not is_json ( dt . title ) :
maxbot_send_text_message ( chat_id = chat_id , max_token = settings [ ' token ' ] , message = dt . url )
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 [ ' token ' ] , message = ' 👇 Выберите раздел ' ,
maxbot_send_menu_button ( chat_id = chat_id , max_token = settings _max [ ' token ' ] , message = ' 👇 Выберите раздел ' ,
client = client )
client = client )
else :
else :
if payload [ ' payload_type ' ] == ' booking_count_people ' :
# обработка сообщения через ИИ ===========================
print ( ' запрос даты ' )
if settings_deepseek . get ( ' token ' , False ) :
text = message [ ' message ' ] [ ' body ' ] [ ' text ' ]
# Получаем системный промт из настроек
system_prompt = settings_deepseek . get ( ' deepseek_system_prompt ' , get_system_prompt ( client ) )
# Отправляем запрос в DeepSeek
response = deepseek_chat_structured (
session_id = str ( chat_id ) ,
api_token = settings_deepseek . get ( ' token ' ) ,
system_prompt = system_prompt ,
user_query = text
)
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 )
elif intent == ' booking ' :
if status == ' need_more_info ' :
# Отправляем уточняющий вопрос
maxbot_send_text_message ( chat_id , settings_max [ ' token ' ] , message_text )
elif status == ' complete ' :
# В с е данные собраны — передаём в CRM
date = entities . get ( ' date ' )
time = entities . get ( ' time ' )
people = entities . get ( ' people ' )
phone = entities . get ( ' phone ' )
if date and time and people :
# Вызываем функцию для отправки в CRM
success = send_booking_to_crm ( chat_id , date , time , people , phone )
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 ( chat_id , phone , contact_method , question , preferred_time , contact )
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 )
else :
maxbot_send_text_message ( chat_id , settings_max [ ' token ' ] , message_text )
# отправка меню
# После ответа отправляем меню (если нужно)
maxbot_send_menu_button ( chat_id = chat_id , max_token = settings [ ' token ' ] , message = ' 👇 Выберите раздел ' ,
maxbot_send_menu_button ( chat_id = chat_id , max_token = settings _max [ ' token ' ] ,
client = client )
message= ' 👇 Выберите раздел ' , client= client )
return True
return True