diff --git a/restoran_max_bot/max_bot/max_api.py b/restoran_max_bot/max_bot/max_api.py index b8b4be7..5f22c4e 100644 --- a/restoran_max_bot/max_bot/max_api.py +++ b/restoran_max_bot/max_bot/max_api.py @@ -59,21 +59,21 @@ def maxbot_send_menu_button(chat_id: str, max_token: str, message: str, buton: l "url": "https://example.com" }, { - "type": "link", - "text": "Закройте сайт", + "type": "message", + "text": "type message", "url": "https://example.com" } ], [ { - "type": "link", - "text": "Откройте сайт", - "url": "https://example.com" + "type": "clipboard", + "text": "type clipboard", + "payload": "test" }, { - "type": "link", - "text": " 🍺 Закройте сайт", - "url": "https://example.com" + "type": "callback", + "text": " 🍺 callback", + "payload": "TEEEETE payload" } ] ] @@ -90,3 +90,41 @@ def maxbot_send_menu_button(chat_id: str, max_token: str, message: str, buton: l rt = {'success': True, 'error': '', 'data': response} return rt + + +def maxbot_get_all_messages(chat_id: str, max_token: str): + url = f"https://platform-api.max.ru/messages?chat_id={chat_id}" + + payload = {} + headers = { + 'Authorization': f'{max_token}', + 'Content-Type': 'application/json' + } + response = requests.request("GET", url, headers=headers, data=payload) + rt = {'success': True, 'error': '', 'data': response.json()} + + return rt + + +def maxbot_del_messages(max_token: str, message_id: str): + url = f"https://platform-api.max.ru/messages?message_id={message_id}" + + payload = {} + headers = { + 'Authorization': f'{max_token}', + 'Content-Type': 'application/json' + } + response = requests.request("DELETE", url, headers=headers, data=payload) + rt = {'success': True, 'error': '', 'data': response.json()} + + return rt + + +def maxbot_delete_all_messages(chat_id: str, max_token: str): + rt = maxbot_get_all_messages(chat_id=chat_id, max_token=max_token) + data = rt['data'] + for dt in data['messages']: + if dt['sender']['is_bot']: + maxbot_del_messages(max_token=max_token, message_id=dt['body']['mid']) + + return True diff --git a/restoran_max_bot/max_bot/views.py b/restoran_max_bot/max_bot/views.py index 3fd5c75..74169dd 100644 --- a/restoran_max_bot/max_bot/views.py +++ b/restoran_max_bot/max_bot/views.py @@ -62,6 +62,8 @@ def api_start_max_v1(request, **kwargs): client = kwargs['client'] settings_max = kwargs['settings_max'] + print(data) + if not has_key(data, 'update_type'): rt = {'success': False, 'error': 'data update_type not found', 'data': ''} return JsonResponse(rt, status=200) @@ -70,6 +72,9 @@ def api_start_max_v1(request, **kwargs): if data['update_type'] == 'message_created': bot_message(client=client, message=data, settings=settings_max) + if data['update_type'] == 'message_callback': + bot_message(client=client, message=data, settings=settings_max) + # start - запуск бота if data['update_type'] == 'bot_started': bot_started(client=client, message=data, settings=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 2ad1d2c..0a98cc1 100644 --- a/restoran_max_bot/restoran_max_bot/bot_message.py +++ b/restoran_max_bot/restoran_max_bot/bot_message.py @@ -1,4 +1,5 @@ -from max_bot.max_api import maxbot_send_text_message, maxbot_send_img_message, maxbot_send_menu_button +from max_bot.max_api import maxbot_send_text_message, maxbot_send_img_message, maxbot_send_menu_button, \ + maxbot_delete_all_messages from max_bot.models import Client from restoran_max_bot.common import common_get_data @@ -17,5 +18,5 @@ def bot_message(client: Client, message: dict, settings: dict): maxbot_send_text_message(chat_id=chat_id, max_token=settings['token'], message=dt.descr) # отправка меню rs = maxbot_send_menu_button(chat_id=chat_id, max_token=settings['token'], message='test', buton=[]) - print(rs['data'].text) + # print(rs['data'].text) return True