Ejemplo n.º 1
0
    def __media_processor(self, data):

        message_type = MessageType.get_value("SIMPLE")
        section_type = data.get("SectionType")
        if section_type in ["Image", "Gif"]:
            media_type = MediaType.get_value("IMAGE")
        elif section_type == "Video":
            media_type = MediaType.get_value("VIDEO")

        url = data.get("Url", "")
        url = AnaHelper.verb_replacer(text=url, state=self.state)
        url = furl(url).url
        preview_url = data.get("PreviewUrl", "")
        preview_url = AnaHelper.verb_replacer(text=preview_url,
                                              state=self.state)
        preview_url = furl(preview_url).url
        text = data.get("Title", "")
        text = AnaHelper.verb_replacer(text=text, state=self.state)
        media_content = Media(type=media_type, url=url,
                              previewUrl=preview_url).trim()
        message_content = MessageContent(text=text,
                                         media=media_content,
                                         mandatory=1).trim()
        message_data = MessageData(type=message_type,
                                   content=message_content).trim()

        return message_data
Ejemplo n.º 2
0
    def __construct_user_messages(cls, input_type, data):
        messages_data = []
        if input_type == "TEXT":
            message_type = MessageType.get_value("SIMPLE")
            text = data.get("val", "")
            message_content = MessageContent(text=text, mandatory=1).trim()
            message_data = MessageData(type=message_type,
                                       content=message_content).trim()
        else:
            logger.error(f"Unsupported input_type for agent {input_type}")

        messages_data.append(message_data)
        return messages_data
Ejemplo n.º 3
0
    def __text_processor(self, data):

        message_type = MessageType.get_value("SIMPLE")
        section_type = data.get("SectionType")
        if section_type == "Text":
            text = data.get("Text", "")
        elif section_type in ["EmbeddedHtml", "Link"]:
            text = data.get("Url", "")
        text = AnaHelper.verb_replacer(text=text, state=self.state)
        message_content = MessageContent(text=text, mandatory=1).trim()
        message_data = MessageData(type=message_type,
                                   content=message_content).trim()

        return message_data
Ejemplo n.º 4
0
    def __carousel_processor(self, data):

        message_type = MessageType.get_value("CAROUSEL")
        section_items = data.get("Items", [])

        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
Ejemplo n.º 5
0
    def get_agent_connected_messages():
        messages_data = []

        message_type = MessageType.get_value("INPUT")
        input_type = InputType.get_value("TEXT")
        input_attr = TextInput(placeHolder="Talk to our Agent").trim()

        content = MessageContent(
            inputType=input_type,
            textInputAttr=input_attr,
            mandatory=1,
        ).trim()
        input_message_data = MessageData(type=message_type,
                                         content=content).trim()

        messages_data.append(input_message_data)
        return messages_data
Ejemplo n.º 6
0
    def __process_input_button(self, button):

        button_type = button.get("ButtonType")

        if button_type == "GetItemFromSource":
            message_data = self.__process_getitem_button(button)
            return message_data

        message_type = ""
        input_type = ""
        input_attr = None
        content = None

        message_type = MessageType.get_value("INPUT")
        placeholder_text = button.get("PlaceholderText", "")
        placeholder_text = AnaHelper.verb_replacer(text=placeholder_text,
                                                   state=self.state)
        input_attr = TextInput(placeHolder=placeholder_text).trim()

        button_type_map = config["button_map"]

        elem_type = button_type_map.get(button_type)
        if elem_type is None:
            logger.warning(f"Undefined Input Type {button_type}")

        type_of_input = elem_type["input_type"]
        type_of_media = elem_type["media_type"]

        input_type = InputType.get_value(type_of_input)
        media_type = MediaType.get_value(type_of_media)

        content = MessageContent(
            inputType=input_type,
            mediaType=media_type,
            textInputAttr=input_attr,
            mandatory=1,
        ).trim()
        message_data = MessageData(type=message_type, content=content).trim()

        return message_data
Ejemplo n.º 7
0
    def __process_click_inputs(self, data, mandatory):

        button_heading = None
        elem_message_data = []
        elem_options = []

        message_type = MessageType.get_value("INPUT")
        input_type = InputType.get_value("OPTIONS")

        button_heading = "Choose an option"
        elem_options = [self.__process_click_button(button) for button in data]

        if elem_options != []:
            message_content = MessageContent(inputType=input_type,
                                             mandatory=mandatory,
                                             options=elem_options,
                                             text=button_heading).trim()
            message_data = MessageData(type=message_type,
                                       content=message_content).trim()
            elem_message_data.append(message_data)

        return elem_message_data
Ejemplo n.º 8
0
    def __process_getitem_button(self, data):

        source = data.get("ItemsSource")
        url = data.get("Url")
        values = list()
        if source:
            source = AnaHelper.verb_replacer(text=source, state=self.state)
            values = list(
                map(
                    lambda x: ListItem(text=x.split(":")[0],
                                       value=x.split(":")[1]).trim(),
                    source.split(",")))
        elif url:
            url = AnaHelper.verb_replacer(text=url, state=self.state)
            items_from_url = requests.get(url).json()
            values = []
            for key, value in items_from_url.items():
                values.append({'text': key, 'value': value})

        button_text = data.get("ButtonName")
        button_text = AnaHelper.verb_replacer(text=button_text,
                                              state=self.state)

        message_type = MessageType.get_value("INPUT")
        input_type = InputType.get_value("LIST")
        is_multiple = 1 if data.get("AllowMultiple") else 0

        content = MessageContent(inputType=input_type,
                                 text=button_text,
                                 multiple=is_multiple,
                                 mandatory=1,
                                 values=values).trim()

        message_data = MessageData(type=message_type, content=content).trim()

        return message_data
Ejemplo n.º 9
0
    def get_simple_text(text):
        message_type = MessageType.get_value("SIMPLE")
        content = MessageContent(text=text).trim()
        data = MessageData(type=message_type, content=content).trim()

        return data