From 84be006940774bc9e3263a44473cbbe26cc2798b Mon Sep 17 00:00:00 2001 From: pilot <657434@03b.ru> Date: Sun, 31 May 2026 23:35:15 +0800 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=BE=D0=B3=D0=BE=20=D0=BF=D1=83=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- restoran_max_bot/max_bot/max_api.py | 31 +++++++++++++++++++ .../restoran_max_bot/bot_message.py | 20 +++++++++--- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/restoran_max_bot/max_bot/max_api.py b/restoran_max_bot/max_bot/max_api.py index ad2adbf..5f4090b 100644 --- a/restoran_max_bot/max_bot/max_api.py +++ b/restoran_max_bot/max_bot/max_api.py @@ -335,3 +335,34 @@ def maxbot_send_booking_count_people_button(client: Client, chat_id: str, max_to rt = {'success': True, 'error': '', 'data': response} return rt + + +def maxbot_send_link_button(text, title_button, link, chat_id, max_token): + url = f"https://platform-api.max.ru/messages?chat_id={chat_id}" + payload = json.dumps({ + "text": text, + "attachments": [ + {"type": "inline_keyboard", + "payload": { + "buttons": [ + [ + { + "type": "link", + "text": title_button, + "url": link + } + ] + ] + } + } + ] + + }) + + headers = { + 'Authorization': f'{max_token}', + 'Content-Type': 'application/json' + } + + response = requests.request("POST", url, headers=headers, data=payload) + rt = {'success': True, 'error': '', 'data': response} diff --git a/restoran_max_bot/restoran_max_bot/bot_message.py b/restoran_max_bot/restoran_max_bot/bot_message.py index aca0562..2913b70 100644 --- a/restoran_max_bot/restoran_max_bot/bot_message.py +++ b/restoran_max_bot/restoran_max_bot/bot_message.py @@ -6,7 +6,7 @@ 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.settings import STATICFILES_DIRS -from restoran_max_bot.utils import has_key +from restoran_max_bot.utils import has_key, is_json # получение информации по интеграции с терминалом ikko, rkeeper @@ -119,23 +119,33 @@ def bot_message(client: Client, message: dict, settings: dict, message_type): chat_id=chat_id, max_token=settings['token']) return True + # для более сложных функций + if is_json(dt.title): + data = json.loads(dt.title) + if 'type' in dt.title: + if data['type'] == 'linkbutton': + maxbot_send_link_button(text=dt.descr, title_button=data['button'], link=dt.url, chat_id=chat_id, + max_token=settings['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['token'], img=url, message=dt.descr) - if '##' not in dt.title and not dt.img: + 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) - if dt.url: + 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_menu_button(chat_id=chat_id, max_token=settings['token'], message='👇 Выберите раздел', client=client) + 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) + maxbot_send_menu_button(chat_id=chat_id, max_token=settings['token'], message='👇 Выберите раздел', + client=client) return True