parent
24dd7f0af4
commit
928ad79d9e
@ -0,0 +1,21 @@
|
||||
from max_bot.max_api import maxbot_send_text_message, maxbot_send_img_message, maxbot_send_menu_button
|
||||
from max_bot.models import Client
|
||||
from restoran_max_bot.common import common_get_data
|
||||
|
||||
|
||||
def bot_message(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()
|
||||
data = common_get_data(client=client, key=text)
|
||||
if data:
|
||||
for dt in data:
|
||||
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)
|
||||
else:
|
||||
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)
|
||||
return True
|
||||
@ -0,0 +1,10 @@
|
||||
from max_bot.max_api import maxbot_send_text_message
|
||||
from max_bot.models import Client
|
||||
|
||||
|
||||
def bot_started(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)
|
||||
return True
|
||||
@ -0,0 +1,10 @@
|
||||
from max_bot.max_api import maxbot_send_text_message
|
||||
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)
|
||||
return True
|
||||
@ -0,0 +1,11 @@
|
||||
# функция поиска контента по ключевому слову
|
||||
from max_bot.models import Client, ProductCategory, Product
|
||||
|
||||
|
||||
def common_get_data(client: Client, key: str) -> Product:
|
||||
product_category = ProductCategory.objects.filter(client=client, status=1, title=key, src=1).first()
|
||||
if product_category:
|
||||
data = Product.objects.filter(up=product_category.pk, status=1)
|
||||
else:
|
||||
data = None
|
||||
return data
|
||||
Loading…
Reference in new issue