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
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from typing import List
from botbuilder.schema import Activity
from botbuilder.schema.teams import (
NotificationInfo,
TeamsChannelData,
TeamInfo,
TeamsMeetingInfo,
OnBehalfOf,
)


Expand Down Expand Up @@ -84,3 +86,14 @@ def teams_get_meeting_info(activity: Activity) -> TeamsMeetingInfo:
return channel_data.meeting

return None


def teams_get_team_on_behalf_of(activity: Activity) -> List[OnBehalfOf]:
if not activity:
return None

if activity.channel_data:
channel_data = TeamsChannelData().deserialize(activity.channel_data)
return channel_data.on_behalf_of

return None
56 changes: 56 additions & 0 deletions libraries/botbuilder-core/tests/teams/test_teams_channel_data.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from uuid import uuid4
import aiounittest

from botbuilder.schema import Activity
from botbuilder.schema.teams import TeamsChannelData
from botbuilder.core.teams import teams_get_team_info
from botbuilder.schema.teams._models_py3 import (
ChannelInfo,
NotificationInfo,
OnBehalfOf,
TeamInfo,
TeamsChannelDataSettings,
TeamsMeetingInfo,
TenantInfo,
)


class TestTeamsChannelData(aiounittest.AsyncTestCase):
Expand All @@ -28,3 +38,49 @@ def test_teams_get_team_info(self):

# Assert
assert team_info.aad_group_id == "teamGroup123"

def test_teams_channel_data_inits(self):
# Arrange
channel = ChannelInfo(id="general", name="General")
event_type = "eventType"
team = TeamInfo(id="supportEngineers", name="Support Engineers")
notification = NotificationInfo(alert=True)
tenant = TenantInfo(id="uniqueTenantId")
meeting = TeamsMeetingInfo(id="BFSE Stand Up")
settings = TeamsChannelDataSettings(selected_channel=channel)
on_behalf_of = [
OnBehalfOf(
display_name="onBehalfOfTest",
item_id=0,
mention_type="person",
mri=str(uuid4()),
)
]

# Act
channel_data = TeamsChannelData(
channel=channel,
event_type=event_type,
team=team,
notification=notification,
tenant=tenant,
meeting=meeting,
settings=settings,
on_behalf_of=on_behalf_of,
)

# Assert
self.assertIsNotNone(channel_data)
self.assertIsInstance(channel_data, TeamsChannelData)
self.assertEqual(channel, channel_data.channel)
self.assertEqual(event_type, channel_data.event_type)
self.assertEqual(team, channel_data.team)
self.assertEqual(notification, channel_data.notification)
self.assertEqual(tenant, channel_data.tenant)
self.assertEqual(meeting, channel_data.meeting)
self.assertEqual(settings, channel_data.settings)
self.assertEqual(on_behalf_of, channel_data.on_behalf_of)
self.assertEqual(on_behalf_of[0].display_name, "onBehalfOfTest")
self.assertEqual(on_behalf_of[0].mention_type, "person")
self.assertIsNotNone(on_behalf_of[0].mri)
self.assertEqual(on_behalf_of[0].item_id, 0)
27 changes: 26 additions & 1 deletion libraries/botbuilder-core/tests/teams/test_teams_extension.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from uuid import uuid4
import aiounittest

from botbuilder.schema import Activity
Expand All @@ -11,7 +12,11 @@
teams_get_team_info,
teams_notify_user,
)
from botbuilder.core.teams.teams_activity_extensions import teams_get_meeting_info
from botbuilder.core.teams.teams_activity_extensions import (
teams_get_meeting_info,
teams_get_team_on_behalf_of,
)
from botbuilder.schema.teams._models_py3 import OnBehalfOf


class TestTeamsActivityHandler(aiounittest.AsyncTestCase):
Expand Down Expand Up @@ -190,3 +195,23 @@ def test_teams_meeting_info(self):

# Assert
assert meeting_id == "meeting123"

def test_teams_channel_data_existing_on_behalf_of(self):
# Arrange
on_behalf_of_list = [
OnBehalfOf(
display_name="onBehalfOfTest",
item_id=0,
mention_type="person",
mri=str(uuid4()),
)
]

activity = Activity(channel_data={"onBehalfOf": on_behalf_of_list})

# Act
on_behalf_of_list = teams_get_team_on_behalf_of(activity)

# Assert
self.assertEqual(1, len(on_behalf_of_list))
self.assertEqual("onBehalfOfTest", on_behalf_of_list[0].display_name)
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
from ._models_py3 import ConfigTaskResponse
from ._models_py3 import MeetingNotificationBase
from ._models_py3 import MeetingNotificationResponse
from ._models_py3 import OnBehalfOf

__all__ = [
"AppBasedLinkQuery",
Expand Down Expand Up @@ -177,4 +178,5 @@
"ConfigTaskResponse",
"MeetingNotificationBase",
"MeetingNotificationResponse",
"OnBehalfOf",
]
Original file line number Diff line number Diff line change
Expand Up @@ -2006,8 +2006,10 @@ 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
:param settings: Information about the about the settings in which the message was sent
:type settings: ~botframework.connector.teams.models.TeamsChannelDataSettings
:param on_behalf_of: The OnBehalfOf list for user attribution
:type on_behalf_of: list[~botframework.connector.teams.models.OnBehalfOf]
"""

_attribute_map = {
Expand All @@ -2018,6 +2020,7 @@ class TeamsChannelData(Model):
"tenant": {"key": "tenant", "type": "TenantInfo"},
"meeting": {"key": "meeting", "type": "TeamsMeetingInfo"},
"settings": {"key": "settings", "type": "TeamsChannelDataSettings"},
"on_behalf_of": {"key": "onBehalfOf", "type": "[OnBehalfOf]"},
}

def __init__(
Expand All @@ -2030,6 +2033,7 @@ def __init__(
tenant=None,
meeting=None,
settings: TeamsChannelDataSettings = None,
on_behalf_of: List["OnBehalfOf"] = None,
**kwargs
) -> None:
super(TeamsChannelData, self).__init__(**kwargs)
Expand All @@ -2041,6 +2045,7 @@ def __init__(
self.tenant = tenant
self.meeting = meeting
self.settings = settings
self.on_behalf_of = on_behalf_of if on_behalf_of is not None else []


class TenantInfo(Model):
Expand Down
Loading