def teams_get_channel_data(activity: Activity) -> TeamsChannelData:
    if not activity:
        return None

    if activity.channel_data:
        return TeamsChannelData().deserialize(activity.channel_data)

    return None
def teams_get_channel_id(activity: Activity) -> str:
    if not activity:
        return None

    if activity.channel_data:
        channel_data = TeamsChannelData().deserialize(activity.channel_data)
        return channel_data.channel.id if channel_data.channel else None

    return None
def teams_get_team_info(activity: Activity) -> TeamInfo:
    if not activity:
        return None

    if activity.channel_data:
        channel_data = TeamsChannelData().deserialize(activity.channel_data)
        return channel_data.team

    return None
    def test_teams_aad_group_id_deserialize(self):
        # Arrange
        raw_channel_data = {"team": {"aadGroupId": "teamGroup123"}}

        # Act
        channel_data = TeamsChannelData().deserialize(raw_channel_data)

        # Assert
        assert channel_data.team.aad_group_id == "teamGroup123"
def teams_get_meeting_info(activity: Activity) -> TeamsMeetingInfo:
    if not activity:
        return None

    if activity.channel_data:
        channel_data = TeamsChannelData().deserialize(activity.channel_data)
        return channel_data.meeting

    return None
Esempio n. 6
0
    async def test_send_message_to_teams(self):
        def create_conversation():
            pass

        adapter = SimpleAdapterWithCreateConversation(
            call_create_conversation=create_conversation)

        activity = Activity(
            type="message",
            text="test_send_message_to_teams_channel",
            channel_id=Channels.ms_teams,
            service_url="https://example.org",
            channel_data=TeamsChannelData(team=TeamInfo(id="team-id")),
        )
        turn_context = TurnContext(adapter, activity)
        handler = TestTeamsActivityHandler()
        await handler.on_turn(turn_context)
    async def on_teams_members_removed(self, teams_members_removed: [
        TeamsChannelAccount
    ], turn_context: TurnContext):
        if not turn_context:
            raise Exception("turn_context cannot be null")

        # TODO: Update once https://github.com/microsoft/botbuilder-python/pull/1069 is resolved
        channel_data = TeamsChannelData().deserialize(
            turn_context.activity.channel_data)
        if channel_data:
            team_info = channel_data.team
            location = (team_info.name if team_info else
                        turn_context.activity.conversation.conversation_type)
            hero_card = HeroCard(text=" ".join([
                f"{member.id} removed from {location}"
                for member in teams_members_removed
            ]))
            await turn_context.send_activity(
                MessageFactory.attachment(CardFactory.hero_card(hero_card)))
    async def on_conversation_update_activity(self, turn_context: TurnContext):

        if turn_context.activity.channel_id == Channels.ms_teams:
            channel_data = TeamsChannelData().deserialize(
                turn_context.activity.channel_data
            )
            if turn_context.activity.members_added:
                return await self.on_teams_members_added_dispatch_activity(
                    turn_context.activity.members_added, channel_data.team, turn_context
                )

            if turn_context.activity.members_removed:
                return await self.on_teams_members_removed_dispatch_activity(
                    turn_context.activity.members_removed,
                    channel_data.team,
                    turn_context,
                )

            if channel_data:
                if channel_data.event_type == "channelCreated":
                    return await self.on_teams_channel_created_activity(
                        ChannelInfo().deserialize(channel_data.channel),
                        channel_data.team,
                        turn_context,
                    )
                if channel_data.event_type == "channelDeleted":
                    return await self.on_teams_channel_deleted_activity(
                        channel_data.channel, channel_data.team, turn_context
                    )
                if channel_data.event_type == "channelRenamed":
                    return await self.on_teams_channel_renamed_activity(
                        channel_data.channel, channel_data.team, turn_context
                    )
                if channel_data.event_type == "teamRenamed":
                    return await self.on_teams_team_renamed_activity(
                        channel_data.team, turn_context
                    )
                return await super().on_conversation_update_activity(turn_context)

        return await super().on_conversation_update_activity(turn_context)
Esempio n. 9
0
 def get_team_id(turn_context: TurnContext):
     channel_data = TeamsChannelData(**turn_context.activity.channel_data)
     if channel_data.team:
         return channel_data.team["id"]
     return ""
    async def on_conversation_update_activity(self, turn_context: TurnContext):
        """
        Invoked when a conversation update activity is received from the channel.
        Conversation update activities are useful when it comes to responding to users
        being added to or removed from the channel.
        For example, a bot could respond to a user being added by greeting the user.

        :param turn_context: A context object for this turn.

        :returns: A task that represents the work queued to execute.

        .. remarks::
            In a derived class, override this method to add logic that applies
            to all conversation update activities.
        """
        if turn_context.activity.channel_id == Channels.ms_teams:
            channel_data = TeamsChannelData().deserialize(
                turn_context.activity.channel_data)
            if turn_context.activity.members_added:
                return await self.on_teams_members_added_dispatch(
                    turn_context.activity.members_added, channel_data.team,
                    turn_context)

            if turn_context.activity.members_removed:
                return await self.on_teams_members_removed_dispatch(
                    turn_context.activity.members_removed,
                    channel_data.team,
                    turn_context,
                )

            if channel_data:
                if channel_data.event_type == "channelCreated":
                    return await self.on_teams_channel_created(
                        ChannelInfo().deserialize(channel_data.channel),
                        channel_data.team,
                        turn_context,
                    )
                if channel_data.event_type == "channelDeleted":
                    return await self.on_teams_channel_deleted(
                        channel_data.channel, channel_data.team, turn_context)
                if channel_data.event_type == "channelRenamed":
                    return await self.on_teams_channel_renamed(
                        channel_data.channel, channel_data.team, turn_context)
                if channel_data.event_type == "teamArchived":
                    return await self.on_teams_team_archived(
                        channel_data.team, turn_context)
                if channel_data.event_type == "teamDeleted":
                    return await self.on_teams_team_deleted(
                        channel_data.team, turn_context)
                if channel_data.event_type == "teamHardDeleted":
                    return await self.on_teams_team_hard_deleted(
                        channel_data.team, turn_context)
                if channel_data.event_type == "channelRestored":
                    return await self.on_teams_channel_restored(
                        channel_data.channel, channel_data.team, turn_context)
                if channel_data.event_type == "teamRenamed":
                    return await self.on_teams_team_renamed(
                        channel_data.team, turn_context)
                if channel_data.event_type == "teamRestored":
                    return await self.on_teams_team_restored(
                        channel_data.team, turn_context)
                if channel_data.event_type == "teamUnarchived":
                    return await self.on_teams_team_unarchived(
                        channel_data.team, turn_context)

        return await super().on_conversation_update_activity(turn_context)