Skip to content
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
2 changes: 2 additions & 0 deletions libraries/botbuilder-core/botbuilder/core/teams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .teams_info import TeamsInfo
from .teams_activity_extensions import (
teams_get_channel_id,
teams_get_selected_channel_id,
teams_get_team_info,
teams_notify_user,
)
Expand All @@ -19,6 +20,7 @@
"TeamsInfo",
"TeamsSSOTokenExchangeMiddleware",
"teams_get_channel_id",
"teams_get_selected_channel_id",
"teams_get_team_info",
"teams_notify_user",
]
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ def teams_get_channel_id(activity: Activity) -> str:
return None


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

if activity.channel_data:
channel_data = TeamsChannelData().deserialize(activity.channel_data)
return (
channel_data.settings.selected_channel.id
if channel_data
and channel_data.settings
and channel_data.settings.selected_channel
else None
)

return None


def teams_get_team_info(activity: Activity) -> TeamInfo:
if not activity:
return None
Expand Down
30 changes: 30 additions & 0 deletions libraries/botbuilder-core/tests/teams/test_teams_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from botbuilder.schema.teams import TeamInfo
from botbuilder.core.teams import (
teams_get_channel_id,
teams_get_selected_channel_id,
teams_get_team_info,
teams_notify_user,
)
Expand All @@ -26,6 +27,35 @@ def test_teams_get_channel_id(self):
# Assert
assert result == "id123"

def test_teams_get_selected_channel_id(self):
# Arrange
activity = Activity(
channel_data={
"channel": {"id": "id123", "name": "channel_name"},
"settings": {
"selectedChannel": {"id": "id12345", "name": "channel_name"}
},
}
)

# Act
result = teams_get_selected_channel_id(activity)

# Assert
assert result == "id12345"

def test_teams_get_selected_channel_id_with_no_selected_channel(self):
# Arrange
activity = Activity(
channel_data={"channel": {"id": "id123", "name": "channel_name"}}
)

# Act
result = teams_get_selected_channel_id(activity)

# Assert
assert result is None

def test_teams_get_channel_id_with_no_channel(self):
# Arrange
activity = Activity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
from ._models_py3 import TeamDetails
from ._models_py3 import TeamInfo
from ._models_py3 import TeamsChannelAccount
from ._models_py3 import TeamsChannelDataSettings
from ._models_py3 import TeamsChannelData
from ._models_py3 import TeamsPagedMembersResult
from ._models_py3 import TenantInfo
Expand Down Expand Up @@ -145,6 +146,7 @@
"TeamDetails",
"TeamInfo",
"TeamsChannelAccount",
"TeamsChannelDataSettings",
"TeamsChannelData",
"TeamsPagedMembersResult",
"TenantInfo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,23 @@ class ChannelInfo(Model):
:type id: str
:param name: Name of the channel
:type name: str
:param type: The channel type
:type type: str
"""

_attribute_map = {
"id": {"key": "id", "type": "str"},
"name": {"key": "name", "type": "str"},
"type": {"key": "type", "type": "str"},
}

def __init__(self, *, id: str = None, name: str = None, **kwargs) -> None:
def __init__(
self, *, id: str = None, name: str = None, type: str = None, **kwargs
) -> None:
super(ChannelInfo, self).__init__(**kwargs)
self.id = id
self.name = name
self.type = type


class CacheInfo(Model):
Expand Down Expand Up @@ -1820,6 +1826,8 @@ class TeamDetails(Model):
:type channel_count: int
:param member_count: The count of members in the team.
:type member_count: int
:param type: The team type
:type type: str
"""

_attribute_map = {
Expand All @@ -1828,6 +1836,7 @@ class TeamDetails(Model):
"aad_group_id": {"key": "aadGroupId", "type": "str"},
"channel_count": {"key": "channelCount", "type": "int"},
"member_count": {"key": "memberCount", "type": "int"},
"type": {"key": "type", "type": "str"},
}

def __init__(
Expand All @@ -1838,6 +1847,7 @@ def __init__(
aad_group_id: str = None,
member_count: int = None,
channel_count: int = None,
type: str = None,
**kwargs
) -> None:
super(TeamDetails, self).__init__(**kwargs)
Expand All @@ -1846,6 +1856,7 @@ def __init__(
self.aad_group_id = aad_group_id
self.channel_count = channel_count
self.member_count = member_count
self.type = type


class TeamInfo(Model):
Expand Down Expand Up @@ -1958,6 +1969,26 @@ def __init__(
self.members = members


class TeamsChannelDataSettings(Model):
"""
Represents the settings information for a Teams channel data.

:param selected_channel: Information about the selected Teams channel.
:type selected_channel: ~botframework.connector.teams.models.ChannelInfo
:param additional_properties: Gets or sets properties that are not otherwise defined by the
type but that might appear in the REST JSON object.
:type additional_properties: object
"""

_attribute_map = {
"selected_channel": {"key": "selectedChannel", "type": "ChannelInfo"},
}

def __init__(self, *, selected_channel=None, **kwargs) -> None:
super(TeamsChannelDataSettings, self).__init__(**kwargs)
self.selected_channel = selected_channel


class TeamsChannelData(Model):
"""Channel data specific to messages received in Microsoft Teams.

Expand All @@ -1974,6 +2005,8 @@ class TeamsChannelData(Model):
:type tenant: ~botframework.connector.teams.models.TenantInfo
:param meeting: Information about the meeting in which the message was sent
:type meeting: ~botframework.connector.teams.models.TeamsMeetingInfo
:param meeting: Information about the about the settings in which the message was sent
:type meeting: ~botframework.connector.teams.models.TeamsChannelDataSettings
"""

_attribute_map = {
Expand All @@ -1983,6 +2016,7 @@ class TeamsChannelData(Model):
"notification": {"key": "notification", "type": "NotificationInfo"},
"tenant": {"key": "tenant", "type": "TenantInfo"},
"meeting": {"key": "meeting", "type": "TeamsMeetingInfo"},
"settings": {"key": "settings", "type": "TeamsChannelDataSettings"},
}

def __init__(
Expand All @@ -1994,6 +2028,7 @@ def __init__(
notification=None,
tenant=None,
meeting=None,
settings: TeamsChannelDataSettings = None,
**kwargs
) -> None:
super(TeamsChannelData, self).__init__(**kwargs)
Expand All @@ -2004,6 +2039,7 @@ def __init__(
self.notification = notification
self.tenant = tenant
self.meeting = meeting
self.settings = settings


class TenantInfo(Model):
Expand Down
Loading