Skip to content

Commit

Permalink
port: [#4463][#6596] TeamsChannelData need OnBehalfOf (#4474)
Browse files Browse the repository at this point in the history
* add onBehalfOf property to Teams channel

* fix code requirements

---------

Co-authored-by: JhontSouth <jhonatan.sandoval@southworks.com>
  • Loading branch information
ceciliaavila and JhontSouth committed May 8, 2023
1 parent c2abd7d commit 04a6175
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
4 changes: 4 additions & 0 deletions libraries/botbuilder/etc/botbuilder.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { MicrosoftAppCredentials } from 'botframework-connector';
import { Middleware } from 'botbuilder-core';
import { NodeWebSocketFactoryBase } from 'botframework-streaming';
import { O365ConnectorCardActionQuery } from 'botbuilder-core';
import { OnBehalfOf } from 'botbuilder-core';
import { PagedMembersResult } from 'botbuilder-core';
import { PagedResult } from 'botbuilder-core';
import { ReadReceiptInfo } from 'botframework-connector';
Expand Down Expand Up @@ -441,6 +442,9 @@ export function teamsGetTeamInfo(activity: Activity): TeamInfo | null;
// @public
export function teamsGetTeamMeetingInfo(activity: Activity): TeamsMeetingInfo | null;

// @public (undocumented)
export function teamsGetTeamOnBehalfOf(activity: Activity): OnBehalfOf[];

// @public
export function teamsGetTenant(activity: Activity): TenantInfo | null;

Expand Down
16 changes: 15 additions & 1 deletion libraries/botbuilder/src/teamsActivityHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT License.
*/

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

function isTeamsChannelData(channelData: unknown): channelData is TeamsChannelData {
return typeof channelData === 'object';
Expand Down Expand Up @@ -131,3 +131,17 @@ export function teamsNotifyUser(
activity.channelData.notification = { alert: !alertInMeeting, alertInMeeting, externalResourceUrl };
}
}

/**
* @param activity The current [Activity](xref:botframework-schema.Activity).
* @returns The current [Activity](xref:botframework-schema.Activity)'s team's onBehalfOf list, or null.
*/
export function teamsGetTeamOnBehalfOf(activity: Activity): OnBehalfOf[] {
validateActivity(activity);

if (isTeamsChannelData(activity.channelData)) {
return activity.channelData.onBehalfOf || null;
}

return null;
}
32 changes: 32 additions & 0 deletions libraries/botbuilder/tests/teamsHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
teamsGetTeamId,
teamsGetTeamInfo,
teamsNotifyUser,
teamsGetTeamOnBehalfOf,
} = require('../');

function createActivityTeamId() {
Expand Down Expand Up @@ -195,4 +196,35 @@ describe('TeamsActivityHelpers method', function () {
assert.strictEqual(channelId, '');
});
});

describe('teamsGetTeamOnBehalfOf()', function () {
it('should return onBehalfOf list', async function () {
const activity = {
channelData: {
onBehalfOf: [
{
itemId: 0,
displayName: 'onBehalfOfTest',
mentionType: 'person',
mri: 'mriTest',
},
],
},
};
const onBehalfOf = teamsGetTeamOnBehalfOf(activity)[0];
assert.strictEqual(onBehalfOf.displayName, activity.channelData.onBehalfOf[0].displayName);
});

it('should return null with no channelData', async function () {
const activity = createActivityNoChannelData();
const onBehalfOf = teamsGetTeamOnBehalfOf(activity);
assert(onBehalfOf === null);
});

it('should return null with no onBehalfOf list', async function () {
const activity = { channelData: { onBehalfOf: null } };
const onBehalfOf = teamsGetTeamOnBehalfOf(activity);
assert(onBehalfOf === null);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,7 @@ export interface TeamsChannelData {
eventType?: string;
meeting?: TeamsMeetingInfo;
notification?: NotificationInfo;
onBehalfOf?: OnBehalfOf[];
settings?: TeamsChannelDataSettings;
team?: TeamInfo;
tenant?: TenantInfo;
Expand Down
5 changes: 4 additions & 1 deletion libraries/botframework-schema/src/teams/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,11 @@ export interface TeamsChannelData {
* message was sent.
*/
settings?: TeamsChannelDataSettings;
/**
* @member {OnBehalfOf} [onBehalfOf] The OnBehalfOf information of the message.
*/
onBehalfOf?: OnBehalfOf[];
}

/**
* @interface
* An interface representing TeamsChannelAccount.
Expand Down

0 comments on commit 04a6175

Please sign in to comment.