pilot 3 months ago
parent 928ad79d9e
commit a3018a60ac

@ -59,21 +59,21 @@ def maxbot_send_menu_button(chat_id: str, max_token: str, message: str, buton: l
"url": "https://example.com" "url": "https://example.com"
}, },
{ {
"type": "link", "type": "message",
"text": "Закройте сайт", "text": "type message",
"url": "https://example.com" "url": "https://example.com"
} }
], ],
[ [
{ {
"type": "link", "type": "clipboard",
"text": "Откройте сайт", "text": "type clipboard",
"url": "https://example.com" "payload": "test"
}, },
{ {
"type": "link", "type": "callback",
"text": " 🍺 Закройте сайт", "text": " 🍺 callback",
"url": "https://example.com" "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} rt = {'success': True, 'error': '', 'data': response}
return rt 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

@ -62,6 +62,8 @@ def api_start_max_v1(request, **kwargs):
client = kwargs['client'] client = kwargs['client']
settings_max = kwargs['settings_max'] settings_max = kwargs['settings_max']
print(data)
if not has_key(data, 'update_type'): if not has_key(data, 'update_type'):
rt = {'success': False, 'error': 'data update_type not found', 'data': ''} rt = {'success': False, 'error': 'data update_type not found', 'data': ''}
return JsonResponse(rt, status=200) return JsonResponse(rt, status=200)
@ -70,6 +72,9 @@ def api_start_max_v1(request, **kwargs):
if data['update_type'] == 'message_created': if data['update_type'] == 'message_created':
bot_message(client=client, message=data, settings=settings_max) 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 - запуск бота # start - запуск бота
if data['update_type'] == 'bot_started': if data['update_type'] == 'bot_started':
bot_started(client=client, message=data, settings=settings_max) bot_started(client=client, message=data, settings=settings_max)

@ -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 max_bot.models import Client
from restoran_max_bot.common import common_get_data 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) 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=[]) 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 return True

Loading…
Cancel
Save