правки по коду

main
pilot 2 months ago
parent 1f3ed30471
commit 286b722c0f

@ -9,7 +9,7 @@ from max_bot.models import Partner, Integration, Client, BonusTransaction, App
from restoran_max_bot.bot_started import bot_started from restoran_max_bot.bot_started import bot_started
from restoran_max_bot.bot_stopped import bot_stopped from restoran_max_bot.bot_stopped import bot_stopped
from restoran_max_bot.bot_message import bot_message, bot_promo from restoran_max_bot.bot_message import bot_message, bot_promo
from restoran_max_bot.common import common_get_contact from restoran_max_bot.common import common_get_contact, common_check_registration
from restoran_max_bot.settings import DEBUG from restoran_max_bot.settings import DEBUG
from restoran_max_bot.utils import is_json, has_key from restoran_max_bot.utils import is_json, has_key
@ -72,13 +72,6 @@ def api_start_max_v1(request, token, **kwargs):
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)
# обработчик промо кодов с запросов
# https://dev.max.ru/docs/chatbots/bots-coding/prepare
# https://max.ru/id032606883607_2_bot?start=source_site
if data.get("payload", None):
print(data['payload'])
bot_promo(client=client, message=data, settings_max=settings_max)
# получение сообщения из бота # получение сообщения из бота
if data['update_type'] == 'message_created': if data['update_type'] == 'message_created':
bot_message(client=client, message=data, settings_max=settings_max, message_type='message_created') bot_message(client=client, message=data, settings_max=settings_max, message_type='message_created')
@ -88,6 +81,12 @@ def api_start_max_v1(request, token, **kwargs):
# start - запуск бота # start - запуск бота
if data['update_type'] == 'bot_started': if data['update_type'] == 'bot_started':
# https://dev.max.ru/docs/chatbots/bots-coding/prepare
# https://max.ru/id032606883607_2_bot?start=source_site
# роверка на промокод
if data.get("payload", None):
bot_promo(client=client, message=data, settings_max=settings_max)
if not common_check_registration(client=client, chat_id=data['chat_id']):
bot_started(client=client, message=data, settings=settings_max) bot_started(client=client, message=data, settings=settings_max)
# выход из бота # выход из бота

@ -282,7 +282,4 @@ def bot_promo(client: Client, message: dict, settings_max: dict):
if dt.url: if dt.url:
maxbot_send_text_message(chat_id=chat_id, max_token=settings_max['token'], message=dt.url) maxbot_send_text_message(chat_id=chat_id, max_token=settings_max['token'], message=dt.url)
# сохранение в meta информации о коде
# ПРОВЕРКА НА РЕГИСТРАЦИЮ ???
return True return True

@ -21,8 +21,7 @@ def bot_started(client: Client, message: dict, settings: dict):
text='Согласен на обработку персональных данных.') text='Согласен на обработку персональных данных.')
return True return True
# проверка есть ли регистрация клиента номер телефона, запись создается после отправки ноера телефона
# проверка есть ли регистрация клиента номер телефона
def get_registration_phone(client: Client, chat_id: str, settings: dict): def get_registration_phone(client: Client, chat_id: str, settings: dict):
contact = common_get_contact(client=client, uid_client=chat_id) contact = common_get_contact(client=client, uid_client=chat_id)
if not contact: if not contact:
@ -41,31 +40,6 @@ def get_registration_phone(client: Client, chat_id: str, settings: dict):
return False return False
return contact return contact
# проверка есть ли регистрация клиента день рождение
def get_registration_birthday(client: Client, chat_id: str, settings: dict):
contact = common_get_contact(client=client, uid_client=chat_id)
if not contact:
data = common_get_data(client=client, key='start'.lower())
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)
if dt.url:
maxbot_send_text_message(chat_id=chat_id, max_token=settings['token'], message=dt.url)
maxbot_get_phone(chat_id=chat_id, max_token=settings['token'], text='Подтвердите согласие')
return False
if not contact.field1:
return False
return contact
# проверка регистрации в боте (что все данные получены) # проверка регистрации в боте (что все данные получены)
def check_registration(client: Client, chat_id: str, message: dict, 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) contact = get_registration_phone(client=client, chat_id=chat_id, settings=settings)

@ -88,3 +88,15 @@ def send_message_all_manager(client: Client, message: str):
return response return response
def common_check_registration(client: Client, chat_id: str) -> None | bool | Contact:
# функция проверяет все ли данные заполнены клиентом
contact = common_get_contact(client=client, uid_client=chat_id)
if not contact:
return None
if contact.field1 is None or contact.field1 == '':
return None
if contact.field2 is None or contact.field2 == '':
return None
return contact
Loading…
Cancel
Save