コード例 #1
0
ファイル: controller.py プロジェクト: recluse27/ffb
    def get_basket(self, sender, **kwargs) -> List[Message]:
        provider = kwargs.get('provider')
        quick_replies_list = ['categories', 'payment', 'basket']
        quick_replies_instance = quick_replies(quick_replies_list,
                                               provider)

        order = BotOrder.find_one({"user_id": sender,
                                   "provider": provider})

        if order is None or not order.orders:
            return [Message(user_id=sender,
                            message_type=TEXT,
                            message_data='У вас нема продуктів у кошику.',
                            quick_replies=quick_replies_instance)]

        messages = []
        rearranged_products = transform(order.orders)
        for product_list in rearranged_products:
            messages.append(Message(user_id=sender,
                                    message_type=ATTACHMENT,
                                    message_data=generic_list_template(product_list, 'Видалити',
                                                                       **{'provider': provider,
                                                                          'type': 'remove_product'}),
                                    quick_replies=quick_replies_instance))
        return messages
コード例 #2
0
ファイル: controller.py プロジェクト: recluse27/ffb
    def get_cafe(self, sender, **kwargs) -> List[Message]:
        provider = kwargs.get('id')
        quick_replies_list = ['categories', 'payment', 'basket', 'about_cafe']
        quick_replies_instance = quick_replies(quick_replies_list,
                                               provider)

        kwargs['provider'] = provider
        adapter = self.adapters.get(provider)

        result = adapter.get_categories(**kwargs)
        rearranged_categories = transform(result)

        messages = [
            Message(user_id=sender,
                    message_type=TEXT,
                    message_data='Чудовий вибір!🙂 '
                                 'Щоб обрати категорію меню - натисніть на її назву.😉',
                    quick_replies=quick_replies_instance)
        ]
        for category_list in rearranged_categories:
            messages.append(Message(user_id=sender,
                                    message_type=ATTACHMENT,
                                    message_data=generic_list_template(category_list, **{'provider': provider,
                                                                                         'type': 'get_category'}),
                                    quick_replies=quick_replies_instance))
        return messages
コード例 #3
0
ファイル: controller.py プロジェクト: recluse27/ffb
    def get_category(self, sender, **kwargs) -> List[Message]:
        provider = kwargs.get('provider')
        adapter = self.adapters.get(provider)

        quick_replies_list = ['categories', 'payment', 'basket']
        quick_replies_instance = quick_replies(quick_replies_list,
                                               provider)

        result = adapter.get_products(**kwargs)
        if not result:
            return [Message(user_id=sender,
                            message_type=TEXT,
                            message_data="У цій категорії нема продуктів.",
                            quick_replies=quick_replies_instance)]

        rearranged_products = transform(result)

        messages = [
            Message(user_id=sender,
                    message_type=TEXT,
                    message_data='Щоб додати позицію до кошику 🛒  - натисніть клавішу "Додати"',
                    quick_replies=quick_replies_instance)
        ]
        for product_list in rearranged_products:
            messages.append(Message(user_id=sender,
                                    message_type=ATTACHMENT,
                                    message_data=generic_list_template(product_list, 'Додати', **{'provider': provider,
                                                                                                  'type': 'add_product'}),
                                    quick_replies=quick_replies_instance))
        return messages
コード例 #4
0
ファイル: controller.py プロジェクト: recluse27/ffb
    def get_cafes(self, sender, **kwargs) -> List[Message]:
        quick_replies_list = ['cafes']
        quick_replies_instance = quick_replies(quick_replies_list,
                                               None)
        result = rq.get(self.cafe_system_url + "bot/cafes/")

        cafes_list = json.loads(result.text).get("cafes")
        for cafe in cafes_list:
            cafe_model = Cafe(**cafe)
            adapter = GenericAdapter(cafe_model)
            self.adapters[cafe.get("provider_name")] = adapter

        cafes = [{'title': cafe_value.name,
                  'id': cafe_key,
                  'image_url': cafe_value.image_url} for cafe_key, cafe_value in self.adapters.items()]
        rearranged_cafes = transform(cafes)

        messages = [
            Message(user_id=sender,
                    message_type=TEXT,
                    message_data="Щоб обрати заклад - натисніть на його назву.",
                    quick_replies=quick_replies_instance),
        ]
        for cafe_list in rearranged_cafes:
            messages.append(Message(user_id=sender,
                                    message_type=ATTACHMENT,
                                    message_data=generic_list_template(cafe_list,
                                                                       **{'type': 'get_cafe'}),
                                    quick_replies=quick_replies_instance))
        return messages