From b8f5d30f4bf2d7cfe3687a981ccef49b6b40a6ff Mon Sep 17 00:00:00 2001 From: pilot <657434@03b.ru> Date: Wed, 13 May 2026 08:10:40 +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 | 48 ++++++++++++++++--- .../restoran_max_bot/bot_message.py | 4 ++ .../restoran_max_bot/bot_started.py | 2 +- restoran_max_bot/restoran_max_bot/common.py | 3 +- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/restoran_max_bot/max_bot/max_api.py b/restoran_max_bot/max_bot/max_api.py index 635ca61..63aa53f 100644 --- a/restoran_max_bot/max_bot/max_api.py +++ b/restoran_max_bot/max_bot/max_api.py @@ -52,10 +52,6 @@ def maxbot_send_menu_button(client: Client, chat_id: str, max_token: str, messag button = [] cnt = 0 for mn in menu: - if cnt == 2: - cnt = 0 - buttons.append(button) - button = [] if mn.emojii: emojii = str(mn.emojii) else: @@ -64,10 +60,14 @@ def maxbot_send_menu_button(client: Client, chat_id: str, max_token: str, messag button_data = {"type": "callback", "text": " ".join([emojii, str(mn.title)]), "payload": json.dumps(payload_data)} button.append(button_data) + if cnt == 2 or str(mn.slug) == 'menu_1': + cnt = 0 + buttons.append(button) + button = [] cnt = cnt + 1 buttons.append(button) - + print(buttons) payload = json.dumps({ "text": message, "attachments": [ @@ -212,7 +212,7 @@ def maxbot_send_month_button(client: Client, chat_id: str, max_token: str, messa buttons.append(button) button = [] payload_data = {"payload_type": "month_birthday", "data": dt} - button_data = {"type": "callback", "text": months[dt-1], "payload": json.dumps(payload_data)} + button_data = {"type": "callback", "text": months[dt - 1], "payload": json.dumps(payload_data)} button.append(button_data) cnt = cnt + 1 @@ -256,3 +256,39 @@ def maxbot_send_content(client: Client, chat_id: str, max_token: str, message: s return True return False + + +def maxbot_send_feedback_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 = [] + cnt = 0 + for dt in range(1, 6): + 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 + + 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/restoran_max_bot/bot_message.py b/restoran_max_bot/restoran_max_bot/bot_message.py index e25a320..48ff79f 100644 --- a/restoran_max_bot/restoran_max_bot/bot_message.py +++ b/restoran_max_bot/restoran_max_bot/bot_message.py @@ -109,6 +109,10 @@ def bot_message(client: Client, message: dict, settings: dict, message_type): maxbot_send_text_message(chat_id=chat_id, max_token=settings['token'], 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.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) diff --git a/restoran_max_bot/restoran_max_bot/bot_started.py b/restoran_max_bot/restoran_max_bot/bot_started.py index f1d5976..3cdfaf0 100644 --- a/restoran_max_bot/restoran_max_bot/bot_started.py +++ b/restoran_max_bot/restoran_max_bot/bot_started.py @@ -68,7 +68,7 @@ def get_registration_birthday(client: Client, chat_id: str, settings: dict): def check_registration(client: Client, chat_id: str, message: dict, settings: dict): contact = get_registration_phone(client=client, chat_id=chat_id, settings=settings) if not contact: - maxbot_send_content(client=client, chat_id=chat_id, max_token=settings['token'], message='start') + # maxbot_send_content(client=client, chat_id=chat_id, max_token=settings['token'], message='start') return False if contact.field1 is None or contact.field1 == '': diff --git a/restoran_max_bot/restoran_max_bot/common.py b/restoran_max_bot/restoran_max_bot/common.py index bad48fa..d2271f1 100644 --- a/restoran_max_bot/restoran_max_bot/common.py +++ b/restoran_max_bot/restoran_max_bot/common.py @@ -14,7 +14,8 @@ def common_get_data(client: Client, key: str) -> Product: def common_get_menu(client: Client) -> ProductCategory: - menu = ProductCategory.objects.filter(client=client, status=1, src=1, slug='menu').order_by('ord') + menu = ProductCategory.objects.filter(client=client, status=1, src=1, + slug__in=['menu', 'menu_1', 'menu_2']).order_by('ord') return menu