@microsoft/teamsfx 2.1.1-alpha.f8e51b9d8.0 → 2.2.0-alpha.034f24ebd.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -28
- package/dist/index.esm2017.js +548 -12
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +871 -34
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +570 -12
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +907 -35
- package/dist/index.node.cjs.js.map +1 -1
- package/package.json +4 -4
- package/types/teamsfx.d.ts +623 -10
package/dist/index.esm2017.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { ConfidentialClientApplication } from '@azure/msal-node';
|
|
|
3
3
|
import { createHash } from 'crypto';
|
|
4
4
|
import { Client } from '@microsoft/microsoft-graph-client';
|
|
5
5
|
import { ManagedIdentityCredential } from '@azure/identity';
|
|
6
|
-
import { ActivityTypes, Channels, TeamsInfo, CardFactory, ActionTypes, MessageFactory, StatusCodes, verifyStateOperationName, tokenExchangeOperationName, TurnContext, TeamsActivityHandler, MemoryStorage, UserState, ConversationState, BotFrameworkAdapter } from 'botbuilder';
|
|
6
|
+
import { ActivityTypes, Channels, TeamsInfo, CardFactory, ActionTypes, MessageFactory, StatusCodes, verifyStateOperationName, tokenExchangeOperationName, TurnContext, TeamsActivityHandler, MemoryStorage, UserState, ConversationState, BotFrameworkAdapter, ConfigurationServiceClientCredentialFactory, ConfigurationBotFrameworkAuthentication, CloudAdapter } from 'botbuilder';
|
|
7
7
|
import { Dialog, ComponentDialog, WaterfallDialog, DialogSet, DialogTurnStatus } from 'botbuilder-dialogs';
|
|
8
8
|
import { v4 } from 'uuid';
|
|
9
9
|
import axios from 'axios';
|
|
@@ -2007,9 +2007,9 @@ class InvokeResponseFactory {
|
|
|
2007
2007
|
* The type of the invoke response is `application/vnd.microsoft.activity.message`
|
|
2008
2008
|
* indicates the request was successfully processed.
|
|
2009
2009
|
*
|
|
2010
|
-
* @param message A text message included in a invoke response.
|
|
2010
|
+
* @param message - A text message included in a invoke response.
|
|
2011
2011
|
*
|
|
2012
|
-
* @returns
|
|
2012
|
+
* @returns An `InvokeResponse` object.
|
|
2013
2013
|
*/
|
|
2014
2014
|
static textMessage(message) {
|
|
2015
2015
|
if (!message) {
|
|
@@ -2031,9 +2031,9 @@ class InvokeResponseFactory {
|
|
|
2031
2031
|
* the request was successfully processed, and the response includes an adaptive card
|
|
2032
2032
|
* that the client should display in place of the current one.
|
|
2033
2033
|
*
|
|
2034
|
-
* @param card The adaptive card JSON payload.
|
|
2034
|
+
* @param card - The adaptive card JSON payload.
|
|
2035
2035
|
*
|
|
2036
|
-
* @returns
|
|
2036
|
+
* @returns An `InvokeResponse` object.
|
|
2037
2037
|
*/
|
|
2038
2038
|
static adaptiveCard(card) {
|
|
2039
2039
|
if (!card) {
|
|
@@ -2054,12 +2054,12 @@ class InvokeResponseFactory {
|
|
|
2054
2054
|
* The type of the invoke response is `application/vnd.microsoft.error` indicates
|
|
2055
2055
|
* the request was failed to processed.
|
|
2056
2056
|
*
|
|
2057
|
-
* @param errorCode The status code indicates error, available values:
|
|
2057
|
+
* @param errorCode - The status code indicates error, available values:
|
|
2058
2058
|
* - 400 (BadRequest): indicate the incoming request was invalid.
|
|
2059
2059
|
* - 500 (InternalServerError): indicate an unexpected error occurred.
|
|
2060
|
-
* @param errorMessage The error message.
|
|
2060
|
+
* @param errorMessage - The error message.
|
|
2061
2061
|
*
|
|
2062
|
-
* @returns
|
|
2062
|
+
* @returns An `InvokeResponse` object.
|
|
2063
2063
|
*/
|
|
2064
2064
|
static errorResponse(errorCode, errorMessage) {
|
|
2065
2065
|
return {
|
|
@@ -2076,10 +2076,10 @@ class InvokeResponseFactory {
|
|
|
2076
2076
|
}
|
|
2077
2077
|
/**
|
|
2078
2078
|
* Create an invoke response with status code and response value.
|
|
2079
|
-
* @param statusCode The status code.
|
|
2080
|
-
* @param body The value of the response body.
|
|
2079
|
+
* @param statusCode - The status code.
|
|
2080
|
+
* @param body - The value of the response body.
|
|
2081
2081
|
*
|
|
2082
|
-
* @returns
|
|
2082
|
+
* @returns An `InvokeResponse` object.
|
|
2083
2083
|
*/
|
|
2084
2084
|
static createInvokeResponse(statusCode, body) {
|
|
2085
2085
|
return {
|
|
@@ -2167,7 +2167,10 @@ class CardActionMiddleware {
|
|
|
2167
2167
|
/**
|
|
2168
2168
|
* A card action bot to respond to adaptive card universal actions.
|
|
2169
2169
|
*/
|
|
2170
|
-
|
|
2170
|
+
/**
|
|
2171
|
+
* @deprecated Use `BotBuilderCloudAdapter.CardActionBot` instead.
|
|
2172
|
+
*/
|
|
2173
|
+
class CardActionBot$1 {
|
|
2171
2174
|
/**
|
|
2172
2175
|
* Creates a new instance of the `CardActionBot`.
|
|
2173
2176
|
*
|
|
@@ -2321,7 +2324,10 @@ class CommandResponseMiddleware {
|
|
|
2321
2324
|
* @remarks
|
|
2322
2325
|
* Ensure each command should ONLY be registered with the command once, otherwise it'll cause unexpected behavior if you register the same command more than once.
|
|
2323
2326
|
*/
|
|
2324
|
-
|
|
2327
|
+
/**
|
|
2328
|
+
* @deprecated Use `BotBuilderCloudAdapter.CommandBot` instead.
|
|
2329
|
+
*/
|
|
2330
|
+
class CommandBot$1 {
|
|
2325
2331
|
/**
|
|
2326
2332
|
* Creates a new instance of the `CommandBot`.
|
|
2327
2333
|
*
|
|
@@ -2419,7 +2425,7 @@ function getTeamsBotInstallationId(context) {
|
|
|
2419
2425
|
return teamId;
|
|
2420
2426
|
}
|
|
2421
2427
|
// Fallback to use conversation id.
|
|
2422
|
-
//
|
|
2428
|
+
// The conversation id is equal to team id only when the bot app is installed into the General channel.
|
|
2423
2429
|
if (context.activity.conversation.name === undefined) {
|
|
2424
2430
|
return context.activity.conversation.id;
|
|
2425
2431
|
}
|
|
@@ -2645,7 +2651,7 @@ class ConversationReferenceStore {
|
|
|
2645
2651
|
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
2646
2652
|
* @returns the response of sending message.
|
|
2647
2653
|
*/
|
|
2648
|
-
function sendMessage(target, text, onError) {
|
|
2654
|
+
function sendMessage$1(target, text, onError) {
|
|
2649
2655
|
return target.sendMessage(text, onError);
|
|
2650
2656
|
}
|
|
2651
2657
|
/**
|
|
@@ -2657,7 +2663,7 @@ function sendMessage(target, text, onError) {
|
|
|
2657
2663
|
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
2658
2664
|
* @returns the response of sending adaptive card message.
|
|
2659
2665
|
*/
|
|
2660
|
-
function sendAdaptiveCard(target, card, onError) {
|
|
2666
|
+
function sendAdaptiveCard$1(target, card, onError) {
|
|
2661
2667
|
return target.sendAdaptiveCard(card, onError);
|
|
2662
2668
|
}
|
|
2663
2669
|
/**
|
|
@@ -2666,7 +2672,7 @@ function sendAdaptiveCard(target, card, onError) {
|
|
|
2666
2672
|
* @remarks
|
|
2667
2673
|
* It's recommended to get channels from {@link TeamsBotInstallation.channels()}.
|
|
2668
2674
|
*/
|
|
2669
|
-
class Channel {
|
|
2675
|
+
class Channel$1 {
|
|
2670
2676
|
/**
|
|
2671
2677
|
* Constructor.
|
|
2672
2678
|
*
|
|
@@ -2760,7 +2766,7 @@ class Channel {
|
|
|
2760
2766
|
* @remarks
|
|
2761
2767
|
* It's recommended to get members from {@link TeamsBotInstallation.members()}.
|
|
2762
2768
|
*/
|
|
2763
|
-
class Member {
|
|
2769
|
+
class Member$1 {
|
|
2764
2770
|
/**
|
|
2765
2771
|
* Constructor.
|
|
2766
2772
|
*
|
|
@@ -2865,7 +2871,10 @@ class Member {
|
|
|
2865
2871
|
* @remarks
|
|
2866
2872
|
* It's recommended to get bot installations from {@link ConversationBot.installations()}.
|
|
2867
2873
|
*/
|
|
2868
|
-
|
|
2874
|
+
/**
|
|
2875
|
+
* @deprecated Use `BotBuilderCloudAdapter.TeamsBotInstallation` instead.
|
|
2876
|
+
*/
|
|
2877
|
+
class TeamsBotInstallation$1 {
|
|
2869
2878
|
/**
|
|
2870
2879
|
* Constructor
|
|
2871
2880
|
*
|
|
@@ -2952,7 +2961,7 @@ class TeamsBotInstallation {
|
|
|
2952
2961
|
}
|
|
2953
2962
|
});
|
|
2954
2963
|
for (const channel of teamsChannels) {
|
|
2955
|
-
channels.push(new Channel(this, channel));
|
|
2964
|
+
channels.push(new Channel$1(this, channel));
|
|
2956
2965
|
}
|
|
2957
2966
|
return channels;
|
|
2958
2967
|
}
|
|
@@ -2969,7 +2978,7 @@ class TeamsBotInstallation {
|
|
|
2969
2978
|
const pagedMembers = await TeamsInfo.getPagedMembers(context, undefined, continuationToken);
|
|
2970
2979
|
continuationToken = pagedMembers.continuationToken;
|
|
2971
2980
|
for (const member of pagedMembers.members) {
|
|
2972
|
-
members.push(new Member(this, member));
|
|
2981
|
+
members.push(new Member$1(this, member));
|
|
2973
2982
|
}
|
|
2974
2983
|
} while (continuationToken !== undefined);
|
|
2975
2984
|
});
|
|
@@ -2997,7 +3006,10 @@ class TeamsBotInstallation {
|
|
|
2997
3006
|
/**
|
|
2998
3007
|
* Provide utilities to send notification to varies targets (e.g., member, group, channel).
|
|
2999
3008
|
*/
|
|
3000
|
-
|
|
3009
|
+
/**
|
|
3010
|
+
* @deprecated Use `BotBuilderCloudAdapter.NotificationBot` instead.
|
|
3011
|
+
*/
|
|
3012
|
+
class NotificationBot$1 {
|
|
3001
3013
|
/**
|
|
3002
3014
|
* constructor of the notification bot.
|
|
3003
3015
|
*
|
|
@@ -3044,7 +3056,7 @@ class NotificationBot {
|
|
|
3044
3056
|
}
|
|
3045
3057
|
});
|
|
3046
3058
|
if (valid) {
|
|
3047
|
-
targets.push(new TeamsBotInstallation(this.adapter, reference));
|
|
3059
|
+
targets.push(new TeamsBotInstallation$1(this.adapter, reference));
|
|
3048
3060
|
}
|
|
3049
3061
|
else {
|
|
3050
3062
|
await this.conversationReferenceStore.delete(reference);
|
|
@@ -3139,10 +3151,10 @@ class NotificationBot {
|
|
|
3139
3151
|
return channels;
|
|
3140
3152
|
}
|
|
3141
3153
|
matchSearchScope(target, scope) {
|
|
3142
|
-
scope = scope !== null && scope !== void 0 ? scope : SearchScope.All;
|
|
3143
|
-
return ((target.type === NotificationTargetType.Channel && (scope & SearchScope.Channel) !== 0) ||
|
|
3144
|
-
(target.type === NotificationTargetType.Group && (scope & SearchScope.Group) !== 0) ||
|
|
3145
|
-
(target.type === NotificationTargetType.Person && (scope & SearchScope.Person) !== 0));
|
|
3154
|
+
scope = scope !== null && scope !== void 0 ? scope : SearchScope$1.All;
|
|
3155
|
+
return ((target.type === NotificationTargetType.Channel && (scope & SearchScope$1.Channel) !== 0) ||
|
|
3156
|
+
(target.type === NotificationTargetType.Group && (scope & SearchScope$1.Group) !== 0) ||
|
|
3157
|
+
(target.type === NotificationTargetType.Person && (scope & SearchScope$1.Person) !== 0));
|
|
3146
3158
|
}
|
|
3147
3159
|
}
|
|
3148
3160
|
/**
|
|
@@ -3150,7 +3162,7 @@ class NotificationBot {
|
|
|
3150
3162
|
* The search scope is a flagged enum and it can be combined with `|`.
|
|
3151
3163
|
* For example, to search from personal chat and group chat, use `SearchScope.Person | SearchScope.Group`.
|
|
3152
3164
|
*/
|
|
3153
|
-
var SearchScope;
|
|
3165
|
+
var SearchScope$1;
|
|
3154
3166
|
(function (SearchScope) {
|
|
3155
3167
|
/**
|
|
3156
3168
|
* Search members from the installations in personal chat only.
|
|
@@ -3168,7 +3180,7 @@ var SearchScope;
|
|
|
3168
3180
|
* Search members from all installations including personal chat, group chat and Teams channel.
|
|
3169
3181
|
*/
|
|
3170
3182
|
SearchScope[SearchScope["All"] = 7] = "All";
|
|
3171
|
-
})(SearchScope || (SearchScope = {}));
|
|
3183
|
+
})(SearchScope$1 || (SearchScope$1 = {}));
|
|
3172
3184
|
|
|
3173
3185
|
// Copyright (c) Microsoft Corporation.
|
|
3174
3186
|
let DIALOG_NAME = "BotSsoExecutionDialog";
|
|
@@ -3563,7 +3575,10 @@ class DefaultBotSsoExecutionActivityHandler extends TeamsActivityHandler {
|
|
|
3563
3575
|
*
|
|
3564
3576
|
* For notification, set `notification.storage` in {@link ConversationOptions} to use your own storage implementation.
|
|
3565
3577
|
*/
|
|
3566
|
-
|
|
3578
|
+
/**
|
|
3579
|
+
* @deprecated Use `BotBuilderCloudAdapter.ConversationBot` instead.
|
|
3580
|
+
*/
|
|
3581
|
+
class ConversationBot$1 {
|
|
3567
3582
|
/**
|
|
3568
3583
|
* Creates new instance of the `ConversationBot`.
|
|
3569
3584
|
*
|
|
@@ -3591,13 +3606,13 @@ class ConversationBot {
|
|
|
3591
3606
|
}
|
|
3592
3607
|
}
|
|
3593
3608
|
if ((_b = options.command) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
3594
|
-
this.command = new CommandBot(this.adapter, options.command, ssoCommandActivityHandler, options.ssoConfig);
|
|
3609
|
+
this.command = new CommandBot$1(this.adapter, options.command, ssoCommandActivityHandler, options.ssoConfig);
|
|
3595
3610
|
}
|
|
3596
3611
|
if ((_c = options.notification) === null || _c === void 0 ? void 0 : _c.enabled) {
|
|
3597
|
-
this.notification = new NotificationBot(this.adapter, options.notification);
|
|
3612
|
+
this.notification = new NotificationBot$1(this.adapter, options.notification);
|
|
3598
3613
|
}
|
|
3599
3614
|
if ((_d = options.cardAction) === null || _d === void 0 ? void 0 : _d.enabled) {
|
|
3600
|
-
this.cardAction = new CardActionBot(this.adapter, options.cardAction);
|
|
3615
|
+
this.cardAction = new CardActionBot$1(this.adapter, options.cardAction);
|
|
3601
3616
|
}
|
|
3602
3617
|
}
|
|
3603
3618
|
createDefaultAdapter(adapterConfig) {
|
|
@@ -3988,5 +4003,827 @@ async function handleMessageExtensionQueryWithSSO(context, config, initiateLogin
|
|
|
3988
4003
|
return await executionWithTokenAndConfig(context, config !== null && config !== void 0 ? config : {}, initiateLoginEndpoint, scopes, logic);
|
|
3989
4004
|
}
|
|
3990
4005
|
|
|
3991
|
-
|
|
4006
|
+
/**
|
|
4007
|
+
* A card action bot to respond to adaptive card universal actions.
|
|
4008
|
+
*/
|
|
4009
|
+
class CardActionBot {
|
|
4010
|
+
/**
|
|
4011
|
+
* Create a new instance of the `CardActionBot`.
|
|
4012
|
+
*
|
|
4013
|
+
* @param adapter - The bound `CloudAdapter`.
|
|
4014
|
+
* @param options - The initialize options.
|
|
4015
|
+
*/
|
|
4016
|
+
constructor(adapter, options) {
|
|
4017
|
+
this.middleware = new CardActionMiddleware(options === null || options === void 0 ? void 0 : options.actions);
|
|
4018
|
+
this.adapter = adapter.use(this.middleware);
|
|
4019
|
+
}
|
|
4020
|
+
/**
|
|
4021
|
+
* Register a card action handler to the bot.
|
|
4022
|
+
*
|
|
4023
|
+
* @param actionHandler - A card action handler to be registered.
|
|
4024
|
+
*/
|
|
4025
|
+
registerHandler(actionHandler) {
|
|
4026
|
+
if (actionHandler) {
|
|
4027
|
+
this.middleware.actionHandlers.push(actionHandler);
|
|
4028
|
+
}
|
|
4029
|
+
}
|
|
4030
|
+
/**
|
|
4031
|
+
* Register card action handlers to the bot.
|
|
4032
|
+
*
|
|
4033
|
+
* @param actionHandlers - A set of card action handlers to be registered.
|
|
4034
|
+
*/
|
|
4035
|
+
registerHandlers(actionHandlers) {
|
|
4036
|
+
if (actionHandlers) {
|
|
4037
|
+
this.middleware.actionHandlers.push(...actionHandlers);
|
|
4038
|
+
}
|
|
4039
|
+
}
|
|
4040
|
+
}
|
|
4041
|
+
|
|
4042
|
+
// Copyright (c) Microsoft Corporation.
|
|
4043
|
+
/**
|
|
4044
|
+
* A command bot for receiving commands and sending responses in Teams.
|
|
4045
|
+
*
|
|
4046
|
+
* @remarks
|
|
4047
|
+
* Ensure each command should ONLY be registered with the command once, otherwise it'll cause unexpected behavior if you register the same command more than once.
|
|
4048
|
+
*/
|
|
4049
|
+
class CommandBot {
|
|
4050
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
4051
|
+
/**
|
|
4052
|
+
* Create a new instance of the `CommandBot`.
|
|
4053
|
+
*
|
|
4054
|
+
* @param adapter - The bound `CloudAdapter`.
|
|
4055
|
+
* @param options - The initialize options
|
|
4056
|
+
* @param ssoCommandActivityHandler - SSO execution activity handler.
|
|
4057
|
+
* @param ssoConfig - SSO configuration for Bot SSO.
|
|
4058
|
+
*/
|
|
4059
|
+
constructor(adapter, options, ssoCommandActivityHandler, ssoConfig) {
|
|
4060
|
+
this.ssoConfig = ssoConfig;
|
|
4061
|
+
this.middleware = new CommandResponseMiddleware(options === null || options === void 0 ? void 0 : options.commands, options === null || options === void 0 ? void 0 : options.ssoCommands, ssoCommandActivityHandler);
|
|
4062
|
+
this.adapter = adapter.use(this.middleware);
|
|
4063
|
+
}
|
|
4064
|
+
/**
|
|
4065
|
+
* Register a command into the command bot.
|
|
4066
|
+
*
|
|
4067
|
+
* @param command - The command to be registered.
|
|
4068
|
+
*/
|
|
4069
|
+
registerCommand(command) {
|
|
4070
|
+
if (command) {
|
|
4071
|
+
this.middleware.commandHandlers.push(command);
|
|
4072
|
+
}
|
|
4073
|
+
}
|
|
4074
|
+
/**
|
|
4075
|
+
* Register commands into the command bot.
|
|
4076
|
+
*
|
|
4077
|
+
* @param commands - The commands to be registered.
|
|
4078
|
+
*/
|
|
4079
|
+
registerCommands(commands) {
|
|
4080
|
+
if (commands) {
|
|
4081
|
+
this.middleware.commandHandlers.push(...commands);
|
|
4082
|
+
}
|
|
4083
|
+
}
|
|
4084
|
+
/**
|
|
4085
|
+
* Register a sso command into the command bot.
|
|
4086
|
+
*
|
|
4087
|
+
* @param ssoCommand - The sso command to be registered.
|
|
4088
|
+
*/
|
|
4089
|
+
registerSsoCommand(ssoCommand) {
|
|
4090
|
+
this.validateSsoActivityHandler();
|
|
4091
|
+
this.middleware.addSsoCommand(ssoCommand);
|
|
4092
|
+
}
|
|
4093
|
+
/**
|
|
4094
|
+
* Register sso commands into the command bot.
|
|
4095
|
+
*
|
|
4096
|
+
* @param ssoCommands - The sso commands to be registered.
|
|
4097
|
+
*/
|
|
4098
|
+
registerSsoCommands(ssoCommands) {
|
|
4099
|
+
if (ssoCommands.length > 0) {
|
|
4100
|
+
this.validateSsoActivityHandler();
|
|
4101
|
+
for (const ssoCommand of ssoCommands) {
|
|
4102
|
+
this.middleware.addSsoCommand(ssoCommand);
|
|
4103
|
+
}
|
|
4104
|
+
}
|
|
4105
|
+
}
|
|
4106
|
+
validateSsoActivityHandler() {
|
|
4107
|
+
if (!this.middleware.ssoActivityHandler) {
|
|
4108
|
+
internalLogger.error(ErrorMessage.SsoActivityHandlerIsNull);
|
|
4109
|
+
throw new ErrorWithCode(ErrorMessage.SsoActivityHandlerIsNull, ErrorCode.SsoActivityHandlerIsUndefined);
|
|
4110
|
+
}
|
|
4111
|
+
}
|
|
4112
|
+
}
|
|
4113
|
+
|
|
4114
|
+
// Copyright (c) Microsoft Corporation.
|
|
4115
|
+
/**
|
|
4116
|
+
* Send a plain text message to a notification target.
|
|
4117
|
+
*
|
|
4118
|
+
* @param target - The notification target.
|
|
4119
|
+
* @param text - The plain text message.
|
|
4120
|
+
* @param onError - An optional error handler that can catch exceptions during message sending.
|
|
4121
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4122
|
+
*
|
|
4123
|
+
* @returns The response of sending message.
|
|
4124
|
+
*/
|
|
4125
|
+
function sendMessage(target, text, onError) {
|
|
4126
|
+
return target.sendMessage(text, onError);
|
|
4127
|
+
}
|
|
4128
|
+
/**
|
|
4129
|
+
* Send an adaptive card message to a notification target.
|
|
4130
|
+
*
|
|
4131
|
+
* @param target - The notification target.
|
|
4132
|
+
* @param card - The adaptive card raw JSON.
|
|
4133
|
+
* @param onError - An optional error handler that can catch exceptions during adaptive card sending.
|
|
4134
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4135
|
+
*
|
|
4136
|
+
* @returns The response of sending adaptive card message.
|
|
4137
|
+
*/
|
|
4138
|
+
function sendAdaptiveCard(target, card, onError) {
|
|
4139
|
+
return target.sendAdaptiveCard(card, onError);
|
|
4140
|
+
}
|
|
4141
|
+
/**
|
|
4142
|
+
* A {@link NotificationTarget} that represents a team channel.
|
|
4143
|
+
*
|
|
4144
|
+
* @remarks
|
|
4145
|
+
* It's recommended to get channels from {@link TeamsBotInstallation.channels()}.
|
|
4146
|
+
*/
|
|
4147
|
+
class Channel {
|
|
4148
|
+
/**
|
|
4149
|
+
* Constructor.
|
|
4150
|
+
*
|
|
4151
|
+
* @remarks
|
|
4152
|
+
* It's recommended to get channels from {@link TeamsBotInstallation.channels()}, instead of using this constructor.
|
|
4153
|
+
*
|
|
4154
|
+
* @param parent - The parent {@link TeamsBotInstallation} where this channel is created from.
|
|
4155
|
+
* @param info - Detailed channel information.
|
|
4156
|
+
*/
|
|
4157
|
+
constructor(parent, info) {
|
|
4158
|
+
/**
|
|
4159
|
+
* Notification target type. For channel it's always "Channel".
|
|
4160
|
+
*/
|
|
4161
|
+
this.type = NotificationTargetType.Channel;
|
|
4162
|
+
this.parent = parent;
|
|
4163
|
+
this.info = info;
|
|
4164
|
+
}
|
|
4165
|
+
/**
|
|
4166
|
+
* Send a plain text message.
|
|
4167
|
+
*
|
|
4168
|
+
* @param text - The plain text message.
|
|
4169
|
+
* @param onError - An optional error handler that can catch exceptions during message sending.
|
|
4170
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4171
|
+
*
|
|
4172
|
+
* @returns The response of sending message.
|
|
4173
|
+
*/
|
|
4174
|
+
async sendMessage(text, onError) {
|
|
4175
|
+
const response = {};
|
|
4176
|
+
await this.parent.adapter.continueConversationAsync(this.parent.botAppId, this.parent.conversationReference, async (context) => {
|
|
4177
|
+
const conversation = await this.newConversation(context);
|
|
4178
|
+
await this.parent.adapter.continueConversationAsync(this.parent.botAppId, conversation, async (ctx) => {
|
|
4179
|
+
try {
|
|
4180
|
+
const res = await ctx.sendActivity(text);
|
|
4181
|
+
response.id = res === null || res === void 0 ? void 0 : res.id;
|
|
4182
|
+
}
|
|
4183
|
+
catch (error) {
|
|
4184
|
+
if (onError) {
|
|
4185
|
+
await onError(ctx, error);
|
|
4186
|
+
}
|
|
4187
|
+
else {
|
|
4188
|
+
throw error;
|
|
4189
|
+
}
|
|
4190
|
+
}
|
|
4191
|
+
});
|
|
4192
|
+
});
|
|
4193
|
+
return response;
|
|
4194
|
+
}
|
|
4195
|
+
/**
|
|
4196
|
+
* Send an adaptive card message.
|
|
4197
|
+
*
|
|
4198
|
+
* @param card - The adaptive card raw JSON.
|
|
4199
|
+
* @param onError - An optional error handler that can catch exceptions during adaptive card sending.
|
|
4200
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4201
|
+
*
|
|
4202
|
+
* @returns The response of sending adaptive card message.
|
|
4203
|
+
*/
|
|
4204
|
+
async sendAdaptiveCard(card, onError) {
|
|
4205
|
+
const response = {};
|
|
4206
|
+
await this.parent.adapter.continueConversationAsync(this.parent.botAppId, this.parent.conversationReference, async (context) => {
|
|
4207
|
+
const conversation = await this.newConversation(context);
|
|
4208
|
+
await this.parent.adapter.continueConversationAsync(this.parent.botAppId, conversation, async (ctx) => {
|
|
4209
|
+
try {
|
|
4210
|
+
const res = await ctx.sendActivity({
|
|
4211
|
+
attachments: [CardFactory.adaptiveCard(card)],
|
|
4212
|
+
});
|
|
4213
|
+
response.id = res === null || res === void 0 ? void 0 : res.id;
|
|
4214
|
+
}
|
|
4215
|
+
catch (error) {
|
|
4216
|
+
if (onError) {
|
|
4217
|
+
await onError(ctx, error);
|
|
4218
|
+
}
|
|
4219
|
+
else {
|
|
4220
|
+
throw error;
|
|
4221
|
+
}
|
|
4222
|
+
}
|
|
4223
|
+
});
|
|
4224
|
+
});
|
|
4225
|
+
return response;
|
|
4226
|
+
}
|
|
4227
|
+
/**
|
|
4228
|
+
* @internal
|
|
4229
|
+
*/
|
|
4230
|
+
async newConversation(context) {
|
|
4231
|
+
const reference = TurnContext.getConversationReference(context.activity);
|
|
4232
|
+
const channelConversation = cloneConversation(reference);
|
|
4233
|
+
channelConversation.conversation.id = this.info.id || "";
|
|
4234
|
+
return channelConversation;
|
|
4235
|
+
}
|
|
4236
|
+
}
|
|
4237
|
+
/**
|
|
4238
|
+
* A {@link NotificationTarget} that represents a team member.
|
|
4239
|
+
*
|
|
4240
|
+
* @remarks
|
|
4241
|
+
* It's recommended to get members from {@link TeamsBotInstallation.members()}.
|
|
4242
|
+
*/
|
|
4243
|
+
class Member {
|
|
4244
|
+
/**
|
|
4245
|
+
* Constructor.
|
|
4246
|
+
*
|
|
4247
|
+
* @remarks
|
|
4248
|
+
* It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
|
|
4249
|
+
*
|
|
4250
|
+
* @param parent - The parent {@link TeamsBotInstallation} where this member is created from.
|
|
4251
|
+
* @param account - Detailed member account information.
|
|
4252
|
+
*/
|
|
4253
|
+
constructor(parent, account) {
|
|
4254
|
+
/**
|
|
4255
|
+
* Notification target type. For member it's always "Person".
|
|
4256
|
+
*/
|
|
4257
|
+
this.type = NotificationTargetType.Person;
|
|
4258
|
+
this.parent = parent;
|
|
4259
|
+
this.account = account;
|
|
4260
|
+
}
|
|
4261
|
+
/**
|
|
4262
|
+
* Send a plain text message.
|
|
4263
|
+
*
|
|
4264
|
+
* @param text - The plain text message.
|
|
4265
|
+
* @param onError - An optional error handler that can catch exceptions during message sending.
|
|
4266
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4267
|
+
*
|
|
4268
|
+
* @returns The response of sending message.
|
|
4269
|
+
*/
|
|
4270
|
+
async sendMessage(text, onError) {
|
|
4271
|
+
const response = {};
|
|
4272
|
+
await this.parent.adapter.continueConversationAsync(this.parent.botAppId, this.parent.conversationReference, async (context) => {
|
|
4273
|
+
const conversation = await this.newConversation(context);
|
|
4274
|
+
await this.parent.adapter.continueConversationAsync(this.parent.botAppId, conversation, async (ctx) => {
|
|
4275
|
+
try {
|
|
4276
|
+
const res = await ctx.sendActivity(text);
|
|
4277
|
+
response.id = res === null || res === void 0 ? void 0 : res.id;
|
|
4278
|
+
}
|
|
4279
|
+
catch (error) {
|
|
4280
|
+
if (onError) {
|
|
4281
|
+
await onError(ctx, error);
|
|
4282
|
+
}
|
|
4283
|
+
else {
|
|
4284
|
+
throw error;
|
|
4285
|
+
}
|
|
4286
|
+
}
|
|
4287
|
+
});
|
|
4288
|
+
});
|
|
4289
|
+
return response;
|
|
4290
|
+
}
|
|
4291
|
+
/**
|
|
4292
|
+
* Send an adaptive card message.
|
|
4293
|
+
*
|
|
4294
|
+
* @param card - The adaptive card raw JSON.
|
|
4295
|
+
* @param onError - An optional error handler that can catch exceptions during adaptive card sending.
|
|
4296
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4297
|
+
*
|
|
4298
|
+
* @returns The response of sending adaptive card message.
|
|
4299
|
+
*/
|
|
4300
|
+
async sendAdaptiveCard(card, onError) {
|
|
4301
|
+
const response = {};
|
|
4302
|
+
await this.parent.adapter.continueConversationAsync(this.parent.botAppId, this.parent.conversationReference, async (context) => {
|
|
4303
|
+
const conversation = await this.newConversation(context);
|
|
4304
|
+
await this.parent.adapter.continueConversationAsync(this.parent.botAppId, conversation, async (ctx) => {
|
|
4305
|
+
try {
|
|
4306
|
+
const res = await ctx.sendActivity({
|
|
4307
|
+
attachments: [CardFactory.adaptiveCard(card)],
|
|
4308
|
+
});
|
|
4309
|
+
response.id = res === null || res === void 0 ? void 0 : res.id;
|
|
4310
|
+
}
|
|
4311
|
+
catch (error) {
|
|
4312
|
+
if (onError) {
|
|
4313
|
+
await onError(ctx, error);
|
|
4314
|
+
}
|
|
4315
|
+
else {
|
|
4316
|
+
throw error;
|
|
4317
|
+
}
|
|
4318
|
+
}
|
|
4319
|
+
});
|
|
4320
|
+
});
|
|
4321
|
+
return response;
|
|
4322
|
+
}
|
|
4323
|
+
/**
|
|
4324
|
+
* @internal
|
|
4325
|
+
*/
|
|
4326
|
+
async newConversation(context) {
|
|
4327
|
+
const reference = TurnContext.getConversationReference(context.activity);
|
|
4328
|
+
const personalConversation = cloneConversation(reference);
|
|
4329
|
+
const connectorClient = context.turnState.get(this.parent.adapter.ConnectorClientKey);
|
|
4330
|
+
const conversation = await connectorClient.conversations.createConversation({
|
|
4331
|
+
isGroup: false,
|
|
4332
|
+
tenantId: context.activity.conversation.tenantId,
|
|
4333
|
+
bot: context.activity.recipient,
|
|
4334
|
+
members: [this.account],
|
|
4335
|
+
channelData: {},
|
|
4336
|
+
});
|
|
4337
|
+
personalConversation.conversation.id = conversation.id;
|
|
4338
|
+
return personalConversation;
|
|
4339
|
+
}
|
|
4340
|
+
}
|
|
4341
|
+
/**
|
|
4342
|
+
* A {@link NotificationTarget} that represents a bot installation. Teams Bot could be installed into
|
|
4343
|
+
* - Personal chat
|
|
4344
|
+
* - Group chat
|
|
4345
|
+
* - Team (by default the `General` channel)
|
|
4346
|
+
*
|
|
4347
|
+
* @remarks
|
|
4348
|
+
* It's recommended to get bot installations from {@link ConversationBot.installations()}.
|
|
4349
|
+
*/
|
|
4350
|
+
class TeamsBotInstallation {
|
|
4351
|
+
/**
|
|
4352
|
+
* Constructor
|
|
4353
|
+
*
|
|
4354
|
+
* @remarks
|
|
4355
|
+
* It's recommended to get bot installations from {@link ConversationBot.installations()}, instead of using this constructor.
|
|
4356
|
+
*
|
|
4357
|
+
* @param adapter - The bound `CloudAdapter`.
|
|
4358
|
+
* @param conversationReference - The bound `ConversationReference`.
|
|
4359
|
+
* @param botAppId - The bot app id.
|
|
4360
|
+
*/
|
|
4361
|
+
constructor(adapter, conversationReference, botAppId) {
|
|
4362
|
+
this.adapter = adapter;
|
|
4363
|
+
this.conversationReference = conversationReference;
|
|
4364
|
+
this.type = getTargetType(conversationReference);
|
|
4365
|
+
this.botAppId = botAppId;
|
|
4366
|
+
}
|
|
4367
|
+
/**
|
|
4368
|
+
* Send a plain text message.
|
|
4369
|
+
*
|
|
4370
|
+
* @param text - The plain text message.
|
|
4371
|
+
* @param onError - An optional error handler that can catch exceptions during message sending.
|
|
4372
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4373
|
+
*
|
|
4374
|
+
* @returns The response of sending message.
|
|
4375
|
+
*/
|
|
4376
|
+
async sendMessage(text, onError) {
|
|
4377
|
+
const response = {};
|
|
4378
|
+
await this.adapter.continueConversationAsync(this.botAppId, this.conversationReference, async (context) => {
|
|
4379
|
+
try {
|
|
4380
|
+
const res = await context.sendActivity(text);
|
|
4381
|
+
response.id = res === null || res === void 0 ? void 0 : res.id;
|
|
4382
|
+
}
|
|
4383
|
+
catch (error) {
|
|
4384
|
+
if (onError) {
|
|
4385
|
+
await onError(context, error);
|
|
4386
|
+
}
|
|
4387
|
+
else {
|
|
4388
|
+
throw error;
|
|
4389
|
+
}
|
|
4390
|
+
}
|
|
4391
|
+
});
|
|
4392
|
+
return response;
|
|
4393
|
+
}
|
|
4394
|
+
/**
|
|
4395
|
+
* Send an adaptive card message.
|
|
4396
|
+
*
|
|
4397
|
+
* @param card - The adaptive card raw JSON.
|
|
4398
|
+
* @param onError - An optional error handler that can catch exceptions during adaptive card sending.
|
|
4399
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4400
|
+
*
|
|
4401
|
+
* @returns The response of sending adaptive card message.
|
|
4402
|
+
*/
|
|
4403
|
+
async sendAdaptiveCard(card, onError) {
|
|
4404
|
+
const response = {};
|
|
4405
|
+
await this.adapter.continueConversationAsync(this.botAppId, this.conversationReference, async (context) => {
|
|
4406
|
+
try {
|
|
4407
|
+
const res = await context.sendActivity({
|
|
4408
|
+
attachments: [CardFactory.adaptiveCard(card)],
|
|
4409
|
+
});
|
|
4410
|
+
response.id = res === null || res === void 0 ? void 0 : res.id;
|
|
4411
|
+
}
|
|
4412
|
+
catch (error) {
|
|
4413
|
+
if (onError) {
|
|
4414
|
+
await onError(context, error);
|
|
4415
|
+
}
|
|
4416
|
+
else {
|
|
4417
|
+
throw error;
|
|
4418
|
+
}
|
|
4419
|
+
}
|
|
4420
|
+
});
|
|
4421
|
+
return response;
|
|
4422
|
+
}
|
|
4423
|
+
/**
|
|
4424
|
+
* Get channels from this bot installation.
|
|
4425
|
+
*
|
|
4426
|
+
* @returns An array of channels if bot is installed into a team, otherwise returns an empty array.
|
|
4427
|
+
*/
|
|
4428
|
+
async channels() {
|
|
4429
|
+
const channels = [];
|
|
4430
|
+
if (this.type !== NotificationTargetType.Channel) {
|
|
4431
|
+
return channels;
|
|
4432
|
+
}
|
|
4433
|
+
let teamsChannels = [];
|
|
4434
|
+
await this.adapter.continueConversationAsync(this.botAppId, this.conversationReference, async (context) => {
|
|
4435
|
+
const teamId = getTeamsBotInstallationId(context);
|
|
4436
|
+
if (teamId !== undefined) {
|
|
4437
|
+
teamsChannels = await TeamsInfo.getTeamChannels(context, teamId);
|
|
4438
|
+
}
|
|
4439
|
+
});
|
|
4440
|
+
for (const channel of teamsChannels) {
|
|
4441
|
+
channels.push(new Channel(this, channel));
|
|
4442
|
+
}
|
|
4443
|
+
return channels;
|
|
4444
|
+
}
|
|
4445
|
+
/**
|
|
4446
|
+
* Get members from this bot installation.
|
|
4447
|
+
*
|
|
4448
|
+
* @returns An array of members from where the bot is installed.
|
|
4449
|
+
*/
|
|
4450
|
+
async members() {
|
|
4451
|
+
const members = [];
|
|
4452
|
+
await this.adapter.continueConversationAsync(this.botAppId, this.conversationReference, async (context) => {
|
|
4453
|
+
let continuationToken;
|
|
4454
|
+
do {
|
|
4455
|
+
const pagedMembers = await TeamsInfo.getPagedMembers(context, undefined, continuationToken);
|
|
4456
|
+
continuationToken = pagedMembers.continuationToken;
|
|
4457
|
+
for (const member of pagedMembers.members) {
|
|
4458
|
+
members.push(new Member(this, member));
|
|
4459
|
+
}
|
|
4460
|
+
} while (continuationToken !== undefined);
|
|
4461
|
+
});
|
|
4462
|
+
return members;
|
|
4463
|
+
}
|
|
4464
|
+
/**
|
|
4465
|
+
* Get team details from this bot installation
|
|
4466
|
+
*
|
|
4467
|
+
* @returns The team details if bot is installed into a team, otherwise returns `undefined`.
|
|
4468
|
+
*/
|
|
4469
|
+
async getTeamDetails() {
|
|
4470
|
+
if (this.type !== NotificationTargetType.Channel) {
|
|
4471
|
+
return undefined;
|
|
4472
|
+
}
|
|
4473
|
+
let teamDetails;
|
|
4474
|
+
await this.adapter.continueConversationAsync(this.botAppId, this.conversationReference, async (context) => {
|
|
4475
|
+
const teamId = getTeamsBotInstallationId(context);
|
|
4476
|
+
if (teamId !== undefined) {
|
|
4477
|
+
teamDetails = await TeamsInfo.getTeamDetails(context, teamId);
|
|
4478
|
+
}
|
|
4479
|
+
});
|
|
4480
|
+
return teamDetails;
|
|
4481
|
+
}
|
|
4482
|
+
}
|
|
4483
|
+
/**
|
|
4484
|
+
* Provide utilities to send notification to varies targets (e.g., member, group, channel).
|
|
4485
|
+
*/
|
|
4486
|
+
class NotificationBot {
|
|
4487
|
+
/**
|
|
4488
|
+
* Constructor of the notification bot.
|
|
4489
|
+
*
|
|
4490
|
+
* @remarks
|
|
4491
|
+
* To ensure accuracy, it's recommended to initialize before handling any message.
|
|
4492
|
+
*
|
|
4493
|
+
* @param adapter - The bound `CloudAdapter`
|
|
4494
|
+
* @param options - The initialize options
|
|
4495
|
+
*/
|
|
4496
|
+
constructor(adapter, options) {
|
|
4497
|
+
var _a, _b, _c;
|
|
4498
|
+
const storage = (_a = options === null || options === void 0 ? void 0 : options.storage) !== null && _a !== void 0 ? _a : new LocalFileStorage(path.resolve(process.env.RUNNING_ON_AZURE === "1" ? (_b = process.env.TEMP) !== null && _b !== void 0 ? _b : "./" : "./"));
|
|
4499
|
+
this.conversationReferenceStore = new ConversationReferenceStore(storage);
|
|
4500
|
+
this.adapter = adapter.use(new NotificationMiddleware({
|
|
4501
|
+
conversationReferenceStore: this.conversationReferenceStore,
|
|
4502
|
+
}));
|
|
4503
|
+
this.botAppId = ((_c = options === null || options === void 0 ? void 0 : options.botAppId) !== null && _c !== void 0 ? _c : process.env.BOT_ID);
|
|
4504
|
+
}
|
|
4505
|
+
/**
|
|
4506
|
+
* Get all targets where the bot is installed.
|
|
4507
|
+
*
|
|
4508
|
+
* @remarks
|
|
4509
|
+
* The result is retrieving from the persisted storage.
|
|
4510
|
+
*
|
|
4511
|
+
* @returns An array of {@link TeamsBotInstallation}.
|
|
4512
|
+
*/
|
|
4513
|
+
async installations() {
|
|
4514
|
+
if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
|
|
4515
|
+
throw new Error("NotificationBot has not been initialized.");
|
|
4516
|
+
}
|
|
4517
|
+
const references = await this.conversationReferenceStore.getAll();
|
|
4518
|
+
const targets = [];
|
|
4519
|
+
for (const reference of references) {
|
|
4520
|
+
// validate connection
|
|
4521
|
+
let valid = true;
|
|
4522
|
+
await this.adapter.continueConversationAsync(this.botAppId, reference, async (context) => {
|
|
4523
|
+
try {
|
|
4524
|
+
// try get member to see if the installation is still valid
|
|
4525
|
+
await TeamsInfo.getPagedMembers(context, 1);
|
|
4526
|
+
}
|
|
4527
|
+
catch (error) {
|
|
4528
|
+
if (error.code === "BotNotInConversationRoster") {
|
|
4529
|
+
valid = false;
|
|
4530
|
+
}
|
|
4531
|
+
}
|
|
4532
|
+
});
|
|
4533
|
+
if (valid) {
|
|
4534
|
+
targets.push(new TeamsBotInstallation(this.adapter, reference, this.botAppId));
|
|
4535
|
+
}
|
|
4536
|
+
else {
|
|
4537
|
+
await this.conversationReferenceStore.delete(reference);
|
|
4538
|
+
}
|
|
4539
|
+
}
|
|
4540
|
+
return targets;
|
|
4541
|
+
}
|
|
4542
|
+
/**
|
|
4543
|
+
* Return the first {@link Member} where predicate is true, and undefined otherwise.
|
|
4544
|
+
*
|
|
4545
|
+
* @param predicate - Find calls predicate once for each member of the installation,
|
|
4546
|
+
* until it finds one where predicate returns true. If such a member is found, find
|
|
4547
|
+
* immediately returns that member. Otherwise, find returns undefined.
|
|
4548
|
+
* @param scope - The scope to find members from the installations
|
|
4549
|
+
* (personal chat, group chat, Teams channel).
|
|
4550
|
+
*
|
|
4551
|
+
* @returns The first {@link Member} where predicate is true, and `undefined` otherwise.
|
|
4552
|
+
*/
|
|
4553
|
+
async findMember(predicate, scope) {
|
|
4554
|
+
for (const target of await this.installations()) {
|
|
4555
|
+
if (this.matchSearchScope(target, scope)) {
|
|
4556
|
+
for (const member of await target.members()) {
|
|
4557
|
+
if (await predicate(member)) {
|
|
4558
|
+
return member;
|
|
4559
|
+
}
|
|
4560
|
+
}
|
|
4561
|
+
}
|
|
4562
|
+
}
|
|
4563
|
+
return;
|
|
4564
|
+
}
|
|
4565
|
+
/**
|
|
4566
|
+
* Return the first {@link Channel} where predicate is true, and undefined otherwise.
|
|
4567
|
+
* (Ensure the bot app is installed into the `General` channel, otherwise undefined will be returned.)
|
|
4568
|
+
*
|
|
4569
|
+
* @param predicate - Find calls predicate once for each channel of the installation,
|
|
4570
|
+
* until it finds one where predicate returns true. If such a channel is found, find
|
|
4571
|
+
* immediately returns that channel. Otherwise, find returns `undefined`.
|
|
4572
|
+
*
|
|
4573
|
+
* @returns The first {@link Channel} where predicate is true, and `undefined` otherwise.
|
|
4574
|
+
*/
|
|
4575
|
+
async findChannel(predicate) {
|
|
4576
|
+
for (const target of await this.installations()) {
|
|
4577
|
+
if (target.type === NotificationTargetType.Channel) {
|
|
4578
|
+
const teamDetails = await target.getTeamDetails();
|
|
4579
|
+
for (const channel of await target.channels()) {
|
|
4580
|
+
if (await predicate(channel, teamDetails)) {
|
|
4581
|
+
return channel;
|
|
4582
|
+
}
|
|
4583
|
+
}
|
|
4584
|
+
}
|
|
4585
|
+
}
|
|
4586
|
+
return;
|
|
4587
|
+
}
|
|
4588
|
+
/**
|
|
4589
|
+
* Return all {@link Member} where predicate is true, and empty array otherwise.
|
|
4590
|
+
*
|
|
4591
|
+
* @param predicate - Find calls predicate for each member of the installation.
|
|
4592
|
+
* @param scope - The scope to find members from the installations
|
|
4593
|
+
* (personal chat, group chat, Teams channel).
|
|
4594
|
+
*
|
|
4595
|
+
* @returns An array of {@link Member} where predicate is true, and empty array otherwise.
|
|
4596
|
+
*/
|
|
4597
|
+
async findAllMembers(predicate, scope) {
|
|
4598
|
+
const members = [];
|
|
4599
|
+
for (const target of await this.installations()) {
|
|
4600
|
+
if (this.matchSearchScope(target, scope)) {
|
|
4601
|
+
for (const member of await target.members()) {
|
|
4602
|
+
if (await predicate(member)) {
|
|
4603
|
+
members.push(member);
|
|
4604
|
+
}
|
|
4605
|
+
}
|
|
4606
|
+
}
|
|
4607
|
+
}
|
|
4608
|
+
return members;
|
|
4609
|
+
}
|
|
4610
|
+
/**
|
|
4611
|
+
* Return all {@link Channel} where predicate is true, and empty array otherwise.
|
|
4612
|
+
* (Ensure the bot app is installed into the `General` channel, otherwise empty array will be returned.)
|
|
4613
|
+
*
|
|
4614
|
+
* @param predicate - Find calls predicate for each channel of the installation.
|
|
4615
|
+
*
|
|
4616
|
+
* @returns An array of {@link Channel} where predicate is true, and empty array otherwise.
|
|
4617
|
+
*/
|
|
4618
|
+
async findAllChannels(predicate) {
|
|
4619
|
+
const channels = [];
|
|
4620
|
+
for (const target of await this.installations()) {
|
|
4621
|
+
if (target.type === NotificationTargetType.Channel) {
|
|
4622
|
+
const teamDetails = await target.getTeamDetails();
|
|
4623
|
+
for (const channel of await target.channels()) {
|
|
4624
|
+
if (await predicate(channel, teamDetails)) {
|
|
4625
|
+
channels.push(channel);
|
|
4626
|
+
}
|
|
4627
|
+
}
|
|
4628
|
+
}
|
|
4629
|
+
}
|
|
4630
|
+
return channels;
|
|
4631
|
+
}
|
|
4632
|
+
matchSearchScope(target, scope) {
|
|
4633
|
+
scope = scope !== null && scope !== void 0 ? scope : SearchScope.All;
|
|
4634
|
+
return ((target.type === NotificationTargetType.Channel && (scope & SearchScope.Channel) !== 0) ||
|
|
4635
|
+
(target.type === NotificationTargetType.Group && (scope & SearchScope.Group) !== 0) ||
|
|
4636
|
+
(target.type === NotificationTargetType.Person && (scope & SearchScope.Person) !== 0));
|
|
4637
|
+
}
|
|
4638
|
+
}
|
|
4639
|
+
/**
|
|
4640
|
+
* The search scope when calling {@link NotificationBot.findMember} and {@link NotificationBot.findAllMembers}.
|
|
4641
|
+
* The search scope is a flagged enum and it can be combined with `|`.
|
|
4642
|
+
* For example, to search from personal chat and group chat, use `SearchScope.Person | SearchScope.Group`.
|
|
4643
|
+
*/
|
|
4644
|
+
var SearchScope;
|
|
4645
|
+
(function (SearchScope) {
|
|
4646
|
+
/**
|
|
4647
|
+
* Search members from the installations in personal chat only.
|
|
4648
|
+
*/
|
|
4649
|
+
SearchScope[SearchScope["Person"] = 1] = "Person";
|
|
4650
|
+
/**
|
|
4651
|
+
* Search members from the installations in group chat only.
|
|
4652
|
+
*/
|
|
4653
|
+
SearchScope[SearchScope["Group"] = 2] = "Group";
|
|
4654
|
+
/**
|
|
4655
|
+
* Search members from the installations in Teams channel only.
|
|
4656
|
+
*/
|
|
4657
|
+
SearchScope[SearchScope["Channel"] = 4] = "Channel";
|
|
4658
|
+
/**
|
|
4659
|
+
* Search members from all installations including personal chat, group chat and Teams channel.
|
|
4660
|
+
*/
|
|
4661
|
+
SearchScope[SearchScope["All"] = 7] = "All";
|
|
4662
|
+
})(SearchScope || (SearchScope = {}));
|
|
4663
|
+
|
|
4664
|
+
// Copyright (c) Microsoft Corporation.
|
|
4665
|
+
/**
|
|
4666
|
+
* Provide utilities for bot conversation, including:
|
|
4667
|
+
* - handle command and response.
|
|
4668
|
+
* - send notification to varies targets (e.g., member, group, channel).
|
|
4669
|
+
*
|
|
4670
|
+
* @example
|
|
4671
|
+
* For command and response, you can register your commands through the constructor, or use the `registerCommand` and `registerCommands` API to add commands later.
|
|
4672
|
+
*
|
|
4673
|
+
* ```typescript
|
|
4674
|
+
* import { BotBuilderCloudAdapter } from "@microsoft/teamsfx";
|
|
4675
|
+
* import ConversationBot = BotBuilderCloudAdapter.ConversationBot;
|
|
4676
|
+
*
|
|
4677
|
+
* // register through constructor
|
|
4678
|
+
* const conversationBot = new ConversationBot({
|
|
4679
|
+
* command: {
|
|
4680
|
+
* enabled: true,
|
|
4681
|
+
* commands: [ new HelloWorldCommandHandler() ],
|
|
4682
|
+
* },
|
|
4683
|
+
* });
|
|
4684
|
+
*
|
|
4685
|
+
* // register through `register*` API
|
|
4686
|
+
* conversationBot.command.registerCommand(new HelpCommandHandler());
|
|
4687
|
+
* ```
|
|
4688
|
+
*
|
|
4689
|
+
* For notification, you can enable notification at initialization, then send notifications at any time.
|
|
4690
|
+
*
|
|
4691
|
+
* ```typescript
|
|
4692
|
+
* import { BotBuilderCloudAdapter } from "@microsoft/teamsfx";
|
|
4693
|
+
* import ConversationBot = BotBuilderCloudAdapter.ConversationBot;
|
|
4694
|
+
*
|
|
4695
|
+
* // enable through constructor
|
|
4696
|
+
* const conversationBot = new ConversationBot({
|
|
4697
|
+
* notification: {
|
|
4698
|
+
* enabled: true,
|
|
4699
|
+
* },
|
|
4700
|
+
* });
|
|
4701
|
+
*
|
|
4702
|
+
* // get all bot installations and send message
|
|
4703
|
+
* for (const target of await conversationBot.notification.installations()) {
|
|
4704
|
+
* await target.sendMessage("Hello Notification");
|
|
4705
|
+
* }
|
|
4706
|
+
*
|
|
4707
|
+
* // alternative - send message to all members
|
|
4708
|
+
* for (const target of await conversationBot.notification.installations()) {
|
|
4709
|
+
* for (const member of await target.members()) {
|
|
4710
|
+
* await member.sendMessage("Hello Notification");
|
|
4711
|
+
* }
|
|
4712
|
+
* }
|
|
4713
|
+
* ```
|
|
4714
|
+
*
|
|
4715
|
+
* @remarks
|
|
4716
|
+
* Set `adapter` in {@link ConversationOptions} to use your own bot adapter.
|
|
4717
|
+
*
|
|
4718
|
+
* For command and response, ensure each command should ONLY be registered with the command once, otherwise it'll cause unexpected behavior if you register the same command more than once.
|
|
4719
|
+
*
|
|
4720
|
+
* For notification, set `notification.storage` in {@link ConversationOptions} to use your own storage implementation.
|
|
4721
|
+
*/
|
|
4722
|
+
class ConversationBot {
|
|
4723
|
+
/**
|
|
4724
|
+
* Create new instance of the `ConversationBot`.
|
|
4725
|
+
*
|
|
4726
|
+
* @remarks
|
|
4727
|
+
* It's recommended to create your own adapter and storage for production environment instead of the default one.
|
|
4728
|
+
*
|
|
4729
|
+
* @param options - The initialize options.
|
|
4730
|
+
*/
|
|
4731
|
+
constructor(options) {
|
|
4732
|
+
var _a, _b, _c, _d;
|
|
4733
|
+
if (options.adapter) {
|
|
4734
|
+
this.adapter = options.adapter;
|
|
4735
|
+
}
|
|
4736
|
+
else {
|
|
4737
|
+
this.adapter = this.createDefaultAdapter(options.adapterConfig);
|
|
4738
|
+
}
|
|
4739
|
+
let ssoCommandActivityHandler;
|
|
4740
|
+
if (options === null || options === void 0 ? void 0 : options.ssoConfig) {
|
|
4741
|
+
if ((_a = options.ssoConfig.dialog) === null || _a === void 0 ? void 0 : _a.CustomBotSsoExecutionActivityHandler) {
|
|
4742
|
+
ssoCommandActivityHandler =
|
|
4743
|
+
new options.ssoConfig.dialog.CustomBotSsoExecutionActivityHandler(options.ssoConfig);
|
|
4744
|
+
}
|
|
4745
|
+
else {
|
|
4746
|
+
ssoCommandActivityHandler = new DefaultBotSsoExecutionActivityHandler(options.ssoConfig);
|
|
4747
|
+
}
|
|
4748
|
+
}
|
|
4749
|
+
if ((_b = options.command) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
4750
|
+
this.command = new CommandBot(this.adapter, options.command, ssoCommandActivityHandler, options.ssoConfig);
|
|
4751
|
+
}
|
|
4752
|
+
if ((_c = options.notification) === null || _c === void 0 ? void 0 : _c.enabled) {
|
|
4753
|
+
this.notification = new NotificationBot(this.adapter, options.notification);
|
|
4754
|
+
}
|
|
4755
|
+
if ((_d = options.cardAction) === null || _d === void 0 ? void 0 : _d.enabled) {
|
|
4756
|
+
this.cardAction = new CardActionBot(this.adapter, options.cardAction);
|
|
4757
|
+
}
|
|
4758
|
+
}
|
|
4759
|
+
createDefaultAdapter(adapterConfig) {
|
|
4760
|
+
const credentialsFactory = adapterConfig === undefined
|
|
4761
|
+
? new ConfigurationServiceClientCredentialFactory({
|
|
4762
|
+
MicrosoftAppId: process.env.BOT_ID,
|
|
4763
|
+
MicrosoftAppPassword: process.env.BOT_PASSWORD,
|
|
4764
|
+
MicrosoftAppType: "MultiTenant",
|
|
4765
|
+
})
|
|
4766
|
+
: new ConfigurationServiceClientCredentialFactory(adapterConfig);
|
|
4767
|
+
const botFrameworkAuthentication = new ConfigurationBotFrameworkAuthentication({}, credentialsFactory);
|
|
4768
|
+
const adapter = new CloudAdapter(botFrameworkAuthentication);
|
|
4769
|
+
// the default error handler
|
|
4770
|
+
adapter.onTurnError = async (context, error) => {
|
|
4771
|
+
// This check writes out errors to console.
|
|
4772
|
+
console.error(`[onTurnError] unhandled error: ${error}`);
|
|
4773
|
+
// Send a trace activity, which will be displayed in Bot Framework Emulator
|
|
4774
|
+
await context.sendTraceActivity("OnTurnError Trace", `${error}`, "https://www.botframework.com/schemas/error", "TurnError");
|
|
4775
|
+
// Send a message to the user
|
|
4776
|
+
await context.sendActivity(`The bot encountered unhandled error: ${error.message}`);
|
|
4777
|
+
await context.sendActivity("To continue to run this bot, please fix the bot source code.");
|
|
4778
|
+
};
|
|
4779
|
+
return adapter;
|
|
4780
|
+
}
|
|
4781
|
+
/**
|
|
4782
|
+
* The request handler to integrate with web request.
|
|
4783
|
+
*
|
|
4784
|
+
* @param req - An incoming HTTP [Request](xref:botbuilder.Request).
|
|
4785
|
+
* @param res - The corresponding HTTP [Response](xref:botbuilder.Response).
|
|
4786
|
+
* @param logic - The additional function to handle bot context.
|
|
4787
|
+
*
|
|
4788
|
+
* @example
|
|
4789
|
+
* For example, to use with Restify:
|
|
4790
|
+
* ``` typescript
|
|
4791
|
+
* // The default/empty behavior
|
|
4792
|
+
* server.use(restify.plugins.bodyParser());
|
|
4793
|
+
* server.post("api/messages", conversationBot.requestHandler);
|
|
4794
|
+
*
|
|
4795
|
+
* // Or, add your own logic
|
|
4796
|
+
* server.use(restify.plugins.bodyParser());
|
|
4797
|
+
* server.post("api/messages", async (req, res) => {
|
|
4798
|
+
* await conversationBot.requestHandler(req, res, async (context) => {
|
|
4799
|
+
* // your-own-context-logic
|
|
4800
|
+
* });
|
|
4801
|
+
* });
|
|
4802
|
+
* ```
|
|
4803
|
+
*/
|
|
4804
|
+
async requestHandler(req, res, logic) {
|
|
4805
|
+
if (logic === undefined) {
|
|
4806
|
+
// create empty logic
|
|
4807
|
+
logic = async () => { };
|
|
4808
|
+
}
|
|
4809
|
+
await this.adapter.process(req, res, logic);
|
|
4810
|
+
}
|
|
4811
|
+
}
|
|
4812
|
+
|
|
4813
|
+
var conversationWithCloudAdapter = /*#__PURE__*/Object.freeze({
|
|
4814
|
+
__proto__: null,
|
|
4815
|
+
ConversationBot: ConversationBot,
|
|
4816
|
+
BotSsoExecutionDialog: BotSsoExecutionDialog,
|
|
4817
|
+
Channel: Channel,
|
|
4818
|
+
Member: Member,
|
|
4819
|
+
NotificationBot: NotificationBot,
|
|
4820
|
+
sendAdaptiveCard: sendAdaptiveCard,
|
|
4821
|
+
sendMessage: sendMessage,
|
|
4822
|
+
TeamsBotInstallation: TeamsBotInstallation,
|
|
4823
|
+
get SearchScope () { return SearchScope; },
|
|
4824
|
+
CommandBot: CommandBot,
|
|
4825
|
+
CardActionBot: CardActionBot
|
|
4826
|
+
});
|
|
4827
|
+
|
|
4828
|
+
export { AdaptiveCardResponse, ApiKeyLocation, ApiKeyProvider, AppCredential, BasicAuthProvider, BearerTokenAuthProvider, conversationWithCloudAdapter as BotBuilderCloudAdapter, BotSsoExecutionDialog, CardActionBot$1 as CardActionBot, CertificateAuthProvider, Channel$1 as Channel, CommandBot$1 as CommandBot, ConversationBot$1 as ConversationBot, ErrorCode, ErrorWithCode, IdentityType, InvokeResponseErrorCode, InvokeResponseFactory, LogLevel, Member$1 as Member, MessageBuilder, MsGraphAuthProvider, NotificationBot$1 as NotificationBot, NotificationTargetType, OnBehalfOfUserCredential, SearchScope$1 as SearchScope, TeamsBotInstallation$1 as TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createMicrosoftGraphClientWithCredential, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, handleMessageExtensionQueryWithSSO, handleMessageExtensionQueryWithToken, sendAdaptiveCard$1 as sendAdaptiveCard, sendMessage$1 as sendMessage, setLogFunction, setLogLevel, setLogger };
|
|
3992
4829
|
//# sourceMappingURL=index.esm2017.mjs.map
|