Ejemplo n.º 1
0
def main_menu(message):
    chat_id = message.chat.id

    if message.text == 'Отмена':
        message_to_send = 'Тогда в другой раз😊'
    else:
        message_to_send = message.text
    bot.send_message(chat_id=chat_id, text=message_to_send, reply_markup=keyboards.get_main_menu_keyboard())
Ejemplo n.º 2
0
def phone_number_processing(message):
    chat_id = message.chat.id
    user = models.TelegramUser.objects.get_or_create(chat_id=chat_id)[0]

    if message.text == 'Отмена':
        message_to_send = 'Тогда в другой раз😊'
        bot.send_message(chat_id=chat_id, text=message_to_send, reply_markup=keyboards.get_main_menu_keyboard())
    else:
        phone_number = message.text
        if is_valid_phone_number(phone_number):
            core.RequestManager.create_request(phone_number=phone_number, question=user.last_question)
            user.phone_number = phone_number
            user.save()
            message_to_send = 'Заявка принята! Мы Вам перезвоним😊'
            bot.send_message(chat_id=chat_id, text=message_to_send, reply_markup=keyboards.get_main_menu_keyboard())
        else:
            message_to_send = 'Вы ввели некорректный номер телефона, попробуйте еще раз'
            msg = bot.send_message(chat_id=chat_id, text=message_to_send, reply_markup=keyboards.get_cancel_keyboard())
            bot.register_next_step_handler(msg, phone_number_processing)
Ejemplo n.º 3
0
def start_message(message):
    chat_id = message.chat.id
    user = models.TelegramUser.objects.get_or_create(chat_id=chat_id)[0]
    if message.from_user.first_name:
        user.name = message.from_user.first_name
    if message.from_user.username:
        user.username = message.from_user.username
    user.save()
    message_to_send = bot.get_start_message()
    bot.send_message(chat_id=chat_id, text=message_to_send, reply_markup=keyboards.get_main_menu_keyboard())
Ejemplo n.º 4
0
def main_menu(message):
    chat_id = message.chat.id
    user = core.User(chat_id)
    if not user.object:
        msg = bot.send_authorization_message(chat_id)
        bot.register_next_step_handler(msg, authorization)
        return

    bot.send_message(chat_id=chat_id, text='Основное меню',
                     reply_markup=keyboards.get_main_menu_keyboard(), parse_mode='html')
Ejemplo n.º 5
0
def authorization(message):
    chat_id = message.chat.id
    token = message.text
    username = message.from_user.username
    user = core.User(chat_id)
    if user.authorization(token=token, username=username):
        bot.send_message(chat_id=chat_id, text=bot.get_instruction(), reply_markup=keyboards.get_main_menu_keyboard())
    else:
        msg = bot.send_authorization_message(chat_id)
        bot.register_next_step_handler(msg, authorization)
Ejemplo n.º 6
0
def start_message(message):
    chat_id = message.chat.id
    user = core.User(chat_id)

    if not user.object:
        bot.send_message(chat_id=chat_id, text=bot.get_start_message())
        msg = bot.send_authorization_message(chat_id=chat_id)
        bot.register_next_step_handler(msg, authorization)
        return

    bot.send_message(chat_id=chat_id, text=bot.get_start_message(), reply_markup=keyboards.get_main_menu_keyboard())
Ejemplo n.º 7
0
def feedback_processing(message):
    chat_id = message.chat.id
    user = models.TelegramUser.objects.get_or_create(chat_id=chat_id)[0]

    if message.text == 'Отмена':
        message_to_send = 'Тогда в другой раз😊'
        bot.send_message(chat_id=chat_id, text=message_to_send, reply_markup=keyboards.get_main_menu_keyboard())
    else:
        user.last_question = message.text
        user.save()
        message_to_send = 'Введите Ваш номер телефона'
        msg = bot.send_message(chat_id=chat_id, text=message_to_send, reply_markup=keyboards.get_cancel_keyboard())
        bot.register_next_step_handler(msg, phone_number_processing)
Ejemplo n.º 8
0
def search_processing(message):
    chat_id = message.chat.id
    if message.text == 'Отмена':
        message_to_send = 'Тогда в другой раз😊'
        bot.send_message(chat_id=chat_id, text=message_to_send, reply_markup=keyboards.get_main_menu_keyboard())
    else:
        questions = core.QuestionsManager.search(message.text)
        if not questions:
            core.RequestManager.create_question(question=message.text)
            message_to_send = bot.get_not_found_answer()
            bot.send_message(chat_id=chat_id, text=message_to_send,
                             reply_markup=keyboards.get_question_not_found_keyboard())
            return
        else:
            message_to_send = 'Результат поиска😉'
            bot.send_message(chat_id=chat_id, text=message_to_send, reply_markup=keyboards.get_main_menu_keyboard())
            for question in questions:
                message_to_send = f'❓Вопрос:\n' \
                                  f'{question.question}\n\n' \
                                  f'❗Ответ:\n' \
                                  f'{question.answer}'
                bot.send_message(chat_id=chat_id, text=message_to_send)
            return
Ejemplo n.º 9
0
def text_message(message):
    chat_id = message.chat.id
    user = models.TelegramUser.objects.get_or_create(chat_id=chat_id)[0]
    if message.from_user.first_name:
        user.name = message.from_user.first_name
    if message.from_user.username:
        user.username = message.from_user.username
    user.save()
    text = message.text

    if "<<" in text:
        text = text[3:]

    categories = categories_manager.get_categories(parent_category_text=text)
    if categories:
        chat_id = message.chat.id
        message_to_send = 'Выберите инетресующую Вас категорию'
        bot.send_message(chat_id=chat_id, text=message_to_send,
                         reply_markup=keyboards.get_categories_keyboard(categories))
        return
    questions = questions_manager.get_questions(category_text=text)
    if questions:
        for question in questions:
            text = f'❓Вопрос:\n' \
                   f'{question.question}\n\n' \
                   f'❗Ответ:\n' \
                   f'{question.answer}'
            bot.send_message(chat_id=chat_id, text=text)
        return
    else:
        questions = core.QuestionsManager.search(message.text)
        if not questions:
            core.RequestManager.create_question(question=message.text)
            message_to_send = bot.get_not_found_answer()
            bot.send_message(chat_id=chat_id, text=message_to_send,
                             reply_markup=keyboards.get_question_not_found_keyboard())
            return
        else:
            message_to_send = 'Результат поиска😉'
            bot.send_message(chat_id=chat_id, text=message_to_send, reply_markup=keyboards.get_main_menu_keyboard())
            for question in questions:
                message_to_send = f'❓Вопрос:\n' \
                                  f'{question.question}\n\n' \
                                  f'❗Ответ:\n' \
                                  f'{question.answer}'
                bot.send_message(chat_id=chat_id, text=message_to_send)
            return
Ejemplo n.º 10
0
 def send_invalid_message_answer(self, chat_id):
     text = 'Я Вас не понимаю. Воспользуйтесь клавиатурой'
     self.send_message(chat_id=chat_id, text=text, reply_markup=keyboards.get_main_menu_keyboard())