Exemplo n.º 1
0
def request_registration_phone_number_handler(message: Message, **kwargs):
    chat_id = message.chat.id
    user_id = message.from_user.id
    name = kwargs.get('name')
    language = kwargs.get('language')

    def error():
        error_msg = strings.get_string('registration.request.phone_number',
                                       language)
        telegram_bot.send_message(chat_id, error_msg, parse_mode='HTML')
        telegram_bot.register_next_step_handler_by_chat_id(
            chat_id,
            request_registration_phone_number_handler,
            name=name,
            language=language)

    if message.contact is not None:
        phone_number = message.contact.phone_number
    else:
        if message.text is None:
            error()
            return
        else:
            match = re.match(r'\+*998\s*\d{2}\s*\d{3}\s*\d{2}\s*\d{2}',
                             message.text)
            if match is None:
                error()
                return
            phone_number = match.group()
    userservice.register_user(user_id, message.from_user.username, name,
                              phone_number, language)
    success_message = strings.get_string("welcome.registration_successfully",
                                         language)
    botutils.to_main_menu(chat_id, language, success_message)
Exemplo n.º 2
0
def process_phone_number(message: Message, **kwargs):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = kwargs.get('language', 'ru')

    def error():
        error_msg = strings.get_string('welcome.phone_number', language)
        telegram_bot.send_message(chat_id, error_msg, parse_mode='HTML')
        telegram_bot.register_next_step_handler_by_chat_id(
            chat_id, process_phone_number)

    if message.contact is not None:
        phone_number = message.contact.phone_number
    else:
        if message.text is None:
            error()
            return
        else:
            match = re.match(r'\+*998\s*\d{2}\s*\d{3}\s*\d{2}\s*\d{2}',
                             message.text)
            if match is None:
                error()
                return
            phone_number = match.group()
    full_user_name = message.from_user.first_name
    if message.from_user.last_name:
        full_user_name += " " + message.from_user.last_name
    userservice.register_user(user_id, message.from_user.username,
                              full_user_name, phone_number, language)
    success_message = strings.get_string('welcome.registration_successfully',
                                         language)
    botutils.to_main_menu(chat_id, language, success_message)