Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port: Implementation of Teams batch APIs (#6655) #2180

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions libraries/botbuilder-core/botbuilder/core/teams/teams_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
TeamsMeetingParticipant,
MeetingNotificationBase,
MeetingNotificationResponse,
BatchFailedEntriesResponse,
BatchOperationState,
TeamMember,
)


Expand Down Expand Up @@ -137,6 +140,111 @@ async def _create_conversation_callback(
)
return (conversation_reference, new_activity_id)

@staticmethod
async def send_message_to_list_of_users(
turn_context: TurnContext,
activity: Activity,
teams_members: List["TeamMember"],
tenant_id: str,
) -> str:
"""Sends a message to the provided list of Teams members."""
if activity is None:
raise ValueError("activity is required.")
if not teams_members:
raise ValueError("teamsMembers is required.")
if not tenant_id:
raise ValueError("tenantId is required.")

connector_client = await TeamsInfo.get_teams_connector_client(turn_context)
return await connector_client.teams.send_message_to_list_of_users(
activity, teams_members, tenant_id
)

@staticmethod
async def send_message_to_all_users_in_tenant(
turn_context: TurnContext, activity: Activity, tenant_id: str
) -> str:
"""Sends a message to all the users in a tenant."""
if activity is None:
raise ValueError("activity is required.")
if not tenant_id:
raise ValueError("tenantId is required.")

connector_client = await TeamsInfo.get_teams_connector_client(turn_context)
return await connector_client.teams.send_message_to_all_users_in_tenant(
activity, tenant_id
)

@staticmethod
async def send_message_to_all_users_in_team(
turn_context: TurnContext, activity: Activity, team_id: str, tenant_id: str
) -> str:
"""Sends a message to all the users in a team."""
if activity is None:
raise ValueError("activity is required.")
if not team_id:
raise ValueError("teamId is required.")
if not tenant_id:
raise ValueError("tenantId is required.")

connector_client = await TeamsInfo.get_teams_connector_client(turn_context)
return await connector_client.teams.send_message_to_all_users_in_team(
activity, team_id, tenant_id
)

@staticmethod
async def send_message_to_list_of_channels(
turn_context: TurnContext,
activity: Activity,
channels_members: List["TeamMember"],
tenant_id: str,
) -> str:
"""Sends a message to the provided list of Teams channels."""
if activity is None:
raise ValueError("activity is required.")
if not channels_members:
raise ValueError("channelsMembers is required.")
if not tenant_id:
raise ValueError("tenantId is required.")

connector_client = await TeamsInfo.get_teams_connector_client(turn_context)
return await connector_client.teams.send_message_to_list_of_channels(
activity, channels_members, tenant_id
)

@staticmethod
async def get_operation_state(
turn_context: TurnContext, operation_id: str
) -> BatchOperationState:
"""Gets the state of an operation."""
if not operation_id:
raise ValueError("operationId is required.")

connector_client = await TeamsInfo.get_teams_connector_client(turn_context)
return await connector_client.teams.get_operation_state(operation_id)

@staticmethod
async def get_paged_failed_entries(
turn_context: TurnContext, operation_id: str, continuation_token: str = None
) -> BatchFailedEntriesResponse:
"""Gets the failed entries of a batch operation."""
if not operation_id:
raise ValueError("operationId is required.")

connector_client = await TeamsInfo.get_teams_connector_client(turn_context)
return await connector_client.teams.get_paged_failed_entries(
operation_id, continuation_token
)

@staticmethod
async def cancel_operation(turn_context: TurnContext, operation_id: str) -> None:
"""Cancels a batch operation by its id."""
if not operation_id:
raise ValueError("operationId is required.")

connector_client = await TeamsInfo.get_teams_connector_client(turn_context)
await connector_client.teams.cancel_operation(operation_id)

@staticmethod
async def get_team_details(
turn_context: TurnContext, team_id: str = ""
Expand Down
Loading
Loading