async def on_teams_members_added_dispatch_activity( # pylint: disable=unused-argument self, members_added: [ChannelAccount], team_info: TeamInfo, turn_context: TurnContext, ): team_members = {} team_members_added = [] for member in members_added: if member.additional_properties != {}: team_members_added.append( deserializer_helper(TeamsChannelAccount, member) ) else: if team_members == {}: result = await TeamsInfo.get_members(turn_context) team_members = {i.id: i for i in result} if member.id in team_members: team_members_added.append(member) else: new_teams_channel_account = TeamsChannelAccount( id=member.id, name=member.name, aad_object_id=member.aad_object_id, role=member.role, ) team_members_added.append(new_teams_channel_account) return await self.on_teams_members_added_activity( team_members_added, team_info, turn_context )
async def on_teams_members_added_dispatch( # pylint: disable=unused-argument self, members_added: [ChannelAccount], team_info: TeamInfo, turn_context: TurnContext, ): team_members_added = [] for member in members_added: is_bot = (turn_context.activity.recipient is not None and member.id == turn_context.activity.recipient.id) if member.additional_properties != {} or is_bot: team_members_added.append( deserializer_helper(TeamsChannelAccount, member)) else: team_member = None try: team_member = await TeamsInfo.get_member( turn_context, member.id) team_members_added.append(team_member) except ErrorResponseException as ex: if (ex.error and ex.error.error and ex.error.error.code == "ConversationNotFound"): new_teams_channel_account = TeamsChannelAccount( id=member.id, name=member.name, aad_object_id=member.aad_object_id, role=member.role, ) team_members_added.append(new_teams_channel_account) else: raise ex return await self.on_teams_members_added(team_members_added, team_info, turn_context)
async def on_teams_members_removed_dispatch( # pylint: disable=unused-argument self, members_removed: [ChannelAccount], team_info: TeamInfo, turn_context: TurnContext, ): """ Override this in a derived class to provide logic for when members other than the bot leave the channel, such as your bot's good-bye logic. It will get the associated members with the provided accounts. :param members_removed: A list of all the accounts removed from the channel, as described by the conversation update activity. :param team_info: The team info object representing the team. :param turn_context: A context object for this turn. :returns: A task that represents the work queued to execute. """ teams_members_removed = [] for member in members_removed: new_account_json = member.serialize() if "additional_properties" in new_account_json: del new_account_json["additional_properties"] teams_members_removed.append( TeamsChannelAccount().deserialize(new_account_json)) return await self.on_teams_members_removed(teams_members_removed, team_info, turn_context)
async def on_teams_members_added_dispatch( # pylint: disable=unused-argument self, members_added: [ChannelAccount], team_info: TeamInfo, turn_context: TurnContext, ): """ Override this in a derived class to provide logic for when members other than the bot join the channel, such as your bot's welcome logic. It will get the associated members with the provided accounts. :param members_added: A list of all the accounts added to the channel, as described by the conversation update activity. :param team_info: The team info object representing the team. :param turn_context: A context object for this turn. :returns: A task that represents the work queued to execute. """ team_members_added = [] for member in members_added: is_bot = ( turn_context.activity.recipient is not None and member.id == turn_context.activity.recipient.id ) if member.additional_properties != {} or is_bot: team_members_added.append( deserializer_helper(TeamsChannelAccount, member) ) else: team_member = None try: team_member = await TeamsInfo.get_member(turn_context, member.id) team_members_added.append(team_member) except ErrorResponseException as ex: if ( ex.error and ex.error.error and ex.error.error.code == "ConversationNotFound" ): new_teams_channel_account = TeamsChannelAccount( id=member.id, name=member.name, aad_object_id=member.aad_object_id, role=member.role, ) team_members_added.append(new_teams_channel_account) else: raise ex return await self.on_teams_members_added( team_members_added, team_info, turn_context )
async def on_teams_members_removed_dispatch( # pylint: disable=unused-argument self, members_removed: [ChannelAccount], team_info: TeamInfo, turn_context: TurnContext, ): teams_members_removed = [] for member in members_removed: new_account_json = member.serialize() if "additional_properties" in new_account_json: del new_account_json["additional_properties"] teams_members_removed.append( TeamsChannelAccount().deserialize(new_account_json)) return await self.on_teams_members_removed(teams_members_removed, team_info, turn_context)
async def _get_members(connector_client: ConnectorClient, conversation_id: str) -> List[TeamsChannelAccount]: if connector_client is None: raise TypeError( "TeamsInfo._get_members.connector_client: cannot be None.") if not conversation_id: raise TypeError( "TeamsInfo._get_members.conversation_id: cannot be empty.") teams_members = [] members = await connector_client.conversations.get_conversation_members( conversation_id) for member in members: teams_members.append(TeamsChannelAccount().deserialize( dict(member.serialize(), **member.additional_properties))) return teams_members
async def _get_member(connector_client: ConnectorClient, conversation_id: str, member_id: str) -> TeamsChannelAccount: if connector_client is None: raise TypeError( "TeamsInfo._get_member.connector_client: cannot be None.") if not conversation_id: raise TypeError( "TeamsInfo._get_member.conversation_id: cannot be empty.") if not member_id: raise TypeError( "TeamsInfo._get_member.member_id: cannot be empty.") member: TeamsChannelAccount = await connector_client.conversations.get_conversation_member( conversation_id, member_id) return TeamsChannelAccount().deserialize( dict(member.serialize(), **member.additional_properties))
async def get_conversation_member( # pylint: disable=unused-argument self, conversation_id, member_id ): return TeamsChannelAccount(id=member_id)