Example #1
0
File: bot.py Project: mmdaz/Bot
def get_date_day(bot, update):
    day = update.get_effective_message().text
    dispatcher.set_conversation_data(update, "day", day)
    user_peer = update.get_effective_user()
    if not (
        (0 < int(day) < 32
         and 0 < int(dispatcher.get_conversation_data(update, "month")) < 7) or
        (0 < int(day) < 31
         and 6 < int(dispatcher.get_conversation_data(update, "month")) < 13)):
        bot.send_message(TemplateMessage(Message.INVALID_INPUT, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_date_day),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
    else:
        bot.send_message(TemplateMessage(Message.GET_ALARM_HOUR, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_date_hour),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
Example #2
0
File: bot.py Project: mmdaz/Bot
def get_date_hour(bot, update):
    hour = update.get_effective_message().text
    dispatcher.set_conversation_data(update, "hour", hour)
    user_peer = update.get_effective_user()
    if not 0 <= int(hour) < 24:
        bot.send_message(TemplateMessage(Message.INVALID_INPUT, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_date_hour),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
    else:
        bot.send_message(TemplateMessage(Message.GET_ALARM_MINUTE,
                                         button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_date_minute),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
Example #3
0
File: bot.py Project: mmdaz/Bot
def get_date_minute(bot, update):
    minute = update.get_effective_message().text
    dispatcher.set_conversation_data(update, "minute", minute)
    user_peer = update.get_effective_user()
    if not 0 <= int(minute) < 60:
        bot.send_message(TemplateMessage(Message.INVALID_INPUT, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_date_minute),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
    else:
        # print(create_time(year, month, day, hour, minute))
        dispatcher.get_conversation_data(
            update, "alarm").start_time = create_time(
                dispatcher.get_conversation_data(update, "year"),
                dispatcher.get_conversation_data(update, "month"),
                dispatcher.get_conversation_data(update, "day"),
                dispatcher.get_conversation_data(update, "hour"),
                dispatcher.get_conversation_data(update, "minute"))
        bot.send_message(TemplateMessage(Message.GET_ALARM_REPETITION_PERIOD,
                                         button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), finish_creating_alarm),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
Example #4
0
File: bot.py Project: mmdaz/Bot
def get_date_year(bot, update):
    user_peer = update.get_effective_user()
    year = update.get_effective_message().text
    dispatcher.set_conversation_data(update, "year", year)
    if int(year) < 1397:
        bot.send_message(TemplateMessage(Message.INVALID_INPUT, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_date_year),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
        print("salammmmmmmmmmmmmmmmmmmmmmmmmm")

    else:
        bot.send_message(TemplateMessage(Message.GET_ALARM_MONTH, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_date_month),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
Example #5
0
File: bot.py Project: mmdaz/Bot
def get_debt_date_month(bot, update):
    user_peer = update.get_effective_user()
    debt_month = update.get_effective_message()
    dispatcher.set_conversation_data(update, "debt_month", debt_month.text)
    if not (0 < int(debt_month.text) < 13):
        bot.send_message(TemplateMessage(Message.INVALID_INPUT, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_debt_date_month),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
    else:
        bot.send_message(TemplateMessage(Message.GET_DEBT_DAY, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_debt_date_day),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
Example #6
0
File: bot.py Project: mmdaz/Bot
def get_alarm_stop_message(bot, update):
    user_peer = update.get_effective_user()
    alarm_stop_message = update.get_effective_message()
    if check_stop_message_repetition(user_peer.get_json_str(),
                                     alarm_stop_message.text):
        bot.send_message(TemplateMessage(Message.STOP_MESSAGE_REPETIOTION,
                                         button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_alarm_stop_message),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
    else:
        dispatcher.get_conversation_data(
            update, "alarm").stop_message = alarm_stop_message.text
        bot.send_message(TemplateMessage(Message.GET_ALARM_PHOTO, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(PhotoFilter(), get_alarm_photo),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
Example #7
0
File: bot.py Project: mmdaz/Bot
def start_bot(bot, update):
    user_peer = update.get_effective_user()
    input = update.get_effective_message()
    print(input.text)
    btn_list = [
        TemplateMessageButton("ساختن هشدار جدید ", "/create_alarm", 0),
        TemplateMessageButton("اضافه کردن بدهی ", "/add_debt", 0),
        TemplateMessageButton("گرفتن فایل اکسل صورتحساب ها  ", "/get_excel", 0)
    ]
    temlate_message = TemplateMessage(
        general_message=Message.START_BOT_MESSAGE, btn_list=btn_list)
    bot.send_message(temlate_message,
                     user_peer,
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(update, [
        MessageHandler(TemplateResponseFilter(keywords=["/create_alarm"]),
                       start_creating_alarm),
        MessageHandler(TemplateResponseFilter(keywords=["/add_debt"]),
                       start_get_debt_conversation),
        MessageHandler(TemplateResponseFilter(keywords=["/get_excel"]),
                       send_excel_report),
        MessageHandler(TextFilter(keywords=["/start"]), start_bot),
        MessageHandler(TemplateResponseFilter(keywords=["/start"]), start_bot)
    ])
Example #8
0
def get_tweet_text(bot, update):
    user_peer = update.get_effective_user()
    user = get_registered_user(bot, update)
    if user:
        dispatcher.set_conversation_data(update, "user", user)
        general_message = TextMessage(ReadyText.send_text_twitter)
        btn_list = [
            TemplateMessageButton(text=ButtonText.cancel,
                                  value=ButtonText.cancel,
                                  action=0)
        ]
        template_message = TemplateMessage(general_message=general_message,
                                           btn_list=btn_list)
        kwargs = {
            "message": template_message,
            "update": update,
            "bot": bot,
            "try_times": 1
        }
        bot.send_message(template_message,
                         user_peer,
                         success_callback=success_send_message,
                         failure_callback=failure_send_message,
                         kwargs=kwargs)
        dispatcher.register_conversation_next_step_handler(
            update, common_handlers + [
                MessageHandler(TextFilter(), send_tweet),
                MessageHandler(DefaultFilter(), start_conversation)
            ])
Example #9
0
def get_tweet_text(bot, update):
    user_peer = update.get_effective_user()
    user_id = user_peer.peer_id
    user = get_user(user_id=user_id)
    if not check_user_registration(update, user_peer, user):
        return 0
    general_message = TextMessage(ReadyMessage.send_text_twitter)
    btn_list = [
        TemplateMessageButton(text=TMessage.cancel,
                              value=TMessage.cancel,
                              action=0)
    ]
    template_message = TemplateMessage(general_message=general_message,
                                       btn_list=btn_list)
    kwargs = {
        "message": template_message,
        "user_peer": user_peer,
        "try_times": 1
    }
    bot.send_message(template_message,
                     user_peer,
                     success_callback=success,
                     failure_callback=failure,
                     kwargs=kwargs)
    dispatcher.register_conversation_next_step_handler(update, [
        CommandHandler("info", info),
        MessageHandler(TextFilter(), send_tweet),
        MessageHandler(DefaultFilter(), start_conversation)
    ])
Example #10
0
    def initiate_search_officers(self, bot, update):
        self.handlers.extend(self.dispatcher.message_handlers)
        user = update.get_effective_user()
        message = TemplateMessage(
            TextMessage(ConstantMessage.officer_search_criterion), [
                TemplateMessageButton(ButtonMessage.all_officers),
                TemplateMessageButton(ButtonMessage.main_menu_message)
            ])
        self.send_message(bot, update, message, user,
                          sys._getframe().f_code.co_name)
        self.handlers.extend([
            MessageHandler(
                TemplateResponseFilter(keywords=[ButtonMessage.all_officers]),
                self.handle_customer_criterion_input),
            MessageHandler(
                TemplateResponseFilter(
                    keywords=[ButtonMessage.main_menu_message]),
                self.show_menu),
        ])

        # TODO: This seems odd to me to add two lists, find a better way if possible
        self.dispatcher.register_conversation_next_step_handler(
            update, self.handlers + [
                MessageHandler(TextFilter(),
                               self.handle_customer_criterion_input)
            ])
Example #11
0
File: bot.py Project: mmdaz/Bot
def get_debt_date_day(bot, update):
    user_peer = update.get_effective_user()
    debt_day = update.get_effective_message()
    dispatcher.set_conversation_data(update, "debt_day", debt_day.text)
    if not ((0 < int(debt_day.text) < 32 and 0 < int(
            dispatcher.get_conversation_data(update, "debt_month")) < 7) or
            (0 < int(debt_day.text) < 31 and 6 < int(
                dispatcher.get_conversation_data(update, "debt_month")) < 13)):
        bot.send_message(TemplateMessage(Message.INVALID_INPUT, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_debt_date_day),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
    else:
        dispatcher.get_conversation_data(
            update, "debt").date = "{}:{}:{}".format(
                dispatcher.get_conversation_data(update, "debt_year"),
                dispatcher.get_conversation_data(update, "debt_month"),
                dispatcher.get_conversation_data(update, "debt_day"))
        print(dispatcher.get_conversation_data(update, "debt").user_id)
        bot.send_message(TemplateMessage(Message.GET_DEBT_PHOTO, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(PhotoFilter(), get_debt_photo),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
def setKolompe(bot, update):
    msg = TextMessage("مقدار کیلو گرم کلمپه را وارد نمایید :")
    bot.send_message(msg,
                     update.get_effective_user(),
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(
        update, [MessageHandler(TextFilter(), setKolompeKilo)])
    def handle_report_begin_date(self, bot, update):
        user = update.get_effective_user()
        message = arabic_to_eng_number(update.get_effective_message().text)
        if re.match(RegexPattern.interval_pattern, message):
            split_message = message.split('-')
            self.dispatcher.set_conversation_data(
                update=update,
                key='start_time_delta',
                value=split_message[0]
            )
            self.dispatcher.set_conversation_data(
                update=update,
                key='end_time_delta',
                value=split_message[1]
            )
            self.create_and_send_final_report(update, bot)

        else:
            row_date = re.match(RegexPattern.jalali_input_pattern, message)
            if row_date:
                message = TemplateMessage(
                    TextMessage(ConstantMessage.service_report_end_date),
                    [TemplateMessageButton(ButtonMessage.main_menu_message)]
                )
                self.dispatcher.set_conversation_data(
                    update=update,
                    key='begin_date',
                    value=row_date
                )
                self.send_message(
                    bot,
                    update,
                    message,
                    user,
                    sys._getframe().f_code.co_name
                )
                self.dispatcher.register_conversation_next_step_handler(
                    update,
                    self.handlers +
                    [
                        MessageHandler(
                            TextFilter(),
                            self.handle_report_end_date
                        ),
                    ]
                )

            else:
                message = TextMessage(ConstantMessage.bad_format)
                self.send_message(
                    bot,
                    update,
                    message,
                    user,
                    sys._getframe().f_code.co_name
                )
def setZire(bot, update):
    msg = TextMessage(
        "مقدار کیلو گرم زیره سیاه را وارد نمایید :\n در حال حاضر فقط زیره سیاه موجود می باشد"
    )
    bot.send_message(msg,
                     update.get_effective_user(),
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(
        update, [MessageHandler(TextFilter(), setZireKilo)])
def request_sender_name(bot, update):
    user_peer = update.get_effective_user()
    text_message = TextMessage(BotTexts.enter_sender_name)
    send_message(message=text_message,
                 peer=user_peer,
                 step=Step.request_sender_name)
    dispatcher.register_conversation_next_step_handler(
        update,
        handlers=common_handlers + [
            MessageHandler(TextFilter(), request_money_changer),
        ])
def new_user_step3(bot, update):
    phone = update.get_effective_message().text
    user.update({"phone": phone})
    msg = "شماره تلفن *{}* برای شما ثبت شد.\n برای تحویل سفارش خود ادرس مورد نظر همراه با ادرس پستی را وارد نمایید.".format(
        phone)
    textMsg = TextMessage(msg)
    bot.send_message(textMsg,
                     update.get_effective_user(),
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(
        update, [MessageHandler(TextFilter(), new_user_step4)])
def new_user_step2(bot, update):
    name = update.get_effective_message().text
    user.update({"name": name})
    msg = "نام و نام خانوادی *{}* برای شما ثبت شد. \nشماره تلفن خود را وارد نمایید. عوامل خورجین انلاین از این شماره برای پیگیری سفارش شما استفاده خواهند کرد.".format(
        name)
    textMsg = TextMessage(msg)
    bot.send_message(textMsg,
                     update.get_effective_user(),
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(
        update, [MessageHandler(TextFilter(), new_user_step3)])
def update_money_changer(bot, update):
    user_peer = update.get_effective_user()
    text_entered = arabic_to_eng_number(update.get_effective_message().text)
    previous_state = dispatcher.get_conversation_data(update, "previous_state")
    money_changer = select_money_changer_by_peer_id(user_peer.peer_id)
    res = None
    text_message = None
    if previous_state == request_remittance_fee_percent:
        percent = float(text_entered)
        res = update_money_changer_remittance_fee_percent(
            money_changer=money_changer, percent=percent)
        text_message = TextMessage(
            BotTexts.remittance_fee_percent_updated_successfully.format(
                percent))
    elif previous_state == request_dollar_rial:
        dollar_rial = float(text_entered)
        res = update_money_changer_dollar_rial(money_changer=money_changer,
                                               dollar_rial=dollar_rial)
        text_message = TextMessage(
            BotTexts.dollar_rial_updated_successfully.format(dollar_rial))
    elif previous_state == request_dollar_afghani:
        dollar_afghani = float(text_entered)
        res = update_money_changer_dollar_afghani(
            money_changer=money_changer, dollar_afghani=dollar_afghani)
        text_message = TextMessage(
            BotTexts.dollar_afghani_updated_successfully.format(
                dollar_afghani))
    elif previous_state == request_card_number:
        card_number = text_entered
        res = update_money_changer_card_number(money_changer=money_changer,
                                               card_number=card_number)
        text_message = TextMessage(
            BotTexts.card_number_updated_successfully.format(card_number))
    if res:
        buttons_list = [BotButtons.back_to_main_menu]
        template_message = TemplateMessage(text_message, buttons_list)
        send_message(message=template_message,
                     peer=user_peer,
                     step=Step.update_money_changer)
        dispatcher.register_conversation_next_step_handler(
            update,
            handlers=common_handlers + [
                MessageHandler(TextFilter(Patterns.float_numbers),
                               request_sender_name)
            ])
    else:
        buttons_list = [BotButtons.back_to_main_menu]
        template_message = TemplateMessage(TextMessage(BotTexts.error),
                                           buttons_list)
        send_message(message=template_message,
                     peer=user_peer,
                     step=Step.update_money_changer)
        dispatcher.finish_conversation(update)
def request_branch_address(bot, update):
    user_peer = update.get_effective_user()
    province = update.get_effective_message().text
    dispatcher.set_conversation_data(update, "province", province)
    text_message = TextMessage(BotTexts.enter_branch_address)
    send_message(message=text_message,
                 peer=user_peer,
                 step=Step.request_branch_address)
    dispatcher.register_conversation_next_step_handler(
        update,
        handlers=common_handlers +
        [MessageHandler(TextFilter(), insert_branch)])
def new_user_step1(bot, update):
    user_peer = update.get_effective_user()
    print("new user =>")
    print(user_peer.peer_id)
    print(user_peer.access_hash)
    msg = "ضمن عرض خوش آمد به خورجین انلاین خواهش مند است نام و نام خانوادگی خود را وارد نمایید."
    textMsg = TextMessage(msg)
    bot.send_message(textMsg,
                     user_peer,
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(
        update, [MessageHandler(TextFilter(), new_user_step2)])
Example #21
0
File: bot.py Project: mmdaz/Bot
def start_get_debt_conversation(bot, update):
    user_peer = update.get_effective_user()
    debt = Debt("", "", "", "", "", "", "")
    dispatcher.set_conversation_data(update, "debt", debt)
    debt.user_id = user_peer.get_json_str()
    bot.send_message(TemplateMessage(Message.GET_DEBT_AMOUNT, button_list),
                     user_peer,
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(update, [
        MessageHandler(TextFilter(), get_amount),
        MessageHandler(TemplateResponseFilter(keywords="/start"), start_bot)
    ])
Example #22
0
File: bot.py Project: mmdaz/Bot
def get_name_creditor(bot, update):
    user_peer = update.get_effective_user()
    creditor_name = update.get_effective_message()
    dispatcher.get_conversation_data(update,
                                     "debt").creditor_name = creditor_name.text
    bot.send_message(TemplateMessage(Message.GET_DEBT_YEAR, button_list),
                     user_peer,
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(update, [
        MessageHandler(TextFilter(), get_debt_date_year),
        MessageHandler(TemplateResponseFilter(keywords="/start"), start_bot)
    ])
Example #23
0
File: bot.py Project: mmdaz/Bot
def get_amount(bot, update):
    user_peer = update.get_effective_user()
    amount = update.get_effective_message()
    dispatcher.get_conversation_data(update, "debt").amount = amount.text
    bot.send_message(TemplateMessage(Message.GET_DEBT_CARD_NUMBER,
                                     button_list),
                     user_peer,
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(update, [
        MessageHandler(TextFilter(), get_card_number),
        MessageHandler(TemplateResponseFilter(keywords="/start"), start_bot)
    ])
def request_card_number(bot, update):
    user_peer = update.get_effective_user()
    text_message = TextMessage(BotTexts.enter_new_card_number)
    dispatcher.set_conversation_data(update, "previous_state",
                                     request_card_number)
    send_message(message=text_message,
                 peer=user_peer,
                 step=Step.request_card_number)
    dispatcher.register_conversation_next_step_handler(
        update,
        handlers=common_handlers + [
            MessageHandler(TextFilter(pattern=Patterns.float_numbers),
                           update_money_changer),
        ])
Example #25
0
File: bot.py Project: mmdaz/Bot
def get_alarm_message(bot, update):
    user_peer = update.get_effective_user()
    alarm_message = update.get_effective_message()
    dispatcher.get_conversation_data(update,
                                     "alarm").message = alarm_message.text
    bot.send_message(TemplateMessage(Message.GET_ALARM_STOP_MESSAGE,
                                     button_list),
                     user_peer,
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(update, [
        MessageHandler(TextFilter(), get_alarm_stop_message),
        MessageHandler(TemplateResponseFilter(keywords="/start"), start_bot)
    ])
def request_receiver_name(bot, update):
    user_peer = update.get_effective_user()
    branch_id = update.get_effective_message().text
    dispatcher.set_conversation_data(update, key="branch_id", value=branch_id)
    buttons_list = [BotButtons.back_to_main_menu]
    general_message = TextMessage(BotTexts.enter_receiver_name)
    template_message = TemplateMessage(general_message, buttons_list)
    send_message(message=template_message,
                 peer=user_peer,
                 step=Step.request_receiver_name)
    dispatcher.register_conversation_next_step_handler(
        update,
        handlers=common_handlers +
        [MessageHandler(TextFilter(), request_receiver_father_name)])
Example #27
0
File: bot.py Project: mmdaz/Bot
def start_creating_alarm(bot, update):
    alarm = Alarm("", "", "", "", "", "", 5, "true")
    dispatcher.set_conversation_data(update, "alarm", alarm)
    user_peer = update.get_effective_user()
    alarm.user_id = user_peer.get_json_str()
    command = update.get_effective_message()
    bot.send_message(TemplateMessage(Message.GET_ALARM_NAME, button_list),
                     user_peer,
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(update, [
        MessageHandler(TextFilter(), get_alarm_name),
        MessageHandler(TemplateResponseFilter(keywords="/start"), start_bot)
    ])
def request_amount(bot, update):
    user_peer = update.get_effective_user()
    receiver_father_name = update.get_effective_message().text
    dispatcher.set_conversation_data(update,
                                     key="receiver_father_name",
                                     value=receiver_father_name)
    buttons_list = [BotButtons.back_to_main_menu]
    template_message = TemplateMessage(TextMessage(BotTexts.enter_amount),
                                       buttons_list)
    send_message(message=template_message,
                 peer=user_peer,
                 step=Step.request_amount)
    dispatcher.register_conversation_next_step_handler(
        update,
        handlers=common_handlers + [MessageHandler(TextFilter(), get_amount)])
def request_province_name(bot, update):
    user_peer = update.get_effective_user()
    province_names = select_all_province_names()
    province_name_buttons = get_template_buttons_from_list(province_names)
    template_message = TemplateMessage(
        TextMessage(BotTexts.choose_or_enter_province), province_name_buttons)
    send_message(message=template_message,
                 peer=user_peer,
                 step=Step.request_province_name)
    dispatcher.register_conversation_next_step_handler(
        update,
        handlers=common_handlers + [
            MessageHandler(TemplateResponseFilter(keywords=province_names),
                           request_branch_address),
            MessageHandler(TextFilter(), request_branch_address)
        ])
Example #30
0
File: bot.py Project: mmdaz/Bot
def get_alarm_photo(bot, update):
    photo = update.get_effective_message()
    dispatcher.get_conversation_data(update,
                                     "alarm").photo = photo.get_json_str()
    user_peer = update.get_effective_user()
    bot.send_message(TemplateMessage(Message.GET_ALARM_YEAR, button_list),
                     user_peer,
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.set_conversation_data(update=update,
                                     key="my_data",
                                     value="my_value")
    dispatcher.register_conversation_next_step_handler(update, [
        MessageHandler(TextFilter(), get_date_year),
        MessageHandler(TemplateResponseFilter(keywords="/start"), start_bot)
    ])