Skip to content

Commit 1617885

Browse files
authored
Port: TeamsChannelData need OnBehalfOf [#6609] (#2175)
* Adds the OnBehalfOf property to send messages via bots on behalf of another user in Teams. * black issue fix * Using List from typing
1 parent 0f2cb2a commit 1617885

File tree

5 files changed

+104
-3
lines changed

5 files changed

+104
-3
lines changed

libraries/botbuilder-core/botbuilder/core/teams/teams_activity_extensions.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4+
from typing import List
45
from botbuilder.schema import Activity
56
from botbuilder.schema.teams import (
67
NotificationInfo,
78
TeamsChannelData,
89
TeamInfo,
910
TeamsMeetingInfo,
11+
OnBehalfOf,
1012
)
1113

1214

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

8688
return None
89+
90+
91+
def teams_get_team_on_behalf_of(activity: Activity) -> List[OnBehalfOf]:
92+
if not activity:
93+
return None
94+
95+
if activity.channel_data:
96+
channel_data = TeamsChannelData().deserialize(activity.channel_data)
97+
return channel_data.on_behalf_of
98+
99+
return None

libraries/botbuilder-core/tests/teams/test_teams_channel_data.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4+
from uuid import uuid4
45
import aiounittest
56

67
from botbuilder.schema import Activity
78
from botbuilder.schema.teams import TeamsChannelData
89
from botbuilder.core.teams import teams_get_team_info
10+
from botbuilder.schema.teams._models_py3 import (
11+
ChannelInfo,
12+
NotificationInfo,
13+
OnBehalfOf,
14+
TeamInfo,
15+
TeamsChannelDataSettings,
16+
TeamsMeetingInfo,
17+
TenantInfo,
18+
)
919

1020

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

2939
# Assert
3040
assert team_info.aad_group_id == "teamGroup123"
41+
42+
def test_teams_channel_data_inits(self):
43+
# Arrange
44+
channel = ChannelInfo(id="general", name="General")
45+
event_type = "eventType"
46+
team = TeamInfo(id="supportEngineers", name="Support Engineers")
47+
notification = NotificationInfo(alert=True)
48+
tenant = TenantInfo(id="uniqueTenantId")
49+
meeting = TeamsMeetingInfo(id="BFSE Stand Up")
50+
settings = TeamsChannelDataSettings(selected_channel=channel)
51+
on_behalf_of = [
52+
OnBehalfOf(
53+
display_name="onBehalfOfTest",
54+
item_id=0,
55+
mention_type="person",
56+
mri=str(uuid4()),
57+
)
58+
]
59+
60+
# Act
61+
channel_data = TeamsChannelData(
62+
channel=channel,
63+
event_type=event_type,
64+
team=team,
65+
notification=notification,
66+
tenant=tenant,
67+
meeting=meeting,
68+
settings=settings,
69+
on_behalf_of=on_behalf_of,
70+
)
71+
72+
# Assert
73+
self.assertIsNotNone(channel_data)
74+
self.assertIsInstance(channel_data, TeamsChannelData)
75+
self.assertEqual(channel, channel_data.channel)
76+
self.assertEqual(event_type, channel_data.event_type)
77+
self.assertEqual(team, channel_data.team)
78+
self.assertEqual(notification, channel_data.notification)
79+
self.assertEqual(tenant, channel_data.tenant)
80+
self.assertEqual(meeting, channel_data.meeting)
81+
self.assertEqual(settings, channel_data.settings)
82+
self.assertEqual(on_behalf_of, channel_data.on_behalf_of)
83+
self.assertEqual(on_behalf_of[0].display_name, "onBehalfOfTest")
84+
self.assertEqual(on_behalf_of[0].mention_type, "person")
85+
self.assertIsNotNone(on_behalf_of[0].mri)
86+
self.assertEqual(on_behalf_of[0].item_id, 0)

libraries/botbuilder-core/tests/teams/test_teams_extension.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4+
from uuid import uuid4
45
import aiounittest
56

67
from botbuilder.schema import Activity
@@ -11,7 +12,11 @@
1112
teams_get_team_info,
1213
teams_notify_user,
1314
)
14-
from botbuilder.core.teams.teams_activity_extensions import teams_get_meeting_info
15+
from botbuilder.core.teams.teams_activity_extensions import (
16+
teams_get_meeting_info,
17+
teams_get_team_on_behalf_of,
18+
)
19+
from botbuilder.schema.teams._models_py3 import OnBehalfOf
1520

1621

1722
class TestTeamsActivityHandler(aiounittest.AsyncTestCase):
@@ -190,3 +195,23 @@ def test_teams_meeting_info(self):
190195

191196
# Assert
192197
assert meeting_id == "meeting123"
198+
199+
def test_teams_channel_data_existing_on_behalf_of(self):
200+
# Arrange
201+
on_behalf_of_list = [
202+
OnBehalfOf(
203+
display_name="onBehalfOfTest",
204+
item_id=0,
205+
mention_type="person",
206+
mri=str(uuid4()),
207+
)
208+
]
209+
210+
activity = Activity(channel_data={"onBehalfOf": on_behalf_of_list})
211+
212+
# Act
213+
on_behalf_of_list = teams_get_team_on_behalf_of(activity)
214+
215+
# Assert
216+
self.assertEqual(1, len(on_behalf_of_list))
217+
self.assertEqual("onBehalfOfTest", on_behalf_of_list[0].display_name)

libraries/botbuilder-schema/botbuilder/schema/teams/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
from ._models_py3 import ConfigTaskResponse
8989
from ._models_py3 import MeetingNotificationBase
9090
from ._models_py3 import MeetingNotificationResponse
91+
from ._models_py3 import OnBehalfOf
9192

9293
__all__ = [
9394
"AppBasedLinkQuery",
@@ -177,4 +178,5 @@
177178
"ConfigTaskResponse",
178179
"MeetingNotificationBase",
179180
"MeetingNotificationResponse",
181+
"OnBehalfOf",
180182
]

libraries/botbuilder-schema/botbuilder/schema/teams/_models_py3.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,8 +2006,10 @@ class TeamsChannelData(Model):
20062006
:type tenant: ~botframework.connector.teams.models.TenantInfo
20072007
:param meeting: Information about the meeting in which the message was sent
20082008
:type meeting: ~botframework.connector.teams.models.TeamsMeetingInfo
2009-
:param meeting: Information about the about the settings in which the message was sent
2010-
:type meeting: ~botframework.connector.teams.models.TeamsChannelDataSettings
2009+
:param settings: Information about the about the settings in which the message was sent
2010+
:type settings: ~botframework.connector.teams.models.TeamsChannelDataSettings
2011+
:param on_behalf_of: The OnBehalfOf list for user attribution
2012+
:type on_behalf_of: list[~botframework.connector.teams.models.OnBehalfOf]
20112013
"""
20122014

20132015
_attribute_map = {
@@ -2018,6 +2020,7 @@ class TeamsChannelData(Model):
20182020
"tenant": {"key": "tenant", "type": "TenantInfo"},
20192021
"meeting": {"key": "meeting", "type": "TeamsMeetingInfo"},
20202022
"settings": {"key": "settings", "type": "TeamsChannelDataSettings"},
2023+
"on_behalf_of": {"key": "onBehalfOf", "type": "[OnBehalfOf]"},
20212024
}
20222025

20232026
def __init__(
@@ -2030,6 +2033,7 @@ def __init__(
20302033
tenant=None,
20312034
meeting=None,
20322035
settings: TeamsChannelDataSettings = None,
2036+
on_behalf_of: List["OnBehalfOf"] = None,
20332037
**kwargs
20342038
) -> None:
20352039
super(TeamsChannelData, self).__init__(**kwargs)
@@ -2041,6 +2045,7 @@ def __init__(
20412045
self.tenant = tenant
20422046
self.meeting = meeting
20432047
self.settings = settings
2048+
self.on_behalf_of = on_behalf_of if on_behalf_of is not None else []
20442049

20452050

20462051
class TenantInfo(Model):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy