Esempio n. 1
0
 def __convert_to_user_message(cls, data):
     events = data.get("events")
     messages_data = []
     if events is None:
         type_of_input = data["content"]["inputType"]
         input_type = InputType.get_name(type_of_input)
         input_data = data["content"]["input"]
         messages_data = cls.__construct_user_messages(
             input_type=input_type, data=input_data)
     else:
         pass
     return messages_data
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
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