예제 #1
0
    def append_choices(self, prompt: Activity, channel_id: str, choices: object, style: object, options : object = None ) -> Activity:
        # Get base prompt text (if any)
        text = prompt.text if prompt != None and not prompt.text == False else ''
        
        # Create temporary msg
        # TODO: fix once ChoiceFactory complete
        def inline() -> Activity:
            return ChoiceFactory.inline(choices, text, None, options)
        def list_style() -> Activity:
            return ChoiceFactory.list_style(choices, text, None, options)
        def suggested_action() -> Activity:
            return ChoiceFactory.suggested_action(choices, text)
        def hero_card() -> Activity:
            return ChoiceFactory.hero_card(choices, text)
        def list_style_none() -> Activity:
            activity = Activity()
            activity.text = text
            return activity
        def default() -> Activity:
            return ChoiceFactory.for_channel(channel_id, choices, text, None, options)
        switcher = {
            # ListStyle.inline
            1: inline,
            2: list_style,
            3: suggested_action,
            4: hero_card,
            5: list_style_none
            }
            
        msg = switcher.get(style, default)()

        # Update prompt with text, actions and attachments
        if not prompt:
            # clone the prompt the set in the options (note ActivityEx has Properties so this is the safest mechanism)
            prompt = copy.copy(prompt)

            prompt.text = msg.text

            if (msg.suggested_actions != None and msg.suggested_actions.actions != None
                and len(msg.suggested_actions.actions) > 0):
                prompt.suggested_actions = msg.suggested_actions

            if msg.attachments != None and len(msg.attachments) > 0:
                prompt.attachments = msg.attachments

            return prompt
        else:
            # TODO: Update to InputHints.ExpectingInput;
            msg.input_hint = None
            return msg
예제 #2
0
    def append_choices(
        self,
        prompt: Activity,
        channel_id: str,
        choices: List[Choice],
        style: ListStyle,
        options: ChoiceFactoryOptions = None,
    ) -> Activity:
        """
        Composes an output activity containing a set of choices.

        :param prompt: The prompt to append the user's choice to
        :type prompt:
        :param channel_id: Id of the channel the prompt is being sent to
        :type channel_id: str
        :param: choices: List of choices to append
        :type choices:  :class:`List`
        :param: style: Configured style for the list of choices
        :type style:  :class:`ListStyle`
        :param: options: Optional formatting options to use when presenting the choices
        :type style: :class:`ChoiceFactoryOptions`

        :return: A task representing the asynchronous operation

        .. remarks::
            If the task is successful, the result contains the updated activity.
            When overridden in a derived class, appends choices to the activity when the user
            is prompted for input. This is an helper function to compose an output activity
            containing a set of choices.

        """
        # Get base prompt text (if any)
        text = prompt.text if prompt is not None and prompt.text else ""

        # Create temporary msg
        # TODO: fix once ChoiceFactory complete
        def inline() -> Activity:
            return ChoiceFactory.inline(choices, text, None, options)

        def list_style() -> Activity:
            return ChoiceFactory.list_style(choices, text, None, options)

        def suggested_action() -> Activity:
            return ChoiceFactory.suggested_action(choices, text)

        def hero_card() -> Activity:
            return ChoiceFactory.hero_card(choices, text)

        def list_style_none() -> Activity:
            activity = Activity(type=ActivityTypes.message)
            activity.text = text
            return activity

        def default() -> Activity:
            return ChoiceFactory.for_channel(channel_id, choices, text, None,
                                             options)

        # Maps to values in ListStyle Enum
        switcher = {
            0: list_style_none,
            1: default,
            2: inline,
            3: list_style,
            4: suggested_action,
            5: hero_card,
        }

        msg = switcher.get(int(style.value), default)()

        # Update prompt with text, actions and attachments
        if prompt:
            # clone the prompt the set in the options (note ActivityEx has Properties so this is the safest mechanism)
            prompt = copy.copy(prompt)

            prompt.text = msg.text

            if (msg.suggested_actions is not None
                    and msg.suggested_actions.actions is not None
                    and msg.suggested_actions.actions):
                prompt.suggested_actions = msg.suggested_actions

            if msg.attachments:
                if prompt.attachments:
                    prompt.attachments.extend(msg.attachments)
                else:
                    prompt.attachments = msg.attachments

            return prompt

        # TODO: Update to InputHints.ExpectingInput;
        msg.input_hint = None
        return msg
예제 #3
0
    def append_choices(
        self,
        prompt: Activity,
        channel_id: str,
        choices: List[Choice],
        style: ListStyle,
        options: ChoiceFactoryOptions = None,
    ) -> Activity:
        """
        Helper function to compose an output activity containing a set of choices.

        Parameters:
        -----------
        prompt: The prompt to append the user's choice to.

        channel_id: ID of the channel the prompt is being sent to.

        choices: List of choices to append.

        style: Configured style for the list of choices.

        options: (Optional) options to configure the underlying `ChoiceFactory` call.
        """
        # Get base prompt text (if any)
        text = prompt.text if prompt is not None and prompt.text else ""

        # Create temporary msg
        # TODO: fix once ChoiceFactory complete
        def inline() -> Activity:
            return ChoiceFactory.inline(choices, text, None, options)

        def list_style() -> Activity:
            return ChoiceFactory.list_style(choices, text, None, options)

        def suggested_action() -> Activity:
            return ChoiceFactory.suggested_action(choices, text)

        def hero_card() -> Activity:
            return ChoiceFactory.hero_card(choices, text)

        def list_style_none() -> Activity:
            activity = Activity(type=ActivityTypes.message)
            activity.text = text
            return activity

        def default() -> Activity:
            return ChoiceFactory.for_channel(channel_id, choices, text, None,
                                             options)

        # Maps to values in ListStyle Enum
        switcher = {
            0: list_style_none,
            1: default,
            2: inline,
            3: list_style,
            4: suggested_action,
            5: hero_card,
        }

        msg = switcher.get(int(style.value), default)()

        # Update prompt with text, actions and attachments
        if not prompt:
            # clone the prompt the set in the options (note ActivityEx has Properties so this is the safest mechanism)
            prompt = copy.copy(prompt)

            prompt.text = msg.text

            if (msg.suggested_actions is not None
                    and msg.suggested_actions.actions is not None
                    and msg.suggested_actions.actions):
                prompt.suggested_actions = msg.suggested_actions

            if msg.attachments is not None and msg.attachments:
                prompt.attachments = msg.attachments

            return prompt

        # TODO: Update to InputHints.ExpectingInput;
        msg.input_hint = None
        return msg
예제 #4
0
    def append_choices(self,
                       prompt: Activity,
                       channel_id: str,
                       choices: object,
                       style: object,
                       options: object = None) -> Activity:
        """
        Helper function to compose an output activity containing a set of choices.

        Parameters:
        -----------
        
        prompt: The prompt to append the user's choice to.

        channel_id: ID of the channel the prompt is being sent to.

        choices: List of choices to append.

        style: Configured style for the list of choices.

        options: (Optional) options to configure the underlying `ChoiceFactory` call.
        """
        # Get base prompt text (if any)
        text = prompt.text if prompt != None and not prompt.text == False else ''

        # Create temporary msg
        # TODO: fix once ChoiceFactory complete
        def inline() -> Activity:
            return ChoiceFactory.inline(choices, text, None, options)

        def list_style() -> Activity:
            return ChoiceFactory.list_style(choices, text, None, options)

        def suggested_action() -> Activity:
            return ChoiceFactory.suggested_action(choices, text)

        def hero_card() -> Activity:
            return ChoiceFactory.hero_card(choices, text)

        def list_style_none() -> Activity:
            activity = Activity()
            activity.text = text
            return activity

        def default() -> Activity:
            return ChoiceFactory.for_channel(channel_id, choices, text, None,
                                             options)

        switcher = {
            # ListStyle.inline
            1: inline,
            2: list_style,
            3: suggested_action,
            4: hero_card,
            5: list_style_none
        }

        msg = switcher.get(style, default)()

        # Update prompt with text, actions and attachments
        if not prompt:
            # clone the prompt the set in the options (note ActivityEx has Properties so this is the safest mechanism)
            prompt = copy.copy(prompt)

            prompt.text = msg.text

            if (msg.suggested_actions != None
                    and msg.suggested_actions.actions != None
                    and len(msg.suggested_actions.actions) > 0):
                prompt.suggested_actions = msg.suggested_actions

            if msg.attachments != None and len(msg.attachments) > 0:
                prompt.attachments = msg.attachments

            return prompt
        else:
            # TODO: Update to InputHints.ExpectingInput;
            msg.input_hint = None
            return msg