From 55b3513e37e9280cbb454370bb3d5ecbdba5b2e8 Mon Sep 17 00:00:00 2001 From: pilot <657434@03b.ru> Date: Thu, 14 May 2026 08:02:34 +0800 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BD=D0=B5=D0=B4=D1=80=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- restoran_max_bot/max_bot/max_api.py | 43 ++++++++++++++++++- restoran_max_bot/max_bot/urls.py | 2 +- restoran_max_bot/max_bot/views.py | 2 +- .../restoran_max_bot/bot_message.py | 15 +++++-- .../restoran_max_bot/bot_stopped.py | 6 +-- 5 files changed, 57 insertions(+), 11 deletions(-) diff --git a/restoran_max_bot/max_bot/max_api.py b/restoran_max_bot/max_bot/max_api.py index 63aa53f..9f6de42 100644 --- a/restoran_max_bot/max_bot/max_api.py +++ b/restoran_max_bot/max_bot/max_api.py @@ -264,7 +264,7 @@ def maxbot_send_feedback_button(client: Client, chat_id: str, max_token: str, me button = [] cnt = 0 for dt in range(1, 6): - payload_data = {"payload_type": "feedback", "data": f"feedback{dt}"} + payload_data = {"payload_type": "feedback", "data": f"feedback_{dt}"} button_data = {"type": "callback", "text": dt, "payload": json.dumps(payload_data)} button.append(button_data) cnt = cnt + 1 @@ -292,3 +292,44 @@ def maxbot_send_feedback_button(client: Client, chat_id: str, max_token: str, me rt = {'success': True, 'error': '', 'data': response} return rt + + +def maxbot_send_booking_count_people_button(client: Client, chat_id: str, max_token: str, message: str): + url = f"https://platform-api.max.ru/messages?chat_id={chat_id}" + buttons = [] + button = [] + for dt in range(1, 6): + payload_data = {"payload_type": "booking_count_people", "data": f"booking_count_people_{dt}"} + button_data = {"type": "callback", "text": dt, "payload": json.dumps(payload_data)} + button.append(button_data) + + buttons.append(button) + + button = [] + payload_data = {"payload_type": "booking_count_people", "data": f"booking_count_people_many"} + button_data = {"type": "callback", "text": 'Больше 5', "payload": json.dumps(payload_data)} + button.append(button_data) + + buttons.append(button) + + payload = json.dumps({ + "text": message, + "attachments": [ + {"type": "inline_keyboard", + "payload": { + "buttons": buttons + } + } + ] + + }) + + headers = { + 'Authorization': f'{max_token}', + 'Content-Type': 'application/json' + } + + response = requests.request("POST", url, headers=headers, data=payload) + rt = {'success': True, 'error': '', 'data': response} + + return rt diff --git a/restoran_max_bot/max_bot/urls.py b/restoran_max_bot/max_bot/urls.py index e36fd48..43cc97e 100644 --- a/restoran_max_bot/max_bot/urls.py +++ b/restoran_max_bot/max_bot/urls.py @@ -2,7 +2,7 @@ from django.urls import path from max_bot.views import api_start_max_v1, iiko_webhook, iiko_send_message urlpatterns = [ - path('api/v1', api_start_max_v1), + path('api/v1/', api_start_max_v1), path('iiko/webhook/', iiko_webhook), path('iiko/send-message/', iiko_send_message), ] diff --git a/restoran_max_bot/max_bot/views.py b/restoran_max_bot/max_bot/views.py index 59776c3..ab5e352 100644 --- a/restoran_max_bot/max_bot/views.py +++ b/restoran_max_bot/max_bot/views.py @@ -61,7 +61,7 @@ def api_decorator(func): @csrf_exempt @api_decorator -def api_start_max_v1(request, **kwargs): +def api_start_max_v1(request, token, **kwargs): data = json.loads(request.body.decode('utf-8')) client = kwargs['client'] settings_max = kwargs['settings_max'] diff --git a/restoran_max_bot/restoran_max_bot/bot_message.py b/restoran_max_bot/restoran_max_bot/bot_message.py index 48ff79f..7128009 100644 --- a/restoran_max_bot/restoran_max_bot/bot_message.py +++ b/restoran_max_bot/restoran_max_bot/bot_message.py @@ -75,7 +75,6 @@ def get_attachments(message: dict): def bot_message(client: Client, message: dict, settings: dict, message_type): - chat_id = message['message']['recipient']['chat_id'] attachments = get_attachments(message=message) @@ -94,8 +93,8 @@ def bot_message(client: Client, message: dict, settings: dict, message_type): data = common_get_data(client=client, key=str(message['message']['body']['text']).lower()) if message_type == 'message_callback': - key = json.loads(message['callback']['payload']) - data = common_get_data(client=client, key=str(key['data']).lower()) + payload = json.loads(message['callback']['payload']) + data = common_get_data(client=client, key=str(payload['data']).lower()) if data: for dt in data: if dt.title == '##bonus##': @@ -107,12 +106,17 @@ def bot_message(client: Client, message: dict, settings: dict, message_type): 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'], - message=f"Ваши бонусы: {bonus} руб") + message=f"💰 Ваш бонусный баланс: {bonus} руб") if dt.title == '##feedback##': maxbot_send_feedback_button(client=client, message='👇', chat_id=chat_id, max_token=settings['token']) return True + if dt.title == '##booking##': + maxbot_send_booking_count_people_button(client=client, message='👇', + chat_id=chat_id, max_token=settings['token']) + return True + 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['token'], img=url, message=dt.descr) @@ -126,6 +130,9 @@ def bot_message(client: Client, message: dict, settings: dict, message_type): # отправка меню maxbot_send_menu_button(chat_id=chat_id, max_token=settings['token'], message='👇 Выбери раздел', client=client) else: + if payload['payload_type'] == 'booking_count_people': + print('запрос даты') + # отправка меню maxbot_send_menu_button(chat_id=chat_id, max_token=settings['token'], message='👇 Выбери раздел', client=client) diff --git a/restoran_max_bot/restoran_max_bot/bot_stopped.py b/restoran_max_bot/restoran_max_bot/bot_stopped.py index 2d1b940..82520d8 100644 --- a/restoran_max_bot/restoran_max_bot/bot_stopped.py +++ b/restoran_max_bot/restoran_max_bot/bot_stopped.py @@ -3,8 +3,6 @@ from max_bot.models import Client def bot_stopped(client: Client, message: dict, settings: dict): - chat_id = message['message']['recipient']['chat_id'] - chat_type = message['message']['recipient']['chat_type'] - text = str(message['message']['body']['text']).lower() - maxbot_send_text_message(chat_id=chat_id, max_token=settings['token'], message=text) + chat_id = message['chat_id'] + # maxbot_send_text_message(chat_id=chat_id, max_token=settings['token'], message=text) return True