예제 #1
0
def process_change_user_phone_number(message: Message):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)

    def error():
        error_msg = strings.get_string('settings.send_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_change_user_phone_number)

    if message.contact:
        userservice.set_user_phone_number(user_id, message.contact.phone_number)
    else:
        if not message.text:
            error()
            return
        if strings.get_string('go_back', language) in message.text:
            back_to_the_settings_menu(chat_id, language)
            return
        match = re.match(r'\+*998\s*\d{2}\s*\d{3}\s*\d{2}\s*\d{2}', message.text)
        if not match:
            error()
            return
        phone_number = match.group()
        userservice.set_user_phone_number(user_id, phone_number)
    success_message = strings.get_string('settings.success_change_phone_number', language)
    back_to_the_settings_menu(chat_id, language, success_message)
예제 #2
0
def process_change_user_language(message: Message):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)

    def error():
        error_msg = strings.get_string('settings.choose_language')
        telegram_bot.send_message(chat_id, error_msg)
        telegram_bot.register_next_step_handler_by_chat_id(chat_id, process_change_user_language)

    if not message.text:
        error()
        return
    if strings.get_string('go_back', language) in message.text:
        back_to_the_settings_menu(chat_id, language)
    elif strings.get_string('language.russian') in message.text:
        new_language = 'ru'
        userservice.set_user_language(user_id, new_language)
        success_message = strings.get_string('settings.success_change_language', new_language)
        back_to_the_settings_menu(chat_id, new_language, success_message)
    elif strings.get_string('language.uzbek') in message.text:
        new_language = 'uz'
        userservice.set_user_language(user_id, new_language)
        success_message = strings.get_string('settings.success_change_language', new_language)
        back_to_the_settings_menu(chat_id, new_language, success_message)
    else:
        error()
예제 #3
0
def confirmation_processor(message: Message, **kwargs):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)

    def error():
        error_msg = strings.get_string('order.confirmation_error', language)
        bot.send_message(chat_id, error_msg)
        bot.register_next_step_handler_by_chat_id(chat_id,
                                                  confirmation_processor)

    if not message.text:
        error()
        return
    if strings.get_string('order.confirm', language) in message.text:
        first_name = message.from_user.first_name
        last_name = message.from_user.last_name
        total = kwargs.get('total')
        order = orderservice.confirm_order(user_id, first_name, last_name,
                                           total)
        order_success_message = strings.get_string('order.success', language)
        back_to_the_catalog(chat_id, language, order_success_message)
        notify_new_order(order, total)
        trelloservice.add_order_to_trello_board(order)
    elif strings.get_string('order.cancel', language) in message.text:
        order_canceled_message = strings.get_string('order.canceled', language)
        back_to_the_catalog(chat_id, language, order_canceled_message)
    else:
        error()
예제 #4
0
def from_ages(language: str, used_ages: str = None) -> ReplyKeyboardMarkup:
    age_keyboard = ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
    if used_ages and used_ages != '':
        if used_ages != AdCampaign.AudienceAges.ALL:
            user_ages = [age.strip() for age in used_ages.split(',')]
            current_ages = [age for age in user_ages if age != '']
            unused_ages = list(
                set(AdCampaign.AudienceAges.AGES) - set(current_ages))
            if '6-10' in unused_ages:
                index = unused_ages.index('6-10')
                unused_ages[index] = '06-10'
            unused_ages.sort()
            if '06-10' in unused_ages:
                index = unused_ages.index('06-10')
                unused_ages[index] = '6-10'
        else:
            unused_ages = []
    else:
        unused_ages = AdCampaign.AudienceAges.AGES
    age_keyboard.add(
        *[from_ages_enum_value(value, language) for value in unused_ages])
    if used_ages:
        age_keyboard.add(get_string('campaign.continue', language))
        age_keyboard.add(get_string('campaign.reset', language))
    else:
        age_keyboard.add(
            from_ages_enum_value(AdCampaign.AudienceAges.ALL, language))
    age_keyboard.add(get_string('go_back', language),
                     get_string('main_menu', language))

    return age_keyboard
예제 #5
0
def confirmation_processor(message: Message, **kwargs):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)

    def error():
        error_msg = strings.get_string('order.confirmation_error', language)
        bot.send_message(chat_id, error_msg)
        bot.register_next_step_handler_by_chat_id(chat_id,
                                                  confirmation_processor)

    if not message.text:
        error()
        return
    if strings.get_string('order.confirm', language) in message.text:
        total = kwargs.get('total')
        user = userservice.get_user_by_telegram_id(user_id)
        order = orderservice.confirm_order(user_id, user.full_user_name, total)
        order_success_message = strings.get_string('order.success', language)
        back_to_the_catalog(chat_id, language, order_success_message)
        notify_new_order(order, total)
    elif strings.get_string('order.cancel', language) in message.text:
        order_canceled_message = strings.get_string('order.canceled', language)
        if 'message_id' in kwargs:
            invoice_message_id = kwargs.get('message_id')
            bot.delete_message(chat_id, invoice_message_id)
        back_to_the_catalog(chat_id, language, order_canceled_message)
    else:
        error()
예제 #6
0
def cart_processor(message: Message, callback=None):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)

    cart = userservice.get_user_cart(user_id)
    if len(cart) == 0:
        cart_empty_message = strings.get_string('cart.empty', language)
        bot.send_message(chat_id, cart_empty_message)
        if callback:
            bot.register_next_step_handler_by_chat_id(chat_id, callback)
        else:
            bot.register_next_step_handler_by_chat_id(chat_id,
                                                      catalog_processor)
        return
    cart_help_message = strings.get_string('cart.help', language)
    total = _total_cart_sum(cart)
    cart_contains_message = strings.from_cart_items(cart, language, total)
    cart_items_keyboard = keyboards.from_cart_items(cart, language)
    bot.send_message(chat_id, cart_help_message, parse_mode='HTML')
    bot.send_message(chat_id,
                     cart_contains_message,
                     parse_mode='HTML',
                     reply_markup=cart_items_keyboard)
    bot.register_next_step_handler_by_chat_id(chat_id, cart_action_processor)
예제 #7
0
def count_callback_query(call):
    def _total_cart_sum(cart) -> int:
        summary_dishes_sum = [
            cart_item.dish.price * cart_item.count for cart_item in cart
        ]
        total = sum(summary_dishes_sum)
        return total

    chat_id = call.message.chat.id
    user_id = call.from_user.id
    language = userservice.get_user_language(user_id)
    bot.answer_callback_query(call.id)
    bot.clear_step_handler_by_chat_id(chat_id)
    selected_number = int(call.data[6:])
    current_dish = userservice.get_current_user_dish(user_id)
    dish_to_check = Dish.query.get(current_dish.id)
    if selected_number > dish_to_check.quantity:
        not_enough_count = strings.get_string(
            'not_enough_count', language).format(dish_to_check.quantity)
        msg = bot.send_message(chat_id, text=not_enough_count)
        bot.register_next_step_handler(msg, dish_action_processor)
    else:
        userservice.add_dish_to_cart(user_id, current_dish, selected_number)
        cart = userservice.get_user_cart(user_id)
        total = _total_cart_sum(cart)
        bot.delete_message(chat_id, call.message.message_id)
        cart_contains_message = strings.from_cart_items(cart, language, total)
        continue_message = strings.get_string(
            'catalog.continue', language).format(cart_contains_message)
        back_to_the_catalog(chat_id, language, continue_message)
        catalog_message = strings.get_string('catalog.start', language)
        bot.send_message(chat_id, catalog_message, parse_mode='HTML')
예제 #8
0
def budget_processor(message: Message):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)

    def error():
        _to_budget(chat_id, language, include_keyboard=False)

    if not message.text:
        error()
        return
    if strings.get_string('go_back', language) in message.text:
        _to_audience_age(chat_id, language)
    elif strings.get_string('main_menu', language) in message.text:
        _to_main_menu(chat_id, language)
    else:
        budget_enum_value = strings.text_to_budget_enum(message.text, language)
        if not budget_enum_value:
            error()
            return
        coverage = advertservice.get_coverages_by_budget(budget_enum_value)
        coverage_msg = strings.from_coverage_to_text(coverage, language)
        coverage_keyboard = keyboards.get_keyboard('campaign.coverage', language)
        bot.send_message(chat_id, coverage_msg, parse_mode='Markdown', reply_markup=coverage_keyboard)
        bot.register_next_step_handler_by_chat_id(chat_id, coverage_processor, budget=budget_enum_value)
예제 #9
0
def from_dishes(dishes, language: str) -> ReplyKeyboardMarkup:
    dishes_keyboard = ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
    names = [dish.name for dish in dishes]
    dishes_keyboard.add(*names)
    dishes_keyboard.add(get_string('catalog.cart', language),
                        get_string('go_back', language))
    return dishes_keyboard
예제 #10
0
def dish_action_processor(message: Message):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)

    def error():
        error_message = strings.get_string('catalog.dish_action_error',
                                           language)
        bot.send_message(chat_id, error_message)
        bot.register_next_step_handler_by_chat_id(chat_id,
                                                  dish_action_processor)

    if not message.text:
        error()
        return
    current_dish = userservice.get_current_user_dish(user_id)
    if strings.get_string('go_back', language) in message.text:
        dishes = dishservice.get_dishes_from_category(current_dish.category,
                                                      sort_by_number=True)
        dish_message = strings.get_string('catalog.choose_dish', language)
        dishes_keyboard = keyboards.from_dishes(dishes, language)
        bot.send_message(chat_id, dish_message, reply_markup=dishes_keyboard)
        bot.register_next_step_handler_by_chat_id(chat_id,
                                                  choose_dish_processor)
    elif strings.get_string('catalog.cart', language) in message.text:
        cart.cart_processor(message, dish_action_processor)
    else:
        if not message.text.isdigit():
            error()
            return
        userservice.add_dish_to_cart(user_id, current_dish, int(message.text))
        continue_message = strings.get_string('catalog.continue', language)
        back_to_the_catalog(chat_id, language, continue_message)
예제 #11
0
def process_user_language(message: Message, **kwargs):
    chat_id = message.chat.id
    accept_policy = kwargs.get('accept_policy')

    def error():
        if message.text == '/start':
            registration.welcome(message)
            return
        error_msg = strings.get_string('welcome.say_me_language')
        telegram_bot.send_message(chat_id, error_msg)
        telegram_bot.register_next_step_handler_by_chat_id(chat_id, process_user_language)

    if not message.text:
        error()
        return
    if message.text.startswith('/'):
        error()
        return
    if strings.get_string('language.russian') in message.text:
        language = 'ru'
    elif strings.get_string('language.uzbek') in message.text:
        language = 'uz'
    else:
        error()
        return
    request_registration_handler(message, language, accept_policy=accept_policy)
예제 #12
0
def confirmation_processor(message: Message, **kwargs):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)

    def error():
        error_msg = strings.get_string('order.confirmation_error', language)
        bot.send_message(chat_id, error_msg)
        bot.register_next_step_handler_by_chat_id(chat_id,
                                                  confirmation_processor)

    if not message.text:
        error()
        return
    if strings.get_string('order.confirm', language) in message.text:
        total = kwargs.get('total')
        user = userservice.get_user_by_telegram_id(user_id)
        order = orderservice.confirm_order(user_id, user.full_user_name, total)
        botutils.to_main_menu(chat_id, language,
                              strings.get_string('notifications.wait'))
        current_user = userservice.get_user_by_id(user_id)
        count_orders = current_user.count_orders
        notify_new_order(order, total, count_orders)
    elif strings.get_string('order.cancel', language) in message.text:
        userservice.clear_user_cart(user_id)
        order_canceled_message = strings.get_string('order.canceled', language)
        if 'message_id' in kwargs:
            invoice_message_id = kwargs.get('message_id')
            bot.delete_message(chat_id, invoice_message_id)
        botutils.to_main_menu(chat_id, language, order_canceled_message)
    else:
        error()
예제 #13
0
def catalog_processor(message: Message):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)

    def error():
        error_message = strings.get_string('catalog.error', language)
        bot.send_message(chat_id, error_message)
        bot.register_next_step_handler_by_chat_id(chat_id, catalog_processor)

    if not message.text:
        error()
        return
    if strings.get_string('go_back', language) in message.text:
        botutils.to_main_menu(chat_id, language)
    elif strings.get_string('catalog.cart', language) in message.text:
        cart.cart_processor(message)
    elif strings.get_string('catalog.make_order', language) in message.text:
        orders.order_processor(message)
    else:
        try:
            category_name = message.text
            dishes = dishservice.get_dishes_by_category_name(
                category_name, language, sort_by_number=True)
        except exceptions.CategoryNotFoundError:
            error()
            return
        dish_message = strings.get_string('catalog.choose_dish', language)
        dishes_keyboard = keyboards.from_dishes(dishes, language)
        bot.send_message(chat_id, dish_message, reply_markup=dishes_keyboard)
        bot.register_next_step_handler_by_chat_id(chat_id,
                                                  choose_dish_processor)
예제 #14
0
def payment_method_processor(message: Message):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)
    current_order = orderservice.get_current_order_by_user(user_id)

    def error():
        error_msg = strings.get_string('order.payment_error', language)
        bot.send_message(chat_id, error_msg)
        bot.register_next_step_handler_by_chat_id(chat_id,
                                                  payment_method_processor)

    def phone_number():
        current_order = orderservice.set_phone_number(user_id)
        _to_the_confirmation(chat_id, current_order, language)

    if not message.text:
        error()
        return
    if strings.get_string('go_to_menu', language) in message.text:
        botutils.to_main_menu(chat_id, language)
    elif strings.get_string('go_back', language) in message.text:
        if current_order.shipping_method == Order.ShippingMethods.PICK_UP:
            back_to_the_catalog(chat_id, language)
        elif current_order.shipping_method == Order.ShippingMethods.DELIVERY:
            back_to_the_catalog(chat_id, language)
    elif strings.from_order_payment_method(Order.PaymentMethods.CASH,
                                           language) in message.text:
        orderservice.set_payment_method(user_id, Order.PaymentMethods.CASH)
        phone_number()
    else:
        error()
예제 #15
0
def _to_the_confirmation(chat_id, current_order, language):
    total = _total_order_sum(current_order.order_items.all())
    summary_order_message = strings.from_order(current_order, language, total)
    confirmation_keyboard = keyboards.get_keyboard('order.confirmation', language)
    if current_order.payment_method == Order.PaymentMethods.PAYME:
        title = strings.get_string('order.payment.title', language).format(current_order.id)
        description = strings.get_string('order.payment.description', language)
        payload = str(total)
        start_parameter = secrets.token_hex(20)
        currency = 'UZS'
        prices = strings.from_order_items_to_labeled_prices(current_order.order_items.all(), language)
        confirmation_keyboard = keyboards.get_keyboard('order.payment_confirmation', language)
        bot.send_message(chat_id, summary_order_message, parse_mode='HTML', reply_markup=confirmation_keyboard)
        invoice = bot.send_invoice(chat_id, title, description, payload, Config.PAYMENT_PROVIDER_TOKEN, currency, prices,
                         start_parameter)
        bot.register_next_step_handler_by_chat_id(chat_id, confirmation_processor, total=total, message_id=invoice.message_id)
        return
    elif current_order.payment_method == Order.PaymentMethods.CLICK:
        title = strings.get_string('order.payment.title', language).format(current_order.id)
        description = strings.get_string('order.payment.description', language)
        payload = str(total)
        start_parameter = secrets.token_hex(20)
        currency = 'UZS'
        prices = strings.from_order_items_to_labeled_prices(current_order.order_items.all(), language)
        confirmation_keyboard = keyboards.get_keyboard('order.payment_confirmation', language)
        bot.send_message(chat_id, summary_order_message, parse_mode='HTML', reply_markup=confirmation_keyboard)
        invoice = bot.send_invoice(chat_id, title, description, payload, Config.PAYMENT_PROVIDER_TOKEN_CLICK, currency, prices,
                         start_parameter)
        bot.register_next_step_handler_by_chat_id(chat_id, confirmation_processor, total=total, message_id=invoice.message_id)
        return
    else:
        bot.send_message(chat_id, summary_order_message, parse_mode='HTML', reply_markup=confirmation_keyboard)
    bot.register_next_step_handler_by_chat_id(chat_id, confirmation_processor, total=total)
예제 #16
0
def channel_processor(message: Message):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)

    def error():
        error_msg = strings.get_string('package_offers.channel', language)
        bot.send_message(chat_id, error_msg)
        bot.register_next_step_handler_by_chat_id(chat_id, channel_processor)

    if not message.text:
        error()
        return
    if strings.get_string('go_back', language) in message.text:
        main_menu_message = strings.get_string('main_menu.choose_option', language)
        main_menu_keyboard = keyboards.get_keyboard('main_menu', language)
        bot.send_message(chat_id, main_menu_message, reply_markup=main_menu_keyboard)
        return
    try:
        package_offers = channelservice.get_package_offers_by_channel(message.text)
    except channelservice.ChannelNotFound:
        error()
        return
    for package_offer in package_offers:
        if package_offer.telegram_id:
            bot.send_document(chat_id, package_offer.telegram_id)
        else:
            bot.send_chat_action(chat_id, 'upload_document')
            file = open(package_offer.file_path, 'rb')
            sent_file = bot.send_document(chat_id, file)
            tg_id = sent_file.document.file_id
            channelservice.set_telegram_id_for_price_file(package_offer.id, tg_id)
    bot.register_next_step_handler_by_chat_id(chat_id, channel_processor)
예제 #17
0
def process_user_language(message: Message):
    chat_id = message.chat.id

    def error():
        error_msg = strings.get_string('welcome.say_me_language')
        telegram_bot.send_message(chat_id, error_msg)
        telegram_bot.register_next_step_handler_by_chat_id(
            chat_id, process_user_language)

    if not message.text:
        error()
        return
    if message.text.startswith('/'):
        error()
        return
    if strings.get_string('language.russian') in message.text:
        language = 'ru'
    elif strings.get_string('language.uzbek') in message.text:
        language = 'uz'
    else:
        error()
        return
    next_message = strings.get_string('welcome.phone_number', language)
    phone_keyboard = keyboards.from_user_phone_number(language)
    telegram_bot.send_message(chat_id,
                              next_message,
                              reply_markup=phone_keyboard,
                              parse_mode='HTML')
    telegram_bot.register_next_step_handler_by_chat_id(chat_id,
                                                       process_phone_number,
                                                       language=language)
예제 #18
0
def choose_dish_processor(message: Message, **kwargs):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)

    def error():
        error_message = strings.get_string('catalog.dish_error', language)
        bot.send_message(chat_id, error_message)
        bot.register_next_step_handler_by_chat_id(chat_id,
                                                  choose_dish_processor)

    if not message.text:
        error()
        return
    if strings.get_string('go_back', language) in message.text:
        if 'category' in kwargs:
            category = kwargs.get('category')
            back_to_the_catalog(chat_id, language, parent_category=category)
            return
        back_to_the_catalog(chat_id, language)
    elif strings.get_string('catalog.cart', language) in message.text:
        cart.cart_processor(message, choose_dish_processor)
    else:
        dish_name = message.text
        dish = dishservice.get_dish_by_name(dish_name, language,
                                            kwargs.get('category'))
        if not dish:
            error()
            return
        userservice.set_current_user_dish(user_id, dish.id)
        dish_info = strings.from_dish(dish, language)
        dish_keyboard = keyboards.get_keyboard('catalog.dish_keyboard',
                                               language)
        if dish.image_id or dish.image_path:
            if dish.image_path and not dish.image_id:
                try:
                    image = open(dish.image_path, 'rb')
                except FileNotFoundError:
                    bot.send_message(chat_id,
                                     dish_info,
                                     reply_markup=dish_keyboard)
                else:
                    sent_message = bot.send_photo(chat_id,
                                                  image,
                                                  caption=dish_info,
                                                  reply_markup=dish_keyboard)
                    dishservice.set_dish_image_id(
                        dish, sent_message.photo[-1].file_id)
            elif dish.image_id:
                bot.send_photo(chat_id,
                               dish.image_id,
                               caption=dish_info,
                               reply_markup=dish_keyboard)
        else:
            bot.send_message(chat_id, dish_info, reply_markup=dish_keyboard)
        dish_action_helper = strings.get_string('catalog.dish_action_helper',
                                                language)
        bot.send_message(chat_id, dish_action_helper)
        bot.register_next_step_handler_by_chat_id(chat_id,
                                                  dish_action_processor)
예제 #19
0
def phone_number_processor(message: Message):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)

    def error():
        error_msg = strings.get_string('calls.number', language)
        bot.send_message(chat_id, error_msg, parse_mode='HTML')
        bot.register_next_step_handler_by_chat_id(chat_id,
                                                  phone_number_processor)

    if message.contact:
        callservice.set_call_phone_number(user_id,
                                          message.contact.phone_number)
    else:
        if not message.text:
            error()
            return
        if strings.get_string('go_back', language) in message.text:
            _to_main_menu(chat_id, language)
            return
        match = re.match(r'\+*998\s*\d{2}\s*\d{3}\s*\d{2}\s*\d{2}',
                         message.text)
        if not match:
            error()
            return
        phone_number = match.group()
        callservice.set_call_phone_number(user_id, phone_number)
    time_message = strings.get_string('call.time', language)
    time_keyboard = keyboards.get_keyboard('call.time', language)
    bot.send_message(chat_id, time_message, reply_markup=time_keyboard)
    bot.register_next_step_handler_by_chat_id(chat_id, call_time_processor)
예제 #20
0
def change_language_processor(message: Message):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)

    def error():
        if message.text == '/start':
            registration.welcome(message)
            return
        error_msg = strings.get_string('language.change', language)
        telegram_bot.send_message(chat_id, error_msg)
        telegram_bot.register_next_step_handler_by_chat_id(
            chat_id, change_language_processor)

    if not message.text:
        error()
        return
    if strings.get_string('go_back', language) in message.text:
        botutlis.to_main_menu(chat_id, language)
        return
    elif strings.get_string('language.russian') in message.text:
        new_language = 'ru'
        userservice.set_user_language(user_id, new_language)
    elif strings.get_string('language.uzbek') in message.text:
        new_language = 'uz'
    else:
        error()
        return
    userservice.set_user_language(user_id, new_language)
    success_message = strings.get_string('language.success', new_language)
    botutlis.to_main_menu(chat_id, new_language, success_message)
예제 #21
0
def from_change_language(current_language: str) -> ReplyKeyboardMarkup:
    change_language_keyboard = ReplyKeyboardMarkup(resize_keyboard=True, row_width=1)
    if current_language == 'uz':
        change_language_keyboard.add(get_string('language.russian'))
    else:
        change_language_keyboard.add(get_string('language.uzbek'))
    change_language_keyboard.add(get_string('go_back', current_language))
    return change_language_keyboard
예제 #22
0
def _to_the_payment_method(chat_id, language, user_id: int):
    current_order = orderservice.get_current_order_by_user(user_id)
    if current_order.shipping_method == Order.ShippingMethods.PICK_UP:
        payment_message = strings.get_string('order.payment_pickup', language)
    else:
        payment_message = strings.get_string('order.payment_delivery', language)
    payment_keyboard = keyboards.get_keyboard('order.payment', language)
    bot.send_message(chat_id, payment_message, reply_markup=payment_keyboard, parse_mode='HTML')
    bot.register_next_step_handler_by_chat_id(chat_id, payment_method_processor)
예제 #23
0
def from_user_phone_number(language, phone_number: str = None, go_back: bool = True) -> ReplyKeyboardMarkup:
    phone_number_keyboard = ReplyKeyboardMarkup(resize_keyboard=True, row_width=1)
    if phone_number and phone_number != '':
        phone_number_keyboard.add(phone_number)
    phone_button = KeyboardButton(get_string('my_number', language), request_contact=True)
    phone_number_keyboard.add(phone_button)
    if go_back:
        phone_number_keyboard.add(get_string('go_back', language))
    return phone_number_keyboard
예제 #24
0
def from_dish_categories(dish_categories,
                         language: str) -> ReplyKeyboardMarkup:
    categories_keyboard = ReplyKeyboardMarkup(resize_keyboard=True,
                                              row_width=2)
    names = [category.name for category in dish_categories]
    categories_keyboard.add(*names)
    categories_keyboard.add(get_string('catalog.cart', language),
                            get_string('go_back', language))
    return categories_keyboard
예제 #25
0
def from_dish_categories(dish_categories, language: str) -> ReplyKeyboardMarkup:
    categories_keyboard = ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
    categories_keyboard.add(get_string('catalog.cart', language), get_string('catalog.make_order', language))
    if language == 'uz':
        names = [category.name_uz for category in dish_categories]
    else:
        names = [category.name for category in dish_categories]
    categories_keyboard.add(*names)
    categories_keyboard.add(get_string('go_to_menu', language), get_string('go_back', language))
    return categories_keyboard
예제 #26
0
def notify_handler(message: Message):
    chat_id = message.chat.id
    chat_title = message.chat.title

    result = notifyservice.add_notify_chat(chat_id, chat_title)
    if result:
        success_message = strings.get_string('notify.registration_success')
        bot.send_message(chat_id, success_message)
    else:
        exists_message = strings.get_string('notify.exists')
        bot.send_message(chat_id, exists_message)
예제 #27
0
def notifications_handler(message: Message):
    chat_id = message.chat.id
    chat_title = message.chat.title

    result = notifyservice.add_notification_chat(chat_id, chat_title)
    if result:
        success_message = strings.get_string('notifications.success')
        telegram_bot.send_message(chat_id, success_message)
    else:
        exist_message = strings.get_string('notifications.exist')
        telegram_bot.send_message(chat_id, exist_message)
예제 #28
0
def from_cart_items(cart_items, language) -> ReplyKeyboardMarkup:
    cart_items_keyboard = ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
    if language == 'uz':
        names = [cart_item.dish.description_uz for cart_item in cart_items]
    else:
        names = [cart_item.dish.description for cart_item in cart_items]
    names = ['❌ ' + name for name in names]
    cart_items_keyboard.add(*names)
    cart_items_keyboard.add(get_string('go_back', language), get_string('cart.clear', language))
    cart_items_keyboard.add(get_string('catalog.make_order', language))
    return cart_items_keyboard
예제 #29
0
def _to_audience_age(chat_id, language, include_keyboard=True, current_ad_order: AdCampaign = None):
    audience_age_msg = strings.get_string('campaign.audience_age', language)
    if include_keyboard:
        ad_campaign = current_ad_order or advertservice.get_current_campaign(chat_id)
        audience_age_keyboard = keyboards.from_ages(language, ad_campaign.age_of_audience)
        if ad_campaign.age_of_audience and ad_campaign.age_of_audience != '':
            selected_ages_template = strings.get_string('campaign.selected_ages', language)
            audience_age_msg = selected_ages_template.format(strings.format_ages(ad_campaign.age_of_audience, language))
        bot.send_message(chat_id, audience_age_msg, reply_markup=audience_age_keyboard, parse_mode='Markdown')
    else:
        bot.send_message(chat_id, audience_age_msg)
    bot.register_next_step_handler_by_chat_id(chat_id, audience_age_processor)
예제 #30
0
def from_dishes(dishes, language: str) -> ReplyKeyboardMarkup:
    dishes_keyboard = ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
    dishes_keyboard.add(get_string('catalog.cart', language),
                        get_string('go_back', language))
    if language == 'uz':
        names = [dish.name_uz for dish in dishes]
    else:
        names = [dish.name for dish in dishes]
    dishes_keyboard.add(*names)
    #####BELLOW###########
    dishes_keyboard.add(get_string('go_to_menu', language))
    return dishes_keyboard