def _create_dialog_skill_bot_activity(
            self, selected_option: str, turn_context: TurnContext) -> Activity:
        """
        Helper method to create the activity to be sent to the DialogSkillBot using selected type and values.
        """

        selected_option = selected_option.lower()
        # Note: in a real bot, the dialogArgs will be created dynamically based on the conversation
        # and what each action requires; here we hardcode the values to make things simpler.

        # Just forward the message activity to the skill with whatever the user said.
        if selected_option == self._skill_action_message.lower():
            # Note message activities also support input parameters but we are not using them in this example.
            return turn_context.activity

        activity = None

        # Send an event activity to the skill with "BookFlight" in the name.
        if selected_option == self._skill_action_book_flight.lower():
            activity = Activity(type=ActivityTypes.event)
            activity.name = self._skill_action_book_flight

        # Send an event activity to the skill with "BookFlight" in the name and some testing values.
        if (selected_option ==
                self._skill_action_book_flight_with_input_parameters.lower()):
            activity = Activity(type=ActivityTypes.event)
            activity.name = self._skill_action_book_flight
            activity.value = {"origin": "New York", "destination": "Seattle"}

        # Send an event activity to the skill with "GetWeather" in the name and some testing values.
        if selected_option == self._skill_action_get_weather.lower():
            activity = Activity(type=ActivityTypes.event)
            activity.name = self._skill_action_get_weather
            activity.value = {"latitude": 47.614891, "longitude": -122.195801}
            return activity

        if not activity:
            raise Exception(
                f"Unable to create dialogArgs for {selected_option}.")

        # We are manually creating the activity to send to the skill; ensure we add the ChannelData and Properties
        # from the original activity so the skill gets them.
        # Note: this is not necessary if we are just forwarding the current activity from context.
        activity.channel_data = turn_context.activity.channel_data
        activity.additional_properties = turn_context.activity.additional_properties

        return activity
Exemple #2
0
    async def event_to_activity(event: SlackEvent,
                                client: SlackClient) -> Activity:
        """
        Creates an activity based on the Slack event data.

        :param event: The data of the Slack event.
        :type event: :class:`SlackEvent`
        :param client: The Slack client.
        :type client: :class:`SlackClient`
        :return: An activity containing the event data.
        :rtype: :class:`botbuilder.schema.Activity`
        """

        if not event:
            raise Exception("slack event is required")

        activity = Activity(
            id=event.event_ts,
            channel_id="slack",
            conversation=ConversationAccount(
                id=event.channel if event.channel else event.channel_id,
                properties={}),
            from_property=ChannelAccount(
                id=event.bot_id if event.bot_id else event.user_id),
            recipient=ChannelAccount(id=None),
            channel_data=event,
            text=event.text,
            type=ActivityTypes.event,
        )

        if not activity.conversation.id:
            if event.item and event.item_channel:
                activity.conversation.id = event.item_channel
            else:
                activity.conversation.id = event.team

        activity.recipient.id = await client.get_bot_user_identity(
            activity=activity)

        if event.thread_ts:
            activity.conversation.properties["thread_ts"] = event.thread_ts

        if event.type == "message" and not event.subtype and not event.bot_id:
            if not event.subtype:
                activity.type = ActivityTypes.message
                activity.text = event.text

            activity.conversation.properties[
                "channel_type"] = event.channel_type
            activity.value = event
        else:
            activity.name = event.type
            activity.value = event

        return activity