|
2 | 2 | # Licensed under the MIT License.
|
3 | 3 |
|
4 | 4 | from typing import List
|
5 |
| -from botbuilder.core.turn_context import TurnContext |
| 5 | +from botbuilder.schema import ConversationParameters |
| 6 | +from botbuilder.core.turn_context import Activity, TurnContext |
6 | 7 | from botbuilder.schema.teams import (
|
7 | 8 | ChannelInfo,
|
8 | 9 | TeamDetails,
|
|
12 | 13 | from botframework.connector.aio import ConnectorClient
|
13 | 14 | from botframework.connector.teams.teams_connector_client import TeamsConnectorClient
|
14 | 15 |
|
15 |
| - |
16 | 16 | class TeamsInfo:
|
| 17 | + @staticmethod |
| 18 | + async def send_message_to_teams_channel( |
| 19 | + turn_context: TurnContext, activity: Activity, teams_channel_id: str |
| 20 | + ) -> tuple: |
| 21 | + if not turn_context: |
| 22 | + raise ValueError("The turn_context cannot be None") |
| 23 | + if not turn_context.activity: |
| 24 | + raise ValueError("The turn_context.activity cannot be None") |
| 25 | + if not teams_channel_id: |
| 26 | + raise ValueError("The teams_channel_id cannot be None or empty") |
| 27 | + |
| 28 | + old_ref = TurnContext.get_conversation_reference(turn_context.activity) |
| 29 | + conversation_parameters = ConversationParameters( |
| 30 | + is_group=True, |
| 31 | + channel_data={"channel": {"id": teams_channel_id}}, |
| 32 | + activity=activity, |
| 33 | + ) |
| 34 | + |
| 35 | + result = await turn_context.adapter.create_conversation( |
| 36 | + old_ref, TeamsInfo._create_conversation_callback, conversation_parameters |
| 37 | + ) |
| 38 | + return (result[0], result[1]) |
| 39 | + |
| 40 | + @staticmethod |
| 41 | + async def _create_conversation_callback(new_turn_context) -> tuple: |
| 42 | + new_activity_id = new_turn_context.activity.id |
| 43 | + conversation_reference = TurnContext.get_conversation_reference(new_turn_context.activity) |
| 44 | + return (conversation_reference, new_activity_id) |
| 45 | + |
17 | 46 | @staticmethod
|
18 | 47 | async def get_team_details(
|
19 | 48 | turn_context: TurnContext, team_id: str = ""
|
|
0 commit comments