botbuilder
Version:
Bot Builder is a framework for building rich bots on virtually any platform.
131 lines • 5.33 kB
JavaScript
/**
* @module botbuilder
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.teamsGetTeamOnBehalfOf = exports.teamsNotifyUser = exports.teamsGetChannelId = exports.teamsGetTeamId = exports.teamsGetTeamInfo = exports.teamsGetTenant = exports.teamsGetTeamMeetingInfo = exports.teamsGetSelectedChannelId = void 0;
function isTeamsChannelData(channelData) {
return typeof channelData === 'object';
}
function validateActivity(activity) {
if (!activity) {
throw new Error('Missing activity parameter');
}
}
/**
* Gets the Team's selected channel id from the current activity.
*
* @param activity The current [Activity](xref:botframework-schema.Activity).
* @returns The current activity's team's selected channel, or empty string.
*/
function teamsGetSelectedChannelId(activity) {
var _a, _b, _c, _d;
validateActivity(activity);
return (_d = (_c = (_b = (_a = activity.channelData) === null || _a === void 0 ? void 0 : _a.settings) === null || _b === void 0 ? void 0 : _b.selectedChannel) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : '';
}
exports.teamsGetSelectedChannelId = teamsGetSelectedChannelId;
/**
* Gets the TeamsMeetingInfo object from the current [Activity](xref:botframework-schema.Activity).
*
* @param activity The current [Activity](xref:botframework-schema.Activity).
* @returns The current [Activity](xref:botframework-schema.Activity)'s team meeting info, or null.
*/
function teamsGetTeamMeetingInfo(activity) {
validateActivity(activity);
if (isTeamsChannelData(activity.channelData)) {
return activity.channelData.meeting || null;
}
return null;
}
exports.teamsGetTeamMeetingInfo = teamsGetTeamMeetingInfo;
/**
* Gets the TenantInfo object from the current [Activity](xref:botframework-schema.Activity).
*
* @param activity The current [Activity](xref:botframework-schema.Activity).
* @returns The current [Activity](xref:botframework-schema.Activity)'s tenant info, or null.
*/
function teamsGetTenant(activity) {
validateActivity(activity);
if (isTeamsChannelData(activity.channelData)) {
return activity.channelData.tenant || null;
}
return null;
}
exports.teamsGetTenant = teamsGetTenant;
/**
* Gets the TeamsInfo object from the current [Activity](xref:botframework-schema.Activity).
*
* @param activity The current [Activity](xref:botframework-schema.Activity).
* @returns The current [Activity](xref:botframework-schema.Activity)'s team's info, or null.
*/
function teamsGetTeamInfo(activity) {
validateActivity(activity);
const channelData = activity.channelData;
if (isTeamsChannelData(channelData)) {
const team = channelData.team;
return team || null;
}
return null;
}
exports.teamsGetTeamInfo = teamsGetTeamInfo;
/**
* Gets the Team Id from the current [Activity](xref:botframework-schema.Activity).
*
* @param activity The current [Activity](xref:botframework-schema.Activity).
* @returns The current [Activity](xref:botframework-schema.Activity)'s team's Id, or null.
*/
function teamsGetTeamId(activity) {
const team = teamsGetTeamInfo(activity);
return team && team.id ? team.id : null;
}
exports.teamsGetTeamId = teamsGetTeamId;
/**
* Activity helper methods for Teams.
*
* @param activity The current [Activity](xref:botframework-schema.Activity).
* @returns The current [Activity](xref:botframework-schema.Activity)'s team's channel id, or null.
*/
function teamsGetChannelId(activity) {
validateActivity(activity);
const channelData = activity.channelData;
if (isTeamsChannelData(channelData)) {
const channel = channelData.channel;
return channel && channel.id ? channel.id : null;
}
return null;
}
exports.teamsGetChannelId = teamsGetChannelId;
/**
* Configures the current [Activity](xref:botframework-schema.Activity) to generate a notification within Teams.
*
* @param activity The current [Activity](xref:botframework-schema.Activity).
* @param alertInMeeting Sent to a meeting chat, this will cause the Teams client to render it in a notification popup as well as in the chat thread.
* @param externalResourceUrl Url to external resource. Must be included in manifest's valid domains.
*/
function teamsNotifyUser(activity, alertInMeeting = false, externalResourceUrl) {
validateActivity(activity);
if (!isTeamsChannelData(activity.channelData)) {
activity.channelData = {};
}
if (isTeamsChannelData(activity.channelData)) {
activity.channelData.notification = { alert: !alertInMeeting, alertInMeeting, externalResourceUrl };
}
}
exports.teamsNotifyUser = teamsNotifyUser;
/**
* @param activity The current [Activity](xref:botframework-schema.Activity).
* @returns The current [Activity](xref:botframework-schema.Activity)'s team's onBehalfOf list, or null.
*/
function teamsGetTeamOnBehalfOf(activity) {
validateActivity(activity);
if (isTeamsChannelData(activity.channelData)) {
return activity.channelData.onBehalfOf || null;
}
return null;
}
exports.teamsGetTeamOnBehalfOf = teamsGetTeamOnBehalfOf;
//# sourceMappingURL=teamsActivityHelpers.js.map
;