@microsoft/teamsfx 2.2.1-rc.1 → 2.2.2-alpha.80bb31043.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/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +123 -44
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +131 -44
- package/dist/index.node.cjs.js.map +1 -1
- package/package.json +4 -4
- package/types/teamsfx.d.ts +111 -2
package/dist/index.esm2017.mjs
CHANGED
@@ -2396,6 +2396,13 @@ class CommandBot$1 {
|
|
2396
2396
|
function cloneConversation(conversation) {
|
2397
2397
|
return JSON.parse(JSON.stringify(conversation));
|
2398
2398
|
}
|
2399
|
+
/**
|
2400
|
+
* @internal
|
2401
|
+
*/
|
2402
|
+
function getKey(reference) {
|
2403
|
+
var _a, _b;
|
2404
|
+
return `_${(_a = reference.conversation) === null || _a === void 0 ? void 0 : _a.tenantId}_${(_b = reference.conversation) === null || _b === void 0 ? void 0 : _b.id}`;
|
2405
|
+
}
|
2399
2406
|
/**
|
2400
2407
|
* @internal
|
2401
2408
|
*/
|
@@ -2458,7 +2465,9 @@ class NotificationMiddleware {
|
|
2458
2465
|
case ActivityType.CurrentBotInstalled:
|
2459
2466
|
case ActivityType.TeamRestored: {
|
2460
2467
|
const reference = TurnContext.getConversationReference(context.activity);
|
2461
|
-
await this.conversationReferenceStore.
|
2468
|
+
await this.conversationReferenceStore.add(getKey(reference), reference, {
|
2469
|
+
overwrite: true,
|
2470
|
+
});
|
2462
2471
|
break;
|
2463
2472
|
}
|
2464
2473
|
case ActivityType.CurrentBotMessaged: {
|
@@ -2468,7 +2477,7 @@ class NotificationMiddleware {
|
|
2468
2477
|
case ActivityType.CurrentBotUninstalled:
|
2469
2478
|
case ActivityType.TeamDeleted: {
|
2470
2479
|
const reference = TurnContext.getConversationReference(context.activity);
|
2471
|
-
await this.conversationReferenceStore.
|
2480
|
+
await this.conversationReferenceStore.remove(getKey(reference), reference);
|
2472
2481
|
break;
|
2473
2482
|
}
|
2474
2483
|
}
|
@@ -2505,18 +2514,16 @@ class NotificationMiddleware {
|
|
2505
2514
|
const reference = TurnContext.getConversationReference(context.activity);
|
2506
2515
|
const conversationType = (_a = reference === null || reference === void 0 ? void 0 : reference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
|
2507
2516
|
if (conversationType === "personal" || conversationType === "groupChat") {
|
2508
|
-
|
2509
|
-
await this.conversationReferenceStore.set(reference);
|
2510
|
-
}
|
2517
|
+
await this.conversationReferenceStore.add(getKey(reference), reference, { overwrite: false });
|
2511
2518
|
}
|
2512
2519
|
else if (conversationType === "channel") {
|
2513
2520
|
const teamId = (_d = (_c = (_b = context.activity) === null || _b === void 0 ? void 0 : _b.channelData) === null || _c === void 0 ? void 0 : _c.team) === null || _d === void 0 ? void 0 : _d.id;
|
2514
2521
|
if (teamId !== undefined) {
|
2515
2522
|
const teamReference = cloneConversation(reference);
|
2516
2523
|
teamReference.conversation.id = teamId;
|
2517
|
-
|
2518
|
-
|
2519
|
-
}
|
2524
|
+
await this.conversationReferenceStore.add(getKey(teamReference), teamReference, {
|
2525
|
+
overwrite: false,
|
2526
|
+
});
|
2520
2527
|
}
|
2521
2528
|
}
|
2522
2529
|
}
|
@@ -2618,26 +2625,36 @@ class LocalFileStorage {
|
|
2618
2625
|
/**
|
2619
2626
|
* @internal
|
2620
2627
|
*/
|
2621
|
-
class
|
2628
|
+
class DefaultConversationReferenceStore {
|
2622
2629
|
constructor(storage) {
|
2623
2630
|
this.storage = storage;
|
2624
2631
|
}
|
2625
|
-
async
|
2626
|
-
|
2627
|
-
|
2628
|
-
|
2629
|
-
|
2630
|
-
|
2631
|
-
|
2632
|
-
|
2633
|
-
|
2632
|
+
async add(key, reference, options) {
|
2633
|
+
if (options.overwrite) {
|
2634
|
+
await this.storage.write(key, reference);
|
2635
|
+
return true;
|
2636
|
+
}
|
2637
|
+
const ref = await this.storage.read(key);
|
2638
|
+
if (ref === undefined) {
|
2639
|
+
await this.storage.write(key, reference);
|
2640
|
+
return true;
|
2641
|
+
}
|
2642
|
+
return false;
|
2634
2643
|
}
|
2635
|
-
|
2636
|
-
|
2644
|
+
async remove(key, reference) {
|
2645
|
+
const ref = await this.storage.read(key);
|
2646
|
+
if (ref === undefined) {
|
2647
|
+
return false;
|
2648
|
+
}
|
2649
|
+
await this.storage.delete(key);
|
2650
|
+
return true;
|
2637
2651
|
}
|
2638
|
-
|
2639
|
-
|
2640
|
-
return
|
2652
|
+
async list(pageSize, continuationToken) {
|
2653
|
+
const data = await this.storage.list();
|
2654
|
+
return {
|
2655
|
+
data,
|
2656
|
+
continuationToken: "",
|
2657
|
+
};
|
2641
2658
|
}
|
2642
2659
|
}
|
2643
2660
|
|
@@ -3022,7 +3039,7 @@ class NotificationBot$1 {
|
|
3022
3039
|
constructor(adapter, options) {
|
3023
3040
|
var _a, _b;
|
3024
3041
|
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 : "./" : "./"));
|
3025
|
-
this.conversationReferenceStore = new
|
3042
|
+
this.conversationReferenceStore = new DefaultConversationReferenceStore(storage);
|
3026
3043
|
this.adapter = adapter.use(new NotificationMiddleware({
|
3027
3044
|
conversationReferenceStore: this.conversationReferenceStore,
|
3028
3045
|
}));
|
@@ -3039,7 +3056,7 @@ class NotificationBot$1 {
|
|
3039
3056
|
if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
|
3040
3057
|
throw new Error("NotificationBot has not been initialized.");
|
3041
3058
|
}
|
3042
|
-
const references = await this.conversationReferenceStore.
|
3059
|
+
const { data: references } = await this.conversationReferenceStore.list();
|
3043
3060
|
const targets = [];
|
3044
3061
|
for (const reference of references) {
|
3045
3062
|
// validate connection
|
@@ -3059,7 +3076,7 @@ class NotificationBot$1 {
|
|
3059
3076
|
targets.push(new TeamsBotInstallation$1(this.adapter, reference));
|
3060
3077
|
}
|
3061
3078
|
else {
|
3062
|
-
await this.conversationReferenceStore.
|
3079
|
+
await this.conversationReferenceStore.remove(getKey(reference), reference);
|
3063
3080
|
}
|
3064
3081
|
}
|
3065
3082
|
return targets;
|
@@ -4442,23 +4459,42 @@ class TeamsBotInstallation {
|
|
4442
4459
|
}
|
4443
4460
|
return channels;
|
4444
4461
|
}
|
4462
|
+
/**
|
4463
|
+
* Gets a pagined list of members from this bot installation.
|
4464
|
+
*
|
4465
|
+
* @param pageSize - Suggested number of entries on a page.
|
4466
|
+
* @param continuationToken - A continuation token.
|
4467
|
+
* @returns An array of members from where the bot is installed.
|
4468
|
+
*/
|
4469
|
+
async getPagedMembers(pageSize, continuationToken) {
|
4470
|
+
let result = {
|
4471
|
+
data: [],
|
4472
|
+
continuationToken: "",
|
4473
|
+
};
|
4474
|
+
await this.adapter.continueConversationAsync(this.botAppId, this.conversationReference, async (context) => {
|
4475
|
+
const pagedMembers = await TeamsInfo.getPagedMembers(context, pageSize, continuationToken);
|
4476
|
+
result = {
|
4477
|
+
data: pagedMembers.members.map((m) => new Member(this, m)),
|
4478
|
+
continuationToken: pagedMembers.continuationToken,
|
4479
|
+
};
|
4480
|
+
});
|
4481
|
+
return result;
|
4482
|
+
}
|
4445
4483
|
/**
|
4446
4484
|
* Get members from this bot installation.
|
4447
4485
|
*
|
4448
4486
|
* @returns An array of members from where the bot is installed.
|
4487
|
+
*
|
4488
|
+
* @deprecated Use `getPagedMembers` instead.
|
4449
4489
|
*/
|
4450
4490
|
async members() {
|
4451
4491
|
const members = [];
|
4452
|
-
|
4453
|
-
|
4454
|
-
|
4455
|
-
|
4456
|
-
|
4457
|
-
|
4458
|
-
members.push(new Member(this, member));
|
4459
|
-
}
|
4460
|
-
} while (continuationToken !== undefined);
|
4461
|
-
});
|
4492
|
+
let continuationToken;
|
4493
|
+
do {
|
4494
|
+
const pagedData = await this.getPagedMembers(undefined, continuationToken);
|
4495
|
+
continuationToken = pagedData.continuationToken;
|
4496
|
+
members.push(...pagedData.data);
|
4497
|
+
} while (continuationToken);
|
4462
4498
|
return members;
|
4463
4499
|
}
|
4464
4500
|
/**
|
@@ -4495,28 +4531,48 @@ class NotificationBot {
|
|
4495
4531
|
*/
|
4496
4532
|
constructor(adapter, options) {
|
4497
4533
|
var _a, _b, _c;
|
4498
|
-
|
4499
|
-
|
4534
|
+
if (options === null || options === void 0 ? void 0 : options.store) {
|
4535
|
+
this.conversationReferenceStore = options.store;
|
4536
|
+
}
|
4537
|
+
else {
|
4538
|
+
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 : "./" : "./"));
|
4539
|
+
this.conversationReferenceStore = new DefaultConversationReferenceStore(storage);
|
4540
|
+
}
|
4500
4541
|
this.adapter = adapter.use(new NotificationMiddleware({
|
4501
4542
|
conversationReferenceStore: this.conversationReferenceStore,
|
4502
4543
|
}));
|
4503
4544
|
this.botAppId = ((_c = options === null || options === void 0 ? void 0 : options.botAppId) !== null && _c !== void 0 ? _c : process.env.BOT_ID);
|
4504
4545
|
}
|
4505
4546
|
/**
|
4506
|
-
*
|
4547
|
+
* Create a {@link TeamsBotInstallation} instance with conversation reference.
|
4548
|
+
*
|
4549
|
+
* @param conversationReference - The bound `ConversationReference`.
|
4550
|
+
* @returns - The {@link TeamsBotInstallation} instance or null.
|
4551
|
+
*/
|
4552
|
+
buildTeamsBotInstallation(conversationReference) {
|
4553
|
+
if (!conversationReference) {
|
4554
|
+
throw new Error("conversationReference is required.");
|
4555
|
+
}
|
4556
|
+
return new TeamsBotInstallation(this.adapter, conversationReference, this.botAppId);
|
4557
|
+
}
|
4558
|
+
/**
|
4559
|
+
* Gets a pagined list of targets where the bot is installed.
|
4507
4560
|
*
|
4508
4561
|
* @remarks
|
4509
4562
|
* The result is retrieving from the persisted storage.
|
4510
4563
|
*
|
4511
|
-
* @
|
4564
|
+
* @param pageSize - Suggested number of entries on a page.
|
4565
|
+
* @param continuationToken - A continuation token.
|
4566
|
+
*
|
4567
|
+
* @returns An array of {@link TeamsBotInstallation} with paged data and continuation token.
|
4512
4568
|
*/
|
4513
|
-
async
|
4569
|
+
async getPagedInstallations(pageSize, continuationToken) {
|
4514
4570
|
if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
|
4515
4571
|
throw new Error("NotificationBot has not been initialized.");
|
4516
4572
|
}
|
4517
|
-
const references = await this.conversationReferenceStore.
|
4573
|
+
const references = await this.conversationReferenceStore.list(pageSize, continuationToken);
|
4518
4574
|
const targets = [];
|
4519
|
-
for (const reference of references) {
|
4575
|
+
for (const reference of references.data) {
|
4520
4576
|
// validate connection
|
4521
4577
|
let valid = true;
|
4522
4578
|
await this.adapter.continueConversationAsync(this.botAppId, reference, async (context) => {
|
@@ -4534,9 +4590,32 @@ class NotificationBot {
|
|
4534
4590
|
targets.push(new TeamsBotInstallation(this.adapter, reference, this.botAppId));
|
4535
4591
|
}
|
4536
4592
|
else {
|
4537
|
-
await this.conversationReferenceStore.
|
4593
|
+
await this.conversationReferenceStore.remove(getKey(reference), reference);
|
4538
4594
|
}
|
4539
4595
|
}
|
4596
|
+
return {
|
4597
|
+
data: targets,
|
4598
|
+
continuationToken: references.continuationToken,
|
4599
|
+
};
|
4600
|
+
}
|
4601
|
+
/**
|
4602
|
+
* Get all targets where the bot is installed.
|
4603
|
+
*
|
4604
|
+
* @remarks
|
4605
|
+
* The result is retrieving from the persisted storage.
|
4606
|
+
*
|
4607
|
+
* @returns An array of {@link TeamsBotInstallation}.
|
4608
|
+
*
|
4609
|
+
* @deprecated Use getPagedInstallations instead.
|
4610
|
+
*/
|
4611
|
+
async installations() {
|
4612
|
+
let continuationToken;
|
4613
|
+
const targets = [];
|
4614
|
+
do {
|
4615
|
+
const result = await this.getPagedInstallations(undefined, continuationToken);
|
4616
|
+
continuationToken = result.continuationToken;
|
4617
|
+
targets.push(...result.data);
|
4618
|
+
} while (continuationToken);
|
4540
4619
|
return targets;
|
4541
4620
|
}
|
4542
4621
|
/**
|