def __process_carousel_item(self, section_item):

        media_type = MediaType.get_value("IMAGE")
        image_url = section_item.get("ImageUrl", "")
        image_url = AnaHelper.verb_replacer(text=image_url, state=self.state)
        image_url = furl(image_url).url

        title = section_item.get("Title", "")
        title = AnaHelper.verb_replacer(text=title, state=self.state)
        description = section_item.get("Caption", "")
        description = AnaHelper.verb_replacer(text=description,
                                              state=self.state)

        media_content = Media(type=media_type, url=image_url).trim()
        buttons = section_item.get("Buttons", [])
        buttons = AnaHelper.process_repeatable(buttons, self.state)
        options = []
        options = [
            self.__process_carousel_button(button) for button in buttons
        ]

        item_element = Item(title=title,
                            desc=description,
                            media=media_content,
                            options=options).trim()

        return item_element
Example #2
0
    def process(self, buttons):

        logger.info(f"btns before: {len(buttons)}")
        buttons = AnaHelper.process_repeatable(buttons, self.state)
        logger.info(f"btns after: {len(buttons)}")
        click_elements = [
            button for button in buttons
            if button["ButtonType"] in self.click_inputs
        ]
        text_elements = [
            button for button in buttons
            if button["ButtonType"] in self.text_inputs
        ]

        messages_data = []

        if click_elements != [] and text_elements == []:
            messages_data = self.__process_click_inputs(click_elements,
                                                        mandatory=1)
        elif click_elements != [] and text_elements != []:
            messages_data = self.__process_click_inputs(click_elements,
                                                        mandatory=0)
        elif click_elements == [] and text_elements != []:
            messages_data = self.__process_text_inputs(text_elements)

        return messages_data
Example #3
0
    def _extract_button_elements(cls, data, state):

        node_buttons = data.get("Buttons", [])
        node_buttons = AnaHelper.process_repeatable(node_buttons, state)
        sections = data.get("Sections", [])
        all_section_buttons = []

        for section in sections:
            if section["SectionType"] == "Carousel":
                carousel_items = section["Items"]
                carousel_items = AnaHelper.process_repeatable(
                    carousel_items, state, True)
                for car_item in carousel_items:
                    carousel_buttons = car_item.get("Buttons", [])
                    carousel_buttons = AnaHelper.process_repeatable(
                        carousel_buttons, state)
                    all_section_buttons = all_section_buttons + carousel_buttons
        return node_buttons + all_section_buttons
    def __carousel_processor(self, data):

        message_type = MessageType.get_value("CAROUSEL")
        section_items = data.get("Items", [])
        section_items = AnaHelper.process_repeatable(section_items, self.state,
                                                     True)
        item_elements = []
        item_elements = [
            self.__process_carousel_item(item) for item in section_items
        ]

        message_content = MessageContent(items=item_elements,
                                         mandatory=1).trim()
        message_data = MessageData(type=message_type,
                                   content=message_content).trim()

        return message_data