Skip to content

Commit 04a6175

Browse files
port: [#4463][#6596] TeamsChannelData need OnBehalfOf (#4474)
* add onBehalfOf property to Teams channel * fix code requirements --------- Co-authored-by: JhontSouth <jhonatan.sandoval@southworks.com>
1 parent c2abd7d commit 04a6175

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

libraries/botbuilder/etc/botbuilder.api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { MicrosoftAppCredentials } from 'botframework-connector';
5151
import { Middleware } from 'botbuilder-core';
5252
import { NodeWebSocketFactoryBase } from 'botframework-streaming';
5353
import { O365ConnectorCardActionQuery } from 'botbuilder-core';
54+
import { OnBehalfOf } from 'botbuilder-core';
5455
import { PagedMembersResult } from 'botbuilder-core';
5556
import { PagedResult } from 'botbuilder-core';
5657
import { ReadReceiptInfo } from 'botframework-connector';
@@ -441,6 +442,9 @@ export function teamsGetTeamInfo(activity: Activity): TeamInfo | null;
441442
// @public
442443
export function teamsGetTeamMeetingInfo(activity: Activity): TeamsMeetingInfo | null;
443444

445+
// @public (undocumented)
446+
export function teamsGetTeamOnBehalfOf(activity: Activity): OnBehalfOf[];
447+
444448
// @public
445449
export function teamsGetTenant(activity: Activity): TenantInfo | null;
446450

libraries/botbuilder/src/teamsActivityHelpers.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Licensed under the MIT License.
77
*/
88

9-
import { Activity, TeamInfo, TeamsChannelData, TeamsMeetingInfo, TenantInfo } from 'botbuilder-core';
9+
import { Activity, OnBehalfOf, TeamInfo, TeamsChannelData, TeamsMeetingInfo, TenantInfo } from 'botbuilder-core';
1010

1111
function isTeamsChannelData(channelData: unknown): channelData is TeamsChannelData {
1212
return typeof channelData === 'object';
@@ -131,3 +131,17 @@ export function teamsNotifyUser(
131131
activity.channelData.notification = { alert: !alertInMeeting, alertInMeeting, externalResourceUrl };
132132
}
133133
}
134+
135+
/**
136+
* @param activity The current [Activity](xref:botframework-schema.Activity).
137+
* @returns The current [Activity](xref:botframework-schema.Activity)'s team's onBehalfOf list, or null.
138+
*/
139+
export function teamsGetTeamOnBehalfOf(activity: Activity): OnBehalfOf[] {
140+
validateActivity(activity);
141+
142+
if (isTeamsChannelData(activity.channelData)) {
143+
return activity.channelData.onBehalfOf || null;
144+
}
145+
146+
return null;
147+
}

libraries/botbuilder/tests/teamsHelpers.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
teamsGetTeamId,
1111
teamsGetTeamInfo,
1212
teamsNotifyUser,
13+
teamsGetTeamOnBehalfOf,
1314
} = require('../');
1415

1516
function createActivityTeamId() {
@@ -195,4 +196,35 @@ describe('TeamsActivityHelpers method', function () {
195196
assert.strictEqual(channelId, '');
196197
});
197198
});
199+
200+
describe('teamsGetTeamOnBehalfOf()', function () {
201+
it('should return onBehalfOf list', async function () {
202+
const activity = {
203+
channelData: {
204+
onBehalfOf: [
205+
{
206+
itemId: 0,
207+
displayName: 'onBehalfOfTest',
208+
mentionType: 'person',
209+
mri: 'mriTest',
210+
},
211+
],
212+
},
213+
};
214+
const onBehalfOf = teamsGetTeamOnBehalfOf(activity)[0];
215+
assert.strictEqual(onBehalfOf.displayName, activity.channelData.onBehalfOf[0].displayName);
216+
});
217+
218+
it('should return null with no channelData', async function () {
219+
const activity = createActivityNoChannelData();
220+
const onBehalfOf = teamsGetTeamOnBehalfOf(activity);
221+
assert(onBehalfOf === null);
222+
});
223+
224+
it('should return null with no onBehalfOf list', async function () {
225+
const activity = { channelData: { onBehalfOf: null } };
226+
const onBehalfOf = teamsGetTeamOnBehalfOf(activity);
227+
assert(onBehalfOf === null);
228+
});
229+
});
198230
});

libraries/botframework-schema/etc/botframework-schema.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,7 @@ export interface TeamsChannelData {
17641764
eventType?: string;
17651765
meeting?: TeamsMeetingInfo;
17661766
notification?: NotificationInfo;
1767+
onBehalfOf?: OnBehalfOf[];
17671768
settings?: TeamsChannelDataSettings;
17681769
team?: TeamInfo;
17691770
tenant?: TenantInfo;

libraries/botframework-schema/src/teams/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,11 @@ export interface TeamsChannelData {
189189
* message was sent.
190190
*/
191191
settings?: TeamsChannelDataSettings;
192+
/**
193+
* @member {OnBehalfOf} [onBehalfOf] The OnBehalfOf information of the message.
194+
*/
195+
onBehalfOf?: OnBehalfOf[];
192196
}
193-
194197
/**
195198
* @interface
196199
* An interface representing TeamsChannelAccount.

0 commit comments

Comments
 (0)