def request_registration_name_handler(message: Message, **kwargs): chat_id = message.chat.id language = kwargs.get('language') accept_policy = kwargs.get('accept_policy') def error(): if message.text == '/start': welcome(message) return error_msg = strings.get_string('registration.request.welcome', language) telegram_bot.send_message(chat_id, error_msg) telegram_bot.register_next_step_handler_by_chat_id(chat_id, request_registration_name_handler, language=language) if not message.text: error() return if message.text == '/start': error() return name = message.text phone_number_message = strings.get_string('registration.request.phone_number', language) phone_number_keyboard = keyboards.from_user_phone_number(language, go_back=False) telegram_bot.send_message(chat_id, phone_number_message, parse_mode='HTML', reply_markup=phone_number_keyboard) telegram_bot.register_next_step_handler_by_chat_id(chat_id, request_registration_phone_number_handler, name=name, language=language, accept_policy=accept_policy)
def error(): if message.text == '/start': 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)
def request_registration_handler(message: Message, language: str, accept_policy: bool): chat_id = message.chat.id welcome_message = strings.get_string('registration.request.welcome', language) remove_keyboard = keyboards.get_keyboard('remove') telegram_bot.send_message(chat_id, welcome_message, reply_markup=remove_keyboard) telegram_bot.register_next_step_handler_by_chat_id(chat_id, request_registration_name_handler, language=language, accept_policy=accept_policy)
def error(): if message.text == '/start': registration.welcome(message) return error_msg = strings.get_string('order.address_error') bot.send_message(chat_id, error_msg, parse_mode='HTML') bot.register_next_step_handler_by_chat_id(chat_id, address_processor)
def error(): if message.text == '/start': registration.welcome(message) return 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)
def back_to_the_catalog(chat_id, language, message_text=None, parent_category=None): #bot.send_chat_action(chat_id, 'typing') #if not message_text: # catalog_message = strings.get_string('catalog.start', language) #else: # catalog_message = message_text #if parent_category: # catalog_message = strings.from_category_name(parent_category, language) # categories = parent_category.get_siblings(include_self=True).all() # category_keyboard = keyboards.from_dish_categories(categories, language) # bot.send_message(chat_id, catalog_message, reply_markup=category_keyboard) # if parent_category.parent: # bot.register_next_step_handler_by_chat_id(chat_id, catalog_processor, parent_category=parent_category.parent) # else: # bot.register_next_step_handler_by_chat_id(chat_id, catalog_processor) # return #categories = dishservice.get_parent_categories(sort_by_number=True) #category_keyboard = keyboards.from_dish_categories(categories, language) #bot.send_message(chat_id, catalog_message, reply_markup=category_keyboard, parse_mode='HTML') #bot.register_next_step_handler_by_chat_id(chat_id, catalog_processor) dishes = Dish.query.filter(Dish.category_id == 0, Dish.is_hidden == False).order_by( Dish.number.asc()).all() dish_message = strings.get_string('catalog.choose_dish', language) if message_text: dish_message = message_text dishes_keyboard = keyboards.from_dishes(dishes, language) bot.send_message(chat_id=chat_id, text=dish_message, reply_markup=dishes_keyboard) bot.register_next_step_handler_by_chat_id(chat_id, choose_dish_processor)
def send_category(category, message, keyboard): if category.image_path or category.image_id: if category.image_path and not category.image_id: try: image = open(category.image_path, 'rb') except FileNotFoundError: bot.send_message(chat_id=chat_id, text=message, reply_markup=keyboard) else: sent_message = bot.send_photo(chat_id=chat_id, photo=image, caption=message, reply_markup=keyboard) dishservice.set_category_image_id( category, sent_message.photo[-1].file_id) elif category.image_id: bot.send_photo(chat_id=chat_id, photo=category.image_id, caption=message, reply_markup=keyboard) else: bot.send_message(chat_id=chat_id, text=message, reply_markup=keyboard)
def back_to_the_catalog(chat_id, language, message_text=None, parent_category_id=None): parent_category = dishservice.get_category_by_id(parent_category_id) bot.send_chat_action(chat_id, 'typing') if not message_text: catalog_message = strings.get_string('catalog.start', language) else: catalog_message = message_text if parent_category: catalog_message = strings.from_category_name(parent_category, language) categories = parent_category.get_siblings(include_self=True).all() category_keyboard = keyboards.from_dish_categories( categories, language) bot.send_message(chat_id, catalog_message, reply_markup=category_keyboard) if parent_category.parent: bot.register_next_step_handler_by_chat_id( chat_id, catalog_processor, parent_category_id=parent_category.parent.id) else: bot.register_next_step_handler_by_chat_id(chat_id, catalog_processor) return categories = dishservice.get_parent_categories(sort_by_number=True) category_keyboard = keyboards.from_dish_categories(categories, language) bot.send_message(chat_id, catalog_message, reply_markup=category_keyboard, parse_mode='HTML') bot.register_next_step_handler_by_chat_id(chat_id, catalog_processor)
def about_handler(message: Message): chat_id = message.chat.id user_id = message.from_user.id language = userservice.get_user_language(user_id) about_text = settings.get_about_text('ru') telegram_bot.send_message(chat_id, about_text) botutlis.to_main_menu(chat_id, language)
def do_mailing(image, text, preview): file_id = None if preview: users = [583411442, 1294618325] else: users = User.query.all() if image: for user in users: user_id = user.id if preview is False else user if file_id: try: telegram_bot.send_photo(chat_id=user_id, photo=file_id, caption=text) except telebot.apihelper.ApiException: continue else: try: file = open(image, 'rb') file_id = telegram_bot.send_photo( chat_id=user_id, photo=file, caption=text).photo[-1].file_id file.close() except telebot.apihelper.ApiException: continue sleep(1 / 10) # 10 message per second else: for user in users: user_id = user.id if preview is False else user try: telegram_bot.send_message(chat_id=user_id, text=text) except telebot.apihelper.ApiException: continue sleep(1 / 10) # 10 message per second
def _to_product_name(chat_id, language, include_keyboard=True): product_name_msg = strings.get_string('campaign.product_name', language) if include_keyboard: go_back_keyboard = keyboards.get_keyboard('go_back', language) bot.send_message(chat_id, product_name_msg, reply_markup=go_back_keyboard) else: bot.send_message(chat_id, product_name_msg) bot.register_next_step_handler_by_chat_id(chat_id, product_name_processor)
def _to_the_address(chat_id, language): address_message = strings.get_string('order.address', language) address_keyboard = keyboards.get_keyboard('order.address', language) bot.send_message(chat_id, address_message, parse_mode='HTML', reply_markup=address_keyboard) bot.register_next_step_handler_by_chat_id(chat_id, address_processor)
def notify_call(call: Call): notify_chats = notifyservice.get_all_notify_chats() notify_message = strings.from_notify_call(call) for chat in notify_chats: try: bot.send_message(chat.id, notify_message, parse_mode='HTML') except ApiException: pass
def notify_new_comment(comment: Comment): notification_chats = notifyservice.get_all_notification_chats() notification_message = strings.from_comment_notification(comment) for chat in notification_chats: try: telegram_bot.send_message(chat.chat_id, notification_message, parse_mode='HTML') except ApiException: pass
def back_to_the_settings_menu(chat_id, language, message_txt=None): if not message_txt: settings_message = strings.get_string('main_menu.settings', language) else: settings_message = message_txt settings_keyboard = keyboards.get_keyboard('settings', language) telegram_bot.send_message(chat_id, settings_message, reply_markup=settings_keyboard) telegram_bot.register_next_step_handler_by_chat_id(chat_id, process_choose_option)
def main_menu_settings(message: Message): chat_id = message.chat.id user_id = message.from_user.id language = userservice.get_user_language(user_id) settings_message = strings.get_string('main_menu.settings', language) settings_keyboard = keyboards.get_keyboard('settings', language) telegram_bot.send_message(chat_id, settings_message, reply_markup=settings_keyboard) telegram_bot.register_next_step_handler_by_chat_id(chat_id, process_choose_option)
def _to_phone_number(chat_id, language): calls_message = strings.get_string('calls.number', language) calls_keyboard = keyboards.get_keyboard('call.number', language) bot.send_message(chat_id, calls_message, parse_mode='HTML', reply_markup=calls_keyboard) bot.register_next_step_handler_by_chat_id(chat_id, phone_number_processor)
def _to_target_audience(chat_id, language, include_keyboard=True): target_audience_msg = strings.get_string('campaign.target_audience', language) if include_keyboard: target_audience_keyboard = keyboards.get_keyboard('campaign.target_audience', language) bot.send_message(chat_id, target_audience_msg, reply_markup=target_audience_keyboard) else: bot.send_message(chat_id, target_audience_msg) bot.register_next_step_handler_by_chat_id(chat_id, target_audience_processor)
def _to_budget(chat_id, language, include_keyboard=True): budget_msg = strings.get_string('campaign.budget', language) if include_keyboard: budget_keyboard = keyboards.get_keyboard('campaign.budget', language) bot.send_message(chat_id, budget_msg, reply_markup=budget_keyboard) else: bot.send_message(chat_id, budget_msg) bot.register_next_step_handler_by_chat_id(chat_id, budget_processor)
def empty_message(message: telebot.types.Message): chat_id = message.chat.id user_id = message.from_user.id language = userservice.get_user_language(user_id) if userservice.is_user_registered(user_id): main_menu_message = strings.get_string('main_menu.choose_option', language) main_menu_keyboard = keyboards.get_keyboard('main_menu', language) telegram_bot.send_message(chat_id, main_menu_message, reply_markup=main_menu_keyboard)
def notify_ad_campaign(ad_campaign: AdCampaign): notify_chats = notifyservice.get_all_notify_chats() notify_message = strings.from_notify_order(ad_campaign) for chat in notify_chats: try: bot.send_message(chat.id, notify_message, parse_mode='Markdown') except ApiException: pass
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)
def error(): if message.text == '/start': registration.welcome(message) return 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)
def _to_the_address(chat_id, language): cart = userservice.get_user_cart(chat_id) total = _total_cart_sum(cart) cart_contains_message = strings.from_cart_items(cart, language, total) address_message = strings.get_string('order.address', language).format(cart_contains_message) address_keyboard = keyboards.get_keyboard('order.address', language) bot.send_message(chat_id, address_message, parse_mode='HTML', reply_markup=address_keyboard) bot.register_next_step_handler_by_chat_id(chat_id, address_processor)
def error(): if message.text == '/start': registration.welcome(message) return error_msg = strings.get_string('registration.request.welcome', language) telegram_bot.send_message(chat_id, error_msg) telegram_bot.register_next_step_handler_by_chat_id(chat_id, request_registration_name_handler, language=language)
def _to_the_phone_number(chat_id, language, user): phone_number_message = strings.get_string('order.phone_number', language) phone_number_keyboard = keyboards.from_user_phone_number( language, user.phone_number) bot.send_message(chat_id, phone_number_message, reply_markup=phone_number_keyboard, parse_mode='HTML') bot.register_next_step_handler_by_chat_id(chat_id, phone_number_processor)
def profile_handler(message: Message): chat_id = message.chat.id user_id = message.from_user.id language = userservice.get_user_language(user_id) current_user = userservice.get_user_by_id(user_id) msg = '<b>До бесплатного кофе: {}</b>'.format( (10 - (current_user.count_orders % 10)) - 1) telegram_bot.send_message(chat_id, text=msg, parse_mode='HTML') botutlis.to_main_menu(chat_id, 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)
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)
def catalog(message: Message): chat_id = message.chat.id user_id = message.from_user.id language = userservice.get_user_language(user_id) bot.send_chat_action(chat_id, 'typing') dishes_keyboard = keyboards.get_keyboard('catalog.dish_keyboard') dish_message = strings.get_string('catalog.dish_action_helper', language) bot.send_message(chat_id, dish_message, reply_markup=dishes_keyboard) bot.register_next_step_handler_by_chat_id(chat_id, count_processor)