Skip to content

Adding helper for starting thread in Teams #653

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

Merged
merged 14 commits into from
Feb 24, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

import aiohttp
from aiohttp.web_request import Request
from slack.web.client import WebClient
from slack.web.slack_response import SlackResponse

from botbuilder.schema import Activity
from botbuilder.adapters.slack import SlackAdapterOptions
from botbuilder.adapters.slack.slack_message import SlackMessage

from slack.web.client import WebClient
from slack.web.slack_response import SlackResponse

POST_MESSAGE_URL = "https://slack.com/api/chat.postMessage"
POST_EPHEMERAL_MESSAGE_URL = "https://slack.com/api/chat.postEphemeral"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from aiohttp.web_request import Request
from aiohttp.web_response import Response
from slack.web.classes.attachments import Attachment

from botbuilder.schema import (
Activity,
Expand All @@ -15,6 +14,8 @@
ActivityTypes,
)

from slack.web.classes.attachments import Attachment

from .slack_message import SlackMessage
from .slack_client import SlackClient
from .slack_event import SlackEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

from typing import Optional, List

from slack.web.classes.actions import Action

from botbuilder.adapters.slack.slack_message import SlackMessage

from slack.web.classes.actions import Action


class SlackPayload:
def __init__(self, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ async def create_conversation(
)
)
client = await self.create_connector_client(reference.service_url)

resource_response = await client.conversations.create_conversation(
parameters
)
# Mix in the tenant ID if specified. This is required for MS Teams.
if reference.conversation is not None and reference.conversation.tenant_id:
# Putting tenant_id in channel_data is a temporary while we wait for the Teams API to be updated
Expand All @@ -316,9 +318,6 @@ async def create_conversation(
# Permanent solution is to put tenant_id in parameters.tenant_id
parameters.tenant_id = reference.conversation.tenant_id

resource_response = await client.conversations.create_conversation(
parameters
)
request = TurnContext.apply_conversation_reference(
Activity(type=ActivityTypes.event, name="CreateConversation"),
reference,
Expand Down
38 changes: 36 additions & 2 deletions libraries/botbuilder-core/botbuilder/core/teams/teams_info.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from typing import List
from botbuilder.core.turn_context import TurnContext
from typing import List, Tuple
from botbuilder.schema import ConversationParameters, ConversationReference
from botbuilder.core.turn_context import Activity, TurnContext
from botbuilder.schema.teams import (
ChannelInfo,
TeamDetails,
Expand All @@ -14,6 +15,39 @@


class TeamsInfo:
@staticmethod
async def send_message_to_teams_channel(
turn_context: TurnContext, activity: Activity, teams_channel_id: str
) -> Tuple[ConversationReference, str]:
if not turn_context:
raise ValueError("The turn_context cannot be None")
if not turn_context.activity:
raise ValueError("The turn_context.activity cannot be None")
if not teams_channel_id:
raise ValueError("The teams_channel_id cannot be None or empty")

old_ref = TurnContext.get_conversation_reference(turn_context.activity)
conversation_parameters = ConversationParameters(
is_group=True,
channel_data={"channel": {"id": teams_channel_id}},
activity=activity,
)

result = await turn_context.adapter.create_conversation(
old_ref, TeamsInfo._create_conversation_callback, conversation_parameters
)
return (result[0], result[1])

@staticmethod
async def _create_conversation_callback(
new_turn_context,
) -> Tuple[ConversationReference, str]:
new_activity_id = new_turn_context.activity.id
conversation_reference = TurnContext.get_conversation_reference(
new_turn_context.activity
)
return (conversation_reference, new_activity_id)

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