@microsoft/teamsfx 2.1.1-alpha.f8e51b9d8.0 → 2.2.0-alpha.07688183f.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 +238 -62
- 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 +6 -5
- package/types/teamsfx.d.ts +623 -10
package/dist/index.node.cjs.js
CHANGED
|
@@ -2072,9 +2072,9 @@ class InvokeResponseFactory {
|
|
|
2072
2072
|
* The type of the invoke response is `application/vnd.microsoft.activity.message`
|
|
2073
2073
|
* indicates the request was successfully processed.
|
|
2074
2074
|
*
|
|
2075
|
-
* @param message A text message included in a invoke response.
|
|
2075
|
+
* @param message - A text message included in a invoke response.
|
|
2076
2076
|
*
|
|
2077
|
-
* @returns
|
|
2077
|
+
* @returns An `InvokeResponse` object.
|
|
2078
2078
|
*/
|
|
2079
2079
|
static textMessage(message) {
|
|
2080
2080
|
if (!message) {
|
|
@@ -2096,9 +2096,9 @@ class InvokeResponseFactory {
|
|
|
2096
2096
|
* the request was successfully processed, and the response includes an adaptive card
|
|
2097
2097
|
* that the client should display in place of the current one.
|
|
2098
2098
|
*
|
|
2099
|
-
* @param card The adaptive card JSON payload.
|
|
2099
|
+
* @param card - The adaptive card JSON payload.
|
|
2100
2100
|
*
|
|
2101
|
-
* @returns
|
|
2101
|
+
* @returns An `InvokeResponse` object.
|
|
2102
2102
|
*/
|
|
2103
2103
|
static adaptiveCard(card) {
|
|
2104
2104
|
if (!card) {
|
|
@@ -2119,12 +2119,12 @@ class InvokeResponseFactory {
|
|
|
2119
2119
|
* The type of the invoke response is `application/vnd.microsoft.error` indicates
|
|
2120
2120
|
* the request was failed to processed.
|
|
2121
2121
|
*
|
|
2122
|
-
* @param errorCode The status code indicates error, available values:
|
|
2122
|
+
* @param errorCode - The status code indicates error, available values:
|
|
2123
2123
|
* - 400 (BadRequest): indicate the incoming request was invalid.
|
|
2124
2124
|
* - 500 (InternalServerError): indicate an unexpected error occurred.
|
|
2125
|
-
* @param errorMessage The error message.
|
|
2125
|
+
* @param errorMessage - The error message.
|
|
2126
2126
|
*
|
|
2127
|
-
* @returns
|
|
2127
|
+
* @returns An `InvokeResponse` object.
|
|
2128
2128
|
*/
|
|
2129
2129
|
static errorResponse(errorCode, errorMessage) {
|
|
2130
2130
|
return {
|
|
@@ -2141,10 +2141,10 @@ class InvokeResponseFactory {
|
|
|
2141
2141
|
}
|
|
2142
2142
|
/**
|
|
2143
2143
|
* Create an invoke response with status code and response value.
|
|
2144
|
-
* @param statusCode The status code.
|
|
2145
|
-
* @param body The value of the response body.
|
|
2144
|
+
* @param statusCode - The status code.
|
|
2145
|
+
* @param body - The value of the response body.
|
|
2146
2146
|
*
|
|
2147
|
-
* @returns
|
|
2147
|
+
* @returns An `InvokeResponse` object.
|
|
2148
2148
|
*/
|
|
2149
2149
|
static createInvokeResponse(statusCode, body) {
|
|
2150
2150
|
return {
|
|
@@ -2236,7 +2236,10 @@ class CardActionMiddleware {
|
|
|
2236
2236
|
/**
|
|
2237
2237
|
* A card action bot to respond to adaptive card universal actions.
|
|
2238
2238
|
*/
|
|
2239
|
-
|
|
2239
|
+
/**
|
|
2240
|
+
* @deprecated Use `BotBuilderCloudAdapter.CardActionBot` instead.
|
|
2241
|
+
*/
|
|
2242
|
+
class CardActionBot$1 {
|
|
2240
2243
|
/**
|
|
2241
2244
|
* Creates a new instance of the `CardActionBot`.
|
|
2242
2245
|
*
|
|
@@ -2394,7 +2397,10 @@ class CommandResponseMiddleware {
|
|
|
2394
2397
|
* @remarks
|
|
2395
2398
|
* 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.
|
|
2396
2399
|
*/
|
|
2397
|
-
|
|
2400
|
+
/**
|
|
2401
|
+
* @deprecated Use `BotBuilderCloudAdapter.CommandBot` instead.
|
|
2402
|
+
*/
|
|
2403
|
+
class CommandBot$1 {
|
|
2398
2404
|
/**
|
|
2399
2405
|
* Creates a new instance of the `CommandBot`.
|
|
2400
2406
|
*
|
|
@@ -2492,7 +2498,7 @@ function getTeamsBotInstallationId(context) {
|
|
|
2492
2498
|
return teamId;
|
|
2493
2499
|
}
|
|
2494
2500
|
// Fallback to use conversation id.
|
|
2495
|
-
//
|
|
2501
|
+
// The conversation id is equal to team id only when the bot app is installed into the General channel.
|
|
2496
2502
|
if (context.activity.conversation.name === undefined) {
|
|
2497
2503
|
return context.activity.conversation.id;
|
|
2498
2504
|
}
|
|
@@ -2734,7 +2740,7 @@ class ConversationReferenceStore {
|
|
|
2734
2740
|
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
2735
2741
|
* @returns the response of sending message.
|
|
2736
2742
|
*/
|
|
2737
|
-
function sendMessage(target, text, onError) {
|
|
2743
|
+
function sendMessage$1(target, text, onError) {
|
|
2738
2744
|
return target.sendMessage(text, onError);
|
|
2739
2745
|
}
|
|
2740
2746
|
/**
|
|
@@ -2746,7 +2752,7 @@ function sendMessage(target, text, onError) {
|
|
|
2746
2752
|
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
2747
2753
|
* @returns the response of sending adaptive card message.
|
|
2748
2754
|
*/
|
|
2749
|
-
function sendAdaptiveCard(target, card, onError) {
|
|
2755
|
+
function sendAdaptiveCard$1(target, card, onError) {
|
|
2750
2756
|
return target.sendAdaptiveCard(card, onError);
|
|
2751
2757
|
}
|
|
2752
2758
|
/**
|
|
@@ -2755,7 +2761,7 @@ function sendAdaptiveCard(target, card, onError) {
|
|
|
2755
2761
|
* @remarks
|
|
2756
2762
|
* It's recommended to get channels from {@link TeamsBotInstallation.channels()}.
|
|
2757
2763
|
*/
|
|
2758
|
-
class Channel {
|
|
2764
|
+
class Channel$1 {
|
|
2759
2765
|
/**
|
|
2760
2766
|
* Constructor.
|
|
2761
2767
|
*
|
|
@@ -2855,7 +2861,7 @@ class Channel {
|
|
|
2855
2861
|
* @remarks
|
|
2856
2862
|
* It's recommended to get members from {@link TeamsBotInstallation.members()}.
|
|
2857
2863
|
*/
|
|
2858
|
-
class Member {
|
|
2864
|
+
class Member$1 {
|
|
2859
2865
|
/**
|
|
2860
2866
|
* Constructor.
|
|
2861
2867
|
*
|
|
@@ -2966,7 +2972,10 @@ class Member {
|
|
|
2966
2972
|
* @remarks
|
|
2967
2973
|
* It's recommended to get bot installations from {@link ConversationBot.installations()}.
|
|
2968
2974
|
*/
|
|
2969
|
-
|
|
2975
|
+
/**
|
|
2976
|
+
* @deprecated Use `BotBuilderCloudAdapter.TeamsBotInstallation` instead.
|
|
2977
|
+
*/
|
|
2978
|
+
class TeamsBotInstallation$1 {
|
|
2970
2979
|
/**
|
|
2971
2980
|
* Constructor
|
|
2972
2981
|
*
|
|
@@ -3058,7 +3067,7 @@ class TeamsBotInstallation {
|
|
|
3058
3067
|
}
|
|
3059
3068
|
}));
|
|
3060
3069
|
for (const channel of teamsChannels) {
|
|
3061
|
-
channels.push(new Channel(this, channel));
|
|
3070
|
+
channels.push(new Channel$1(this, channel));
|
|
3062
3071
|
}
|
|
3063
3072
|
return channels;
|
|
3064
3073
|
});
|
|
@@ -3077,7 +3086,7 @@ class TeamsBotInstallation {
|
|
|
3077
3086
|
const pagedMembers = yield botbuilder.TeamsInfo.getPagedMembers(context, undefined, continuationToken);
|
|
3078
3087
|
continuationToken = pagedMembers.continuationToken;
|
|
3079
3088
|
for (const member of pagedMembers.members) {
|
|
3080
|
-
members.push(new Member(this, member));
|
|
3089
|
+
members.push(new Member$1(this, member));
|
|
3081
3090
|
}
|
|
3082
3091
|
} while (continuationToken !== undefined);
|
|
3083
3092
|
}));
|
|
@@ -3108,7 +3117,10 @@ class TeamsBotInstallation {
|
|
|
3108
3117
|
/**
|
|
3109
3118
|
* Provide utilities to send notification to varies targets (e.g., member, group, channel).
|
|
3110
3119
|
*/
|
|
3111
|
-
|
|
3120
|
+
/**
|
|
3121
|
+
* @deprecated Use `BotBuilderCloudAdapter.NotificationBot` instead.
|
|
3122
|
+
*/
|
|
3123
|
+
class NotificationBot$1 {
|
|
3112
3124
|
/**
|
|
3113
3125
|
* constructor of the notification bot.
|
|
3114
3126
|
*
|
|
@@ -3156,7 +3168,7 @@ class NotificationBot {
|
|
|
3156
3168
|
}
|
|
3157
3169
|
}));
|
|
3158
3170
|
if (valid) {
|
|
3159
|
-
targets.push(new TeamsBotInstallation(this.adapter, reference));
|
|
3171
|
+
targets.push(new TeamsBotInstallation$1(this.adapter, reference));
|
|
3160
3172
|
}
|
|
3161
3173
|
else {
|
|
3162
3174
|
yield this.conversationReferenceStore.delete(reference);
|
|
@@ -3705,7 +3717,10 @@ class DefaultBotSsoExecutionActivityHandler extends botbuilder.TeamsActivityHand
|
|
|
3705
3717
|
*
|
|
3706
3718
|
* For notification, set `notification.storage` in {@link ConversationOptions} to use your own storage implementation.
|
|
3707
3719
|
*/
|
|
3708
|
-
|
|
3720
|
+
/**
|
|
3721
|
+
* @deprecated Use `BotBuilderCloudAdapter.ConversationBot` instead.
|
|
3722
|
+
*/
|
|
3723
|
+
class ConversationBot$1 {
|
|
3709
3724
|
/**
|
|
3710
3725
|
* Creates new instance of the `ConversationBot`.
|
|
3711
3726
|
*
|
|
@@ -3733,13 +3748,13 @@ class ConversationBot {
|
|
|
3733
3748
|
}
|
|
3734
3749
|
}
|
|
3735
3750
|
if ((_b = options.command) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
3736
|
-
this.command = new CommandBot(this.adapter, options.command, ssoCommandActivityHandler, options.ssoConfig);
|
|
3751
|
+
this.command = new CommandBot$1(this.adapter, options.command, ssoCommandActivityHandler, options.ssoConfig);
|
|
3737
3752
|
}
|
|
3738
3753
|
if ((_c = options.notification) === null || _c === void 0 ? void 0 : _c.enabled) {
|
|
3739
|
-
this.notification = new NotificationBot(this.adapter, options.notification);
|
|
3754
|
+
this.notification = new NotificationBot$1(this.adapter, options.notification);
|
|
3740
3755
|
}
|
|
3741
3756
|
if ((_d = options.cardAction) === null || _d === void 0 ? void 0 : _d.enabled) {
|
|
3742
|
-
this.cardAction = new CardActionBot(this.adapter, options.cardAction);
|
|
3757
|
+
this.cardAction = new CardActionBot$1(this.adapter, options.cardAction);
|
|
3743
3758
|
}
|
|
3744
3759
|
}
|
|
3745
3760
|
createDefaultAdapter(adapterConfig) {
|
|
@@ -4140,24 +4155,881 @@ function handleMessageExtensionQueryWithSSO(context, config, initiateLoginEndpoi
|
|
|
4140
4155
|
});
|
|
4141
4156
|
}
|
|
4142
4157
|
|
|
4158
|
+
/**
|
|
4159
|
+
* A card action bot to respond to adaptive card universal actions.
|
|
4160
|
+
*/
|
|
4161
|
+
class CardActionBot {
|
|
4162
|
+
/**
|
|
4163
|
+
* Create a new instance of the `CardActionBot`.
|
|
4164
|
+
*
|
|
4165
|
+
* @param adapter - The bound `CloudAdapter`.
|
|
4166
|
+
* @param options - The initialize options.
|
|
4167
|
+
*/
|
|
4168
|
+
constructor(adapter, options) {
|
|
4169
|
+
this.middleware = new CardActionMiddleware(options === null || options === void 0 ? void 0 : options.actions);
|
|
4170
|
+
this.adapter = adapter.use(this.middleware);
|
|
4171
|
+
}
|
|
4172
|
+
/**
|
|
4173
|
+
* Register a card action handler to the bot.
|
|
4174
|
+
*
|
|
4175
|
+
* @param actionHandler - A card action handler to be registered.
|
|
4176
|
+
*/
|
|
4177
|
+
registerHandler(actionHandler) {
|
|
4178
|
+
if (actionHandler) {
|
|
4179
|
+
this.middleware.actionHandlers.push(actionHandler);
|
|
4180
|
+
}
|
|
4181
|
+
}
|
|
4182
|
+
/**
|
|
4183
|
+
* Register card action handlers to the bot.
|
|
4184
|
+
*
|
|
4185
|
+
* @param actionHandlers - A set of card action handlers to be registered.
|
|
4186
|
+
*/
|
|
4187
|
+
registerHandlers(actionHandlers) {
|
|
4188
|
+
if (actionHandlers) {
|
|
4189
|
+
this.middleware.actionHandlers.push(...actionHandlers);
|
|
4190
|
+
}
|
|
4191
|
+
}
|
|
4192
|
+
}
|
|
4193
|
+
|
|
4194
|
+
// Copyright (c) Microsoft Corporation.
|
|
4195
|
+
/**
|
|
4196
|
+
* A command bot for receiving commands and sending responses in Teams.
|
|
4197
|
+
*
|
|
4198
|
+
* @remarks
|
|
4199
|
+
* 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.
|
|
4200
|
+
*/
|
|
4201
|
+
class CommandBot {
|
|
4202
|
+
// eslint-disable-next-line no-secrets/no-secrets
|
|
4203
|
+
/**
|
|
4204
|
+
* Create a new instance of the `CommandBot`.
|
|
4205
|
+
*
|
|
4206
|
+
* @param adapter - The bound `CloudAdapter`.
|
|
4207
|
+
* @param options - The initialize options
|
|
4208
|
+
* @param ssoCommandActivityHandler - SSO execution activity handler.
|
|
4209
|
+
* @param ssoConfig - SSO configuration for Bot SSO.
|
|
4210
|
+
*/
|
|
4211
|
+
constructor(adapter, options, ssoCommandActivityHandler, ssoConfig) {
|
|
4212
|
+
this.ssoConfig = ssoConfig;
|
|
4213
|
+
this.middleware = new CommandResponseMiddleware(options === null || options === void 0 ? void 0 : options.commands, options === null || options === void 0 ? void 0 : options.ssoCommands, ssoCommandActivityHandler);
|
|
4214
|
+
this.adapter = adapter.use(this.middleware);
|
|
4215
|
+
}
|
|
4216
|
+
/**
|
|
4217
|
+
* Register a command into the command bot.
|
|
4218
|
+
*
|
|
4219
|
+
* @param command - The command to be registered.
|
|
4220
|
+
*/
|
|
4221
|
+
registerCommand(command) {
|
|
4222
|
+
if (command) {
|
|
4223
|
+
this.middleware.commandHandlers.push(command);
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
/**
|
|
4227
|
+
* Register commands into the command bot.
|
|
4228
|
+
*
|
|
4229
|
+
* @param commands - The commands to be registered.
|
|
4230
|
+
*/
|
|
4231
|
+
registerCommands(commands) {
|
|
4232
|
+
if (commands) {
|
|
4233
|
+
this.middleware.commandHandlers.push(...commands);
|
|
4234
|
+
}
|
|
4235
|
+
}
|
|
4236
|
+
/**
|
|
4237
|
+
* Register a sso command into the command bot.
|
|
4238
|
+
*
|
|
4239
|
+
* @param ssoCommand - The sso command to be registered.
|
|
4240
|
+
*/
|
|
4241
|
+
registerSsoCommand(ssoCommand) {
|
|
4242
|
+
this.validateSsoActivityHandler();
|
|
4243
|
+
this.middleware.addSsoCommand(ssoCommand);
|
|
4244
|
+
}
|
|
4245
|
+
/**
|
|
4246
|
+
* Register sso commands into the command bot.
|
|
4247
|
+
*
|
|
4248
|
+
* @param ssoCommands - The sso commands to be registered.
|
|
4249
|
+
*/
|
|
4250
|
+
registerSsoCommands(ssoCommands) {
|
|
4251
|
+
if (ssoCommands.length > 0) {
|
|
4252
|
+
this.validateSsoActivityHandler();
|
|
4253
|
+
for (const ssoCommand of ssoCommands) {
|
|
4254
|
+
this.middleware.addSsoCommand(ssoCommand);
|
|
4255
|
+
}
|
|
4256
|
+
}
|
|
4257
|
+
}
|
|
4258
|
+
validateSsoActivityHandler() {
|
|
4259
|
+
if (!this.middleware.ssoActivityHandler) {
|
|
4260
|
+
internalLogger.error(ErrorMessage.SsoActivityHandlerIsNull);
|
|
4261
|
+
throw new ErrorWithCode(ErrorMessage.SsoActivityHandlerIsNull, exports.ErrorCode.SsoActivityHandlerIsUndefined);
|
|
4262
|
+
}
|
|
4263
|
+
}
|
|
4264
|
+
}
|
|
4265
|
+
|
|
4266
|
+
// Copyright (c) Microsoft Corporation.
|
|
4267
|
+
/**
|
|
4268
|
+
* Send a plain text message to a notification target.
|
|
4269
|
+
*
|
|
4270
|
+
* @param target - The notification target.
|
|
4271
|
+
* @param text - The plain text message.
|
|
4272
|
+
* @param onError - An optional error handler that can catch exceptions during message sending.
|
|
4273
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4274
|
+
*
|
|
4275
|
+
* @returns The response of sending message.
|
|
4276
|
+
*/
|
|
4277
|
+
function sendMessage(target, text, onError) {
|
|
4278
|
+
return target.sendMessage(text, onError);
|
|
4279
|
+
}
|
|
4280
|
+
/**
|
|
4281
|
+
* Send an adaptive card message to a notification target.
|
|
4282
|
+
*
|
|
4283
|
+
* @param target - The notification target.
|
|
4284
|
+
* @param card - The adaptive card raw JSON.
|
|
4285
|
+
* @param onError - An optional error handler that can catch exceptions during adaptive card sending.
|
|
4286
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4287
|
+
*
|
|
4288
|
+
* @returns The response of sending adaptive card message.
|
|
4289
|
+
*/
|
|
4290
|
+
function sendAdaptiveCard(target, card, onError) {
|
|
4291
|
+
return target.sendAdaptiveCard(card, onError);
|
|
4292
|
+
}
|
|
4293
|
+
/**
|
|
4294
|
+
* A {@link NotificationTarget} that represents a team channel.
|
|
4295
|
+
*
|
|
4296
|
+
* @remarks
|
|
4297
|
+
* It's recommended to get channels from {@link TeamsBotInstallation.channels()}.
|
|
4298
|
+
*/
|
|
4299
|
+
class Channel {
|
|
4300
|
+
/**
|
|
4301
|
+
* Constructor.
|
|
4302
|
+
*
|
|
4303
|
+
* @remarks
|
|
4304
|
+
* It's recommended to get channels from {@link TeamsBotInstallation.channels()}, instead of using this constructor.
|
|
4305
|
+
*
|
|
4306
|
+
* @param parent - The parent {@link TeamsBotInstallation} where this channel is created from.
|
|
4307
|
+
* @param info - Detailed channel information.
|
|
4308
|
+
*/
|
|
4309
|
+
constructor(parent, info) {
|
|
4310
|
+
/**
|
|
4311
|
+
* Notification target type. For channel it's always "Channel".
|
|
4312
|
+
*/
|
|
4313
|
+
this.type = exports.NotificationTargetType.Channel;
|
|
4314
|
+
this.parent = parent;
|
|
4315
|
+
this.info = info;
|
|
4316
|
+
}
|
|
4317
|
+
/**
|
|
4318
|
+
* Send a plain text message.
|
|
4319
|
+
*
|
|
4320
|
+
* @param text - The plain text message.
|
|
4321
|
+
* @param onError - An optional error handler that can catch exceptions during message sending.
|
|
4322
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4323
|
+
*
|
|
4324
|
+
* @returns The response of sending message.
|
|
4325
|
+
*/
|
|
4326
|
+
sendMessage(text, onError) {
|
|
4327
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4328
|
+
const response = {};
|
|
4329
|
+
yield this.parent.adapter.continueConversationAsync(this.parent.botAppId, this.parent.conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4330
|
+
const conversation = yield this.newConversation(context);
|
|
4331
|
+
yield this.parent.adapter.continueConversationAsync(this.parent.botAppId, conversation, (ctx) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4332
|
+
try {
|
|
4333
|
+
const res = yield ctx.sendActivity(text);
|
|
4334
|
+
response.id = res === null || res === void 0 ? void 0 : res.id;
|
|
4335
|
+
}
|
|
4336
|
+
catch (error) {
|
|
4337
|
+
if (onError) {
|
|
4338
|
+
yield onError(ctx, error);
|
|
4339
|
+
}
|
|
4340
|
+
else {
|
|
4341
|
+
throw error;
|
|
4342
|
+
}
|
|
4343
|
+
}
|
|
4344
|
+
}));
|
|
4345
|
+
}));
|
|
4346
|
+
return response;
|
|
4347
|
+
});
|
|
4348
|
+
}
|
|
4349
|
+
/**
|
|
4350
|
+
* Send an adaptive card message.
|
|
4351
|
+
*
|
|
4352
|
+
* @param card - The adaptive card raw JSON.
|
|
4353
|
+
* @param onError - An optional error handler that can catch exceptions during adaptive card sending.
|
|
4354
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4355
|
+
*
|
|
4356
|
+
* @returns The response of sending adaptive card message.
|
|
4357
|
+
*/
|
|
4358
|
+
sendAdaptiveCard(card, onError) {
|
|
4359
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4360
|
+
const response = {};
|
|
4361
|
+
yield this.parent.adapter.continueConversationAsync(this.parent.botAppId, this.parent.conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4362
|
+
const conversation = yield this.newConversation(context);
|
|
4363
|
+
yield this.parent.adapter.continueConversationAsync(this.parent.botAppId, conversation, (ctx) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4364
|
+
try {
|
|
4365
|
+
const res = yield ctx.sendActivity({
|
|
4366
|
+
attachments: [botbuilder.CardFactory.adaptiveCard(card)],
|
|
4367
|
+
});
|
|
4368
|
+
response.id = res === null || res === void 0 ? void 0 : res.id;
|
|
4369
|
+
}
|
|
4370
|
+
catch (error) {
|
|
4371
|
+
if (onError) {
|
|
4372
|
+
yield onError(ctx, error);
|
|
4373
|
+
}
|
|
4374
|
+
else {
|
|
4375
|
+
throw error;
|
|
4376
|
+
}
|
|
4377
|
+
}
|
|
4378
|
+
}));
|
|
4379
|
+
}));
|
|
4380
|
+
return response;
|
|
4381
|
+
});
|
|
4382
|
+
}
|
|
4383
|
+
/**
|
|
4384
|
+
* @internal
|
|
4385
|
+
*/
|
|
4386
|
+
newConversation(context) {
|
|
4387
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4388
|
+
const reference = botbuilder.TurnContext.getConversationReference(context.activity);
|
|
4389
|
+
const channelConversation = cloneConversation(reference);
|
|
4390
|
+
channelConversation.conversation.id = this.info.id || "";
|
|
4391
|
+
return channelConversation;
|
|
4392
|
+
});
|
|
4393
|
+
}
|
|
4394
|
+
}
|
|
4395
|
+
/**
|
|
4396
|
+
* A {@link NotificationTarget} that represents a team member.
|
|
4397
|
+
*
|
|
4398
|
+
* @remarks
|
|
4399
|
+
* It's recommended to get members from {@link TeamsBotInstallation.members()}.
|
|
4400
|
+
*/
|
|
4401
|
+
class Member {
|
|
4402
|
+
/**
|
|
4403
|
+
* Constructor.
|
|
4404
|
+
*
|
|
4405
|
+
* @remarks
|
|
4406
|
+
* It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
|
|
4407
|
+
*
|
|
4408
|
+
* @param parent - The parent {@link TeamsBotInstallation} where this member is created from.
|
|
4409
|
+
* @param account - Detailed member account information.
|
|
4410
|
+
*/
|
|
4411
|
+
constructor(parent, account) {
|
|
4412
|
+
/**
|
|
4413
|
+
* Notification target type. For member it's always "Person".
|
|
4414
|
+
*/
|
|
4415
|
+
this.type = exports.NotificationTargetType.Person;
|
|
4416
|
+
this.parent = parent;
|
|
4417
|
+
this.account = account;
|
|
4418
|
+
}
|
|
4419
|
+
/**
|
|
4420
|
+
* Send a plain text message.
|
|
4421
|
+
*
|
|
4422
|
+
* @param text - The plain text message.
|
|
4423
|
+
* @param onError - An optional error handler that can catch exceptions during message sending.
|
|
4424
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4425
|
+
*
|
|
4426
|
+
* @returns The response of sending message.
|
|
4427
|
+
*/
|
|
4428
|
+
sendMessage(text, onError) {
|
|
4429
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4430
|
+
const response = {};
|
|
4431
|
+
yield this.parent.adapter.continueConversationAsync(this.parent.botAppId, this.parent.conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4432
|
+
const conversation = yield this.newConversation(context);
|
|
4433
|
+
yield this.parent.adapter.continueConversationAsync(this.parent.botAppId, conversation, (ctx) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4434
|
+
try {
|
|
4435
|
+
const res = yield ctx.sendActivity(text);
|
|
4436
|
+
response.id = res === null || res === void 0 ? void 0 : res.id;
|
|
4437
|
+
}
|
|
4438
|
+
catch (error) {
|
|
4439
|
+
if (onError) {
|
|
4440
|
+
yield onError(ctx, error);
|
|
4441
|
+
}
|
|
4442
|
+
else {
|
|
4443
|
+
throw error;
|
|
4444
|
+
}
|
|
4445
|
+
}
|
|
4446
|
+
}));
|
|
4447
|
+
}));
|
|
4448
|
+
return response;
|
|
4449
|
+
});
|
|
4450
|
+
}
|
|
4451
|
+
/**
|
|
4452
|
+
* Send an adaptive card message.
|
|
4453
|
+
*
|
|
4454
|
+
* @param card - The adaptive card raw JSON.
|
|
4455
|
+
* @param onError - An optional error handler that can catch exceptions during adaptive card sending.
|
|
4456
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4457
|
+
*
|
|
4458
|
+
* @returns The response of sending adaptive card message.
|
|
4459
|
+
*/
|
|
4460
|
+
sendAdaptiveCard(card, onError) {
|
|
4461
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4462
|
+
const response = {};
|
|
4463
|
+
yield this.parent.adapter.continueConversationAsync(this.parent.botAppId, this.parent.conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4464
|
+
const conversation = yield this.newConversation(context);
|
|
4465
|
+
yield this.parent.adapter.continueConversationAsync(this.parent.botAppId, conversation, (ctx) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4466
|
+
try {
|
|
4467
|
+
const res = yield ctx.sendActivity({
|
|
4468
|
+
attachments: [botbuilder.CardFactory.adaptiveCard(card)],
|
|
4469
|
+
});
|
|
4470
|
+
response.id = res === null || res === void 0 ? void 0 : res.id;
|
|
4471
|
+
}
|
|
4472
|
+
catch (error) {
|
|
4473
|
+
if (onError) {
|
|
4474
|
+
yield onError(ctx, error);
|
|
4475
|
+
}
|
|
4476
|
+
else {
|
|
4477
|
+
throw error;
|
|
4478
|
+
}
|
|
4479
|
+
}
|
|
4480
|
+
}));
|
|
4481
|
+
}));
|
|
4482
|
+
return response;
|
|
4483
|
+
});
|
|
4484
|
+
}
|
|
4485
|
+
/**
|
|
4486
|
+
* @internal
|
|
4487
|
+
*/
|
|
4488
|
+
newConversation(context) {
|
|
4489
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4490
|
+
const reference = botbuilder.TurnContext.getConversationReference(context.activity);
|
|
4491
|
+
const personalConversation = cloneConversation(reference);
|
|
4492
|
+
const connectorClient = context.turnState.get(this.parent.adapter.ConnectorClientKey);
|
|
4493
|
+
const conversation = yield connectorClient.conversations.createConversation({
|
|
4494
|
+
isGroup: false,
|
|
4495
|
+
tenantId: context.activity.conversation.tenantId,
|
|
4496
|
+
bot: context.activity.recipient,
|
|
4497
|
+
members: [this.account],
|
|
4498
|
+
channelData: {},
|
|
4499
|
+
});
|
|
4500
|
+
personalConversation.conversation.id = conversation.id;
|
|
4501
|
+
return personalConversation;
|
|
4502
|
+
});
|
|
4503
|
+
}
|
|
4504
|
+
}
|
|
4505
|
+
/**
|
|
4506
|
+
* A {@link NotificationTarget} that represents a bot installation. Teams Bot could be installed into
|
|
4507
|
+
* - Personal chat
|
|
4508
|
+
* - Group chat
|
|
4509
|
+
* - Team (by default the `General` channel)
|
|
4510
|
+
*
|
|
4511
|
+
* @remarks
|
|
4512
|
+
* It's recommended to get bot installations from {@link ConversationBot.installations()}.
|
|
4513
|
+
*/
|
|
4514
|
+
class TeamsBotInstallation {
|
|
4515
|
+
/**
|
|
4516
|
+
* Constructor
|
|
4517
|
+
*
|
|
4518
|
+
* @remarks
|
|
4519
|
+
* It's recommended to get bot installations from {@link ConversationBot.installations()}, instead of using this constructor.
|
|
4520
|
+
*
|
|
4521
|
+
* @param adapter - The bound `CloudAdapter`.
|
|
4522
|
+
* @param conversationReference - The bound `ConversationReference`.
|
|
4523
|
+
* @param botAppId - The bot app id.
|
|
4524
|
+
*/
|
|
4525
|
+
constructor(adapter, conversationReference, botAppId) {
|
|
4526
|
+
this.adapter = adapter;
|
|
4527
|
+
this.conversationReference = conversationReference;
|
|
4528
|
+
this.type = getTargetType(conversationReference);
|
|
4529
|
+
this.botAppId = botAppId;
|
|
4530
|
+
}
|
|
4531
|
+
/**
|
|
4532
|
+
* Send a plain text message.
|
|
4533
|
+
*
|
|
4534
|
+
* @param text - The plain text message.
|
|
4535
|
+
* @param onError - An optional error handler that can catch exceptions during message sending.
|
|
4536
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4537
|
+
*
|
|
4538
|
+
* @returns The response of sending message.
|
|
4539
|
+
*/
|
|
4540
|
+
sendMessage(text, onError) {
|
|
4541
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4542
|
+
const response = {};
|
|
4543
|
+
yield this.adapter.continueConversationAsync(this.botAppId, this.conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4544
|
+
try {
|
|
4545
|
+
const res = yield context.sendActivity(text);
|
|
4546
|
+
response.id = res === null || res === void 0 ? void 0 : res.id;
|
|
4547
|
+
}
|
|
4548
|
+
catch (error) {
|
|
4549
|
+
if (onError) {
|
|
4550
|
+
yield onError(context, error);
|
|
4551
|
+
}
|
|
4552
|
+
else {
|
|
4553
|
+
throw error;
|
|
4554
|
+
}
|
|
4555
|
+
}
|
|
4556
|
+
}));
|
|
4557
|
+
return response;
|
|
4558
|
+
});
|
|
4559
|
+
}
|
|
4560
|
+
/**
|
|
4561
|
+
* Send an adaptive card message.
|
|
4562
|
+
*
|
|
4563
|
+
* @param card - The adaptive card raw JSON.
|
|
4564
|
+
* @param onError - An optional error handler that can catch exceptions during adaptive card sending.
|
|
4565
|
+
* If not defined, error will be handled by `BotAdapter.onTurnError`.
|
|
4566
|
+
*
|
|
4567
|
+
* @returns The response of sending adaptive card message.
|
|
4568
|
+
*/
|
|
4569
|
+
sendAdaptiveCard(card, onError) {
|
|
4570
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4571
|
+
const response = {};
|
|
4572
|
+
yield this.adapter.continueConversationAsync(this.botAppId, this.conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4573
|
+
try {
|
|
4574
|
+
const res = yield context.sendActivity({
|
|
4575
|
+
attachments: [botbuilder.CardFactory.adaptiveCard(card)],
|
|
4576
|
+
});
|
|
4577
|
+
response.id = res === null || res === void 0 ? void 0 : res.id;
|
|
4578
|
+
}
|
|
4579
|
+
catch (error) {
|
|
4580
|
+
if (onError) {
|
|
4581
|
+
yield onError(context, error);
|
|
4582
|
+
}
|
|
4583
|
+
else {
|
|
4584
|
+
throw error;
|
|
4585
|
+
}
|
|
4586
|
+
}
|
|
4587
|
+
}));
|
|
4588
|
+
return response;
|
|
4589
|
+
});
|
|
4590
|
+
}
|
|
4591
|
+
/**
|
|
4592
|
+
* Get channels from this bot installation.
|
|
4593
|
+
*
|
|
4594
|
+
* @returns An array of channels if bot is installed into a team, otherwise returns an empty array.
|
|
4595
|
+
*/
|
|
4596
|
+
channels() {
|
|
4597
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4598
|
+
const channels = [];
|
|
4599
|
+
if (this.type !== exports.NotificationTargetType.Channel) {
|
|
4600
|
+
return channels;
|
|
4601
|
+
}
|
|
4602
|
+
let teamsChannels = [];
|
|
4603
|
+
yield this.adapter.continueConversationAsync(this.botAppId, this.conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4604
|
+
const teamId = getTeamsBotInstallationId(context);
|
|
4605
|
+
if (teamId !== undefined) {
|
|
4606
|
+
teamsChannels = yield botbuilder.TeamsInfo.getTeamChannels(context, teamId);
|
|
4607
|
+
}
|
|
4608
|
+
}));
|
|
4609
|
+
for (const channel of teamsChannels) {
|
|
4610
|
+
channels.push(new Channel(this, channel));
|
|
4611
|
+
}
|
|
4612
|
+
return channels;
|
|
4613
|
+
});
|
|
4614
|
+
}
|
|
4615
|
+
/**
|
|
4616
|
+
* Get members from this bot installation.
|
|
4617
|
+
*
|
|
4618
|
+
* @returns An array of members from where the bot is installed.
|
|
4619
|
+
*/
|
|
4620
|
+
members() {
|
|
4621
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4622
|
+
const members = [];
|
|
4623
|
+
yield this.adapter.continueConversationAsync(this.botAppId, this.conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4624
|
+
let continuationToken;
|
|
4625
|
+
do {
|
|
4626
|
+
const pagedMembers = yield botbuilder.TeamsInfo.getPagedMembers(context, undefined, continuationToken);
|
|
4627
|
+
continuationToken = pagedMembers.continuationToken;
|
|
4628
|
+
for (const member of pagedMembers.members) {
|
|
4629
|
+
members.push(new Member(this, member));
|
|
4630
|
+
}
|
|
4631
|
+
} while (continuationToken !== undefined);
|
|
4632
|
+
}));
|
|
4633
|
+
return members;
|
|
4634
|
+
});
|
|
4635
|
+
}
|
|
4636
|
+
/**
|
|
4637
|
+
* Get team details from this bot installation
|
|
4638
|
+
*
|
|
4639
|
+
* @returns The team details if bot is installed into a team, otherwise returns `undefined`.
|
|
4640
|
+
*/
|
|
4641
|
+
getTeamDetails() {
|
|
4642
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4643
|
+
if (this.type !== exports.NotificationTargetType.Channel) {
|
|
4644
|
+
return undefined;
|
|
4645
|
+
}
|
|
4646
|
+
let teamDetails;
|
|
4647
|
+
yield this.adapter.continueConversationAsync(this.botAppId, this.conversationReference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4648
|
+
const teamId = getTeamsBotInstallationId(context);
|
|
4649
|
+
if (teamId !== undefined) {
|
|
4650
|
+
teamDetails = yield botbuilder.TeamsInfo.getTeamDetails(context, teamId);
|
|
4651
|
+
}
|
|
4652
|
+
}));
|
|
4653
|
+
return teamDetails;
|
|
4654
|
+
});
|
|
4655
|
+
}
|
|
4656
|
+
}
|
|
4657
|
+
/**
|
|
4658
|
+
* Provide utilities to send notification to varies targets (e.g., member, group, channel).
|
|
4659
|
+
*/
|
|
4660
|
+
class NotificationBot {
|
|
4661
|
+
/**
|
|
4662
|
+
* Constructor of the notification bot.
|
|
4663
|
+
*
|
|
4664
|
+
* @remarks
|
|
4665
|
+
* To ensure accuracy, it's recommended to initialize before handling any message.
|
|
4666
|
+
*
|
|
4667
|
+
* @param adapter - The bound `CloudAdapter`
|
|
4668
|
+
* @param options - The initialize options
|
|
4669
|
+
*/
|
|
4670
|
+
constructor(adapter, options) {
|
|
4671
|
+
var _a, _b, _c;
|
|
4672
|
+
const storage = (_a = options === null || options === void 0 ? void 0 : options.storage) !== null && _a !== void 0 ? _a : new LocalFileStorage(path__namespace.resolve(process.env.RUNNING_ON_AZURE === "1" ? (_b = process.env.TEMP) !== null && _b !== void 0 ? _b : "./" : "./"));
|
|
4673
|
+
this.conversationReferenceStore = new ConversationReferenceStore(storage);
|
|
4674
|
+
this.adapter = adapter.use(new NotificationMiddleware({
|
|
4675
|
+
conversationReferenceStore: this.conversationReferenceStore,
|
|
4676
|
+
}));
|
|
4677
|
+
this.botAppId = ((_c = options === null || options === void 0 ? void 0 : options.botAppId) !== null && _c !== void 0 ? _c : process.env.BOT_ID);
|
|
4678
|
+
}
|
|
4679
|
+
/**
|
|
4680
|
+
* Get all targets where the bot is installed.
|
|
4681
|
+
*
|
|
4682
|
+
* @remarks
|
|
4683
|
+
* The result is retrieving from the persisted storage.
|
|
4684
|
+
*
|
|
4685
|
+
* @returns An array of {@link TeamsBotInstallation}.
|
|
4686
|
+
*/
|
|
4687
|
+
installations() {
|
|
4688
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4689
|
+
if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
|
|
4690
|
+
throw new Error("NotificationBot has not been initialized.");
|
|
4691
|
+
}
|
|
4692
|
+
const references = yield this.conversationReferenceStore.getAll();
|
|
4693
|
+
const targets = [];
|
|
4694
|
+
for (const reference of references) {
|
|
4695
|
+
// validate connection
|
|
4696
|
+
let valid = true;
|
|
4697
|
+
yield this.adapter.continueConversationAsync(this.botAppId, reference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4698
|
+
try {
|
|
4699
|
+
// try get member to see if the installation is still valid
|
|
4700
|
+
yield botbuilder.TeamsInfo.getPagedMembers(context, 1);
|
|
4701
|
+
}
|
|
4702
|
+
catch (error) {
|
|
4703
|
+
if (error.code === "BotNotInConversationRoster") {
|
|
4704
|
+
valid = false;
|
|
4705
|
+
}
|
|
4706
|
+
}
|
|
4707
|
+
}));
|
|
4708
|
+
if (valid) {
|
|
4709
|
+
targets.push(new TeamsBotInstallation(this.adapter, reference, this.botAppId));
|
|
4710
|
+
}
|
|
4711
|
+
else {
|
|
4712
|
+
yield this.conversationReferenceStore.delete(reference);
|
|
4713
|
+
}
|
|
4714
|
+
}
|
|
4715
|
+
return targets;
|
|
4716
|
+
});
|
|
4717
|
+
}
|
|
4718
|
+
/**
|
|
4719
|
+
* Return the first {@link Member} where predicate is true, and undefined otherwise.
|
|
4720
|
+
*
|
|
4721
|
+
* @param predicate - Find calls predicate once for each member of the installation,
|
|
4722
|
+
* until it finds one where predicate returns true. If such a member is found, find
|
|
4723
|
+
* immediately returns that member. Otherwise, find returns undefined.
|
|
4724
|
+
* @param scope - The scope to find members from the installations
|
|
4725
|
+
* (personal chat, group chat, Teams channel).
|
|
4726
|
+
*
|
|
4727
|
+
* @returns The first {@link Member} where predicate is true, and `undefined` otherwise.
|
|
4728
|
+
*/
|
|
4729
|
+
findMember(predicate, scope) {
|
|
4730
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4731
|
+
for (const target of yield this.installations()) {
|
|
4732
|
+
if (this.matchSearchScope(target, scope)) {
|
|
4733
|
+
for (const member of yield target.members()) {
|
|
4734
|
+
if (yield predicate(member)) {
|
|
4735
|
+
return member;
|
|
4736
|
+
}
|
|
4737
|
+
}
|
|
4738
|
+
}
|
|
4739
|
+
}
|
|
4740
|
+
return;
|
|
4741
|
+
});
|
|
4742
|
+
}
|
|
4743
|
+
/**
|
|
4744
|
+
* Return the first {@link Channel} where predicate is true, and undefined otherwise.
|
|
4745
|
+
* (Ensure the bot app is installed into the `General` channel, otherwise undefined will be returned.)
|
|
4746
|
+
*
|
|
4747
|
+
* @param predicate - Find calls predicate once for each channel of the installation,
|
|
4748
|
+
* until it finds one where predicate returns true. If such a channel is found, find
|
|
4749
|
+
* immediately returns that channel. Otherwise, find returns `undefined`.
|
|
4750
|
+
*
|
|
4751
|
+
* @returns The first {@link Channel} where predicate is true, and `undefined` otherwise.
|
|
4752
|
+
*/
|
|
4753
|
+
findChannel(predicate) {
|
|
4754
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4755
|
+
for (const target of yield this.installations()) {
|
|
4756
|
+
if (target.type === exports.NotificationTargetType.Channel) {
|
|
4757
|
+
const teamDetails = yield target.getTeamDetails();
|
|
4758
|
+
for (const channel of yield target.channels()) {
|
|
4759
|
+
if (yield predicate(channel, teamDetails)) {
|
|
4760
|
+
return channel;
|
|
4761
|
+
}
|
|
4762
|
+
}
|
|
4763
|
+
}
|
|
4764
|
+
}
|
|
4765
|
+
return;
|
|
4766
|
+
});
|
|
4767
|
+
}
|
|
4768
|
+
/**
|
|
4769
|
+
* Return all {@link Member} where predicate is true, and empty array otherwise.
|
|
4770
|
+
*
|
|
4771
|
+
* @param predicate - Find calls predicate for each member of the installation.
|
|
4772
|
+
* @param scope - The scope to find members from the installations
|
|
4773
|
+
* (personal chat, group chat, Teams channel).
|
|
4774
|
+
*
|
|
4775
|
+
* @returns An array of {@link Member} where predicate is true, and empty array otherwise.
|
|
4776
|
+
*/
|
|
4777
|
+
findAllMembers(predicate, scope) {
|
|
4778
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4779
|
+
const members = [];
|
|
4780
|
+
for (const target of yield this.installations()) {
|
|
4781
|
+
if (this.matchSearchScope(target, scope)) {
|
|
4782
|
+
for (const member of yield target.members()) {
|
|
4783
|
+
if (yield predicate(member)) {
|
|
4784
|
+
members.push(member);
|
|
4785
|
+
}
|
|
4786
|
+
}
|
|
4787
|
+
}
|
|
4788
|
+
}
|
|
4789
|
+
return members;
|
|
4790
|
+
});
|
|
4791
|
+
}
|
|
4792
|
+
/**
|
|
4793
|
+
* Return all {@link Channel} where predicate is true, and empty array otherwise.
|
|
4794
|
+
* (Ensure the bot app is installed into the `General` channel, otherwise empty array will be returned.)
|
|
4795
|
+
*
|
|
4796
|
+
* @param predicate - Find calls predicate for each channel of the installation.
|
|
4797
|
+
*
|
|
4798
|
+
* @returns An array of {@link Channel} where predicate is true, and empty array otherwise.
|
|
4799
|
+
*/
|
|
4800
|
+
findAllChannels(predicate) {
|
|
4801
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4802
|
+
const channels = [];
|
|
4803
|
+
for (const target of yield this.installations()) {
|
|
4804
|
+
if (target.type === exports.NotificationTargetType.Channel) {
|
|
4805
|
+
const teamDetails = yield target.getTeamDetails();
|
|
4806
|
+
for (const channel of yield target.channels()) {
|
|
4807
|
+
if (yield predicate(channel, teamDetails)) {
|
|
4808
|
+
channels.push(channel);
|
|
4809
|
+
}
|
|
4810
|
+
}
|
|
4811
|
+
}
|
|
4812
|
+
}
|
|
4813
|
+
return channels;
|
|
4814
|
+
});
|
|
4815
|
+
}
|
|
4816
|
+
matchSearchScope(target, scope) {
|
|
4817
|
+
scope = scope !== null && scope !== void 0 ? scope : SearchScope.All;
|
|
4818
|
+
return ((target.type === exports.NotificationTargetType.Channel && (scope & SearchScope.Channel) !== 0) ||
|
|
4819
|
+
(target.type === exports.NotificationTargetType.Group && (scope & SearchScope.Group) !== 0) ||
|
|
4820
|
+
(target.type === exports.NotificationTargetType.Person && (scope & SearchScope.Person) !== 0));
|
|
4821
|
+
}
|
|
4822
|
+
}
|
|
4823
|
+
/**
|
|
4824
|
+
* The search scope when calling {@link NotificationBot.findMember} and {@link NotificationBot.findAllMembers}.
|
|
4825
|
+
* The search scope is a flagged enum and it can be combined with `|`.
|
|
4826
|
+
* For example, to search from personal chat and group chat, use `SearchScope.Person | SearchScope.Group`.
|
|
4827
|
+
*/
|
|
4828
|
+
var SearchScope;
|
|
4829
|
+
(function (SearchScope) {
|
|
4830
|
+
/**
|
|
4831
|
+
* Search members from the installations in personal chat only.
|
|
4832
|
+
*/
|
|
4833
|
+
SearchScope[SearchScope["Person"] = 1] = "Person";
|
|
4834
|
+
/**
|
|
4835
|
+
* Search members from the installations in group chat only.
|
|
4836
|
+
*/
|
|
4837
|
+
SearchScope[SearchScope["Group"] = 2] = "Group";
|
|
4838
|
+
/**
|
|
4839
|
+
* Search members from the installations in Teams channel only.
|
|
4840
|
+
*/
|
|
4841
|
+
SearchScope[SearchScope["Channel"] = 4] = "Channel";
|
|
4842
|
+
/**
|
|
4843
|
+
* Search members from all installations including personal chat, group chat and Teams channel.
|
|
4844
|
+
*/
|
|
4845
|
+
SearchScope[SearchScope["All"] = 7] = "All";
|
|
4846
|
+
})(SearchScope || (SearchScope = {}));
|
|
4847
|
+
|
|
4848
|
+
// Copyright (c) Microsoft Corporation.
|
|
4849
|
+
/**
|
|
4850
|
+
* Provide utilities for bot conversation, including:
|
|
4851
|
+
* - handle command and response.
|
|
4852
|
+
* - send notification to varies targets (e.g., member, group, channel).
|
|
4853
|
+
*
|
|
4854
|
+
* @example
|
|
4855
|
+
* For command and response, you can register your commands through the constructor, or use the `registerCommand` and `registerCommands` API to add commands later.
|
|
4856
|
+
*
|
|
4857
|
+
* ```typescript
|
|
4858
|
+
* import { BotBuilderCloudAdapter } from "@microsoft/teamsfx";
|
|
4859
|
+
* import ConversationBot = BotBuilderCloudAdapter.ConversationBot;
|
|
4860
|
+
*
|
|
4861
|
+
* // register through constructor
|
|
4862
|
+
* const conversationBot = new ConversationBot({
|
|
4863
|
+
* command: {
|
|
4864
|
+
* enabled: true,
|
|
4865
|
+
* commands: [ new HelloWorldCommandHandler() ],
|
|
4866
|
+
* },
|
|
4867
|
+
* });
|
|
4868
|
+
*
|
|
4869
|
+
* // register through `register*` API
|
|
4870
|
+
* conversationBot.command.registerCommand(new HelpCommandHandler());
|
|
4871
|
+
* ```
|
|
4872
|
+
*
|
|
4873
|
+
* For notification, you can enable notification at initialization, then send notifications at any time.
|
|
4874
|
+
*
|
|
4875
|
+
* ```typescript
|
|
4876
|
+
* import { BotBuilderCloudAdapter } from "@microsoft/teamsfx";
|
|
4877
|
+
* import ConversationBot = BotBuilderCloudAdapter.ConversationBot;
|
|
4878
|
+
*
|
|
4879
|
+
* // enable through constructor
|
|
4880
|
+
* const conversationBot = new ConversationBot({
|
|
4881
|
+
* notification: {
|
|
4882
|
+
* enabled: true,
|
|
4883
|
+
* },
|
|
4884
|
+
* });
|
|
4885
|
+
*
|
|
4886
|
+
* // get all bot installations and send message
|
|
4887
|
+
* for (const target of await conversationBot.notification.installations()) {
|
|
4888
|
+
* await target.sendMessage("Hello Notification");
|
|
4889
|
+
* }
|
|
4890
|
+
*
|
|
4891
|
+
* // alternative - send message to all members
|
|
4892
|
+
* for (const target of await conversationBot.notification.installations()) {
|
|
4893
|
+
* for (const member of await target.members()) {
|
|
4894
|
+
* await member.sendMessage("Hello Notification");
|
|
4895
|
+
* }
|
|
4896
|
+
* }
|
|
4897
|
+
* ```
|
|
4898
|
+
*
|
|
4899
|
+
* @remarks
|
|
4900
|
+
* Set `adapter` in {@link ConversationOptions} to use your own bot adapter.
|
|
4901
|
+
*
|
|
4902
|
+
* 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.
|
|
4903
|
+
*
|
|
4904
|
+
* For notification, set `notification.storage` in {@link ConversationOptions} to use your own storage implementation.
|
|
4905
|
+
*/
|
|
4906
|
+
class ConversationBot {
|
|
4907
|
+
/**
|
|
4908
|
+
* Create new instance of the `ConversationBot`.
|
|
4909
|
+
*
|
|
4910
|
+
* @remarks
|
|
4911
|
+
* It's recommended to create your own adapter and storage for production environment instead of the default one.
|
|
4912
|
+
*
|
|
4913
|
+
* @param options - The initialize options.
|
|
4914
|
+
*/
|
|
4915
|
+
constructor(options) {
|
|
4916
|
+
var _a, _b, _c, _d;
|
|
4917
|
+
if (options.adapter) {
|
|
4918
|
+
this.adapter = options.adapter;
|
|
4919
|
+
}
|
|
4920
|
+
else {
|
|
4921
|
+
this.adapter = this.createDefaultAdapter(options.adapterConfig);
|
|
4922
|
+
}
|
|
4923
|
+
let ssoCommandActivityHandler;
|
|
4924
|
+
if (options === null || options === void 0 ? void 0 : options.ssoConfig) {
|
|
4925
|
+
if ((_a = options.ssoConfig.dialog) === null || _a === void 0 ? void 0 : _a.CustomBotSsoExecutionActivityHandler) {
|
|
4926
|
+
ssoCommandActivityHandler =
|
|
4927
|
+
new options.ssoConfig.dialog.CustomBotSsoExecutionActivityHandler(options.ssoConfig);
|
|
4928
|
+
}
|
|
4929
|
+
else {
|
|
4930
|
+
ssoCommandActivityHandler = new DefaultBotSsoExecutionActivityHandler(options.ssoConfig);
|
|
4931
|
+
}
|
|
4932
|
+
}
|
|
4933
|
+
if ((_b = options.command) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
4934
|
+
this.command = new CommandBot(this.adapter, options.command, ssoCommandActivityHandler, options.ssoConfig);
|
|
4935
|
+
}
|
|
4936
|
+
if ((_c = options.notification) === null || _c === void 0 ? void 0 : _c.enabled) {
|
|
4937
|
+
this.notification = new NotificationBot(this.adapter, options.notification);
|
|
4938
|
+
}
|
|
4939
|
+
if ((_d = options.cardAction) === null || _d === void 0 ? void 0 : _d.enabled) {
|
|
4940
|
+
this.cardAction = new CardActionBot(this.adapter, options.cardAction);
|
|
4941
|
+
}
|
|
4942
|
+
}
|
|
4943
|
+
createDefaultAdapter(adapterConfig) {
|
|
4944
|
+
const credentialsFactory = adapterConfig === undefined
|
|
4945
|
+
? new botbuilder.ConfigurationServiceClientCredentialFactory({
|
|
4946
|
+
MicrosoftAppId: process.env.BOT_ID,
|
|
4947
|
+
MicrosoftAppPassword: process.env.BOT_PASSWORD,
|
|
4948
|
+
MicrosoftAppType: "MultiTenant",
|
|
4949
|
+
})
|
|
4950
|
+
: new botbuilder.ConfigurationServiceClientCredentialFactory(adapterConfig);
|
|
4951
|
+
const botFrameworkAuthentication = new botbuilder.ConfigurationBotFrameworkAuthentication({}, credentialsFactory);
|
|
4952
|
+
const adapter = new botbuilder.CloudAdapter(botFrameworkAuthentication);
|
|
4953
|
+
// the default error handler
|
|
4954
|
+
adapter.onTurnError = (context, error) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4955
|
+
// This check writes out errors to console.
|
|
4956
|
+
console.error(`[onTurnError] unhandled error: ${error}`);
|
|
4957
|
+
// Send a trace activity, which will be displayed in Bot Framework Emulator
|
|
4958
|
+
yield context.sendTraceActivity("OnTurnError Trace", `${error}`, "https://www.botframework.com/schemas/error", "TurnError");
|
|
4959
|
+
// Send a message to the user
|
|
4960
|
+
yield context.sendActivity(`The bot encountered unhandled error: ${error.message}`);
|
|
4961
|
+
yield context.sendActivity("To continue to run this bot, please fix the bot source code.");
|
|
4962
|
+
});
|
|
4963
|
+
return adapter;
|
|
4964
|
+
}
|
|
4965
|
+
/**
|
|
4966
|
+
* The request handler to integrate with web request.
|
|
4967
|
+
*
|
|
4968
|
+
* @param req - An incoming HTTP [Request](xref:botbuilder.Request).
|
|
4969
|
+
* @param res - The corresponding HTTP [Response](xref:botbuilder.Response).
|
|
4970
|
+
* @param logic - The additional function to handle bot context.
|
|
4971
|
+
*
|
|
4972
|
+
* @example
|
|
4973
|
+
* For example, to use with Restify:
|
|
4974
|
+
* ``` typescript
|
|
4975
|
+
* // The default/empty behavior
|
|
4976
|
+
* server.use(restify.plugins.bodyParser());
|
|
4977
|
+
* server.post("api/messages", conversationBot.requestHandler);
|
|
4978
|
+
*
|
|
4979
|
+
* // Or, add your own logic
|
|
4980
|
+
* server.use(restify.plugins.bodyParser());
|
|
4981
|
+
* server.post("api/messages", async (req, res) => {
|
|
4982
|
+
* await conversationBot.requestHandler(req, res, async (context) => {
|
|
4983
|
+
* // your-own-context-logic
|
|
4984
|
+
* });
|
|
4985
|
+
* });
|
|
4986
|
+
* ```
|
|
4987
|
+
*/
|
|
4988
|
+
requestHandler(req, res, logic) {
|
|
4989
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
4990
|
+
if (logic === undefined) {
|
|
4991
|
+
// create empty logic
|
|
4992
|
+
logic = () => tslib.__awaiter(this, void 0, void 0, function* () { });
|
|
4993
|
+
}
|
|
4994
|
+
yield this.adapter.process(req, res, logic);
|
|
4995
|
+
});
|
|
4996
|
+
}
|
|
4997
|
+
}
|
|
4998
|
+
|
|
4999
|
+
var conversationWithCloudAdapter = /*#__PURE__*/Object.freeze({
|
|
5000
|
+
__proto__: null,
|
|
5001
|
+
ConversationBot: ConversationBot,
|
|
5002
|
+
BotSsoExecutionDialog: BotSsoExecutionDialog,
|
|
5003
|
+
Channel: Channel,
|
|
5004
|
+
Member: Member,
|
|
5005
|
+
NotificationBot: NotificationBot,
|
|
5006
|
+
sendAdaptiveCard: sendAdaptiveCard,
|
|
5007
|
+
sendMessage: sendMessage,
|
|
5008
|
+
TeamsBotInstallation: TeamsBotInstallation,
|
|
5009
|
+
get SearchScope () { return SearchScope; },
|
|
5010
|
+
CommandBot: CommandBot,
|
|
5011
|
+
CardActionBot: CardActionBot
|
|
5012
|
+
});
|
|
5013
|
+
|
|
4143
5014
|
exports.ApiKeyProvider = ApiKeyProvider;
|
|
4144
5015
|
exports.AppCredential = AppCredential;
|
|
4145
5016
|
exports.BasicAuthProvider = BasicAuthProvider;
|
|
4146
5017
|
exports.BearerTokenAuthProvider = BearerTokenAuthProvider;
|
|
5018
|
+
exports.BotBuilderCloudAdapter = conversationWithCloudAdapter;
|
|
4147
5019
|
exports.BotSsoExecutionDialog = BotSsoExecutionDialog;
|
|
4148
|
-
exports.CardActionBot = CardActionBot;
|
|
5020
|
+
exports.CardActionBot = CardActionBot$1;
|
|
4149
5021
|
exports.CertificateAuthProvider = CertificateAuthProvider;
|
|
4150
|
-
exports.Channel = Channel;
|
|
4151
|
-
exports.CommandBot = CommandBot;
|
|
4152
|
-
exports.ConversationBot = ConversationBot;
|
|
5022
|
+
exports.Channel = Channel$1;
|
|
5023
|
+
exports.CommandBot = CommandBot$1;
|
|
5024
|
+
exports.ConversationBot = ConversationBot$1;
|
|
4153
5025
|
exports.ErrorWithCode = ErrorWithCode;
|
|
4154
5026
|
exports.InvokeResponseFactory = InvokeResponseFactory;
|
|
4155
|
-
exports.Member = Member;
|
|
5027
|
+
exports.Member = Member$1;
|
|
4156
5028
|
exports.MessageBuilder = MessageBuilder;
|
|
4157
5029
|
exports.MsGraphAuthProvider = MsGraphAuthProvider;
|
|
4158
|
-
exports.NotificationBot = NotificationBot;
|
|
5030
|
+
exports.NotificationBot = NotificationBot$1;
|
|
4159
5031
|
exports.OnBehalfOfUserCredential = OnBehalfOfUserCredential;
|
|
4160
|
-
exports.TeamsBotInstallation = TeamsBotInstallation;
|
|
5032
|
+
exports.TeamsBotInstallation = TeamsBotInstallation$1;
|
|
4161
5033
|
exports.TeamsBotSsoPrompt = TeamsBotSsoPrompt;
|
|
4162
5034
|
exports.TeamsFx = TeamsFx;
|
|
4163
5035
|
exports.TeamsUserCredential = TeamsUserCredential;
|
|
@@ -4170,8 +5042,8 @@ exports.getLogLevel = getLogLevel;
|
|
|
4170
5042
|
exports.getTediousConnectionConfig = getTediousConnectionConfig;
|
|
4171
5043
|
exports.handleMessageExtensionQueryWithSSO = handleMessageExtensionQueryWithSSO;
|
|
4172
5044
|
exports.handleMessageExtensionQueryWithToken = handleMessageExtensionQueryWithToken;
|
|
4173
|
-
exports.sendAdaptiveCard = sendAdaptiveCard;
|
|
4174
|
-
exports.sendMessage = sendMessage;
|
|
5045
|
+
exports.sendAdaptiveCard = sendAdaptiveCard$1;
|
|
5046
|
+
exports.sendMessage = sendMessage$1;
|
|
4175
5047
|
exports.setLogFunction = setLogFunction;
|
|
4176
5048
|
exports.setLogLevel = setLogLevel;
|
|
4177
5049
|
exports.setLogger = setLogger;
|