@microsoft/teamsfx 0.7.1-beta.c23501411.0 → 0.7.1-beta.dc88fcdc0.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.
@@ -1902,6 +1902,41 @@ class TeamsFx {
1902
1902
  }
1903
1903
  }
1904
1904
 
1905
+ // Copyright (c) Microsoft Corporation.
1906
+ // Licensed under the MIT license.
1907
+ /**
1908
+ * @internal
1909
+ */
1910
+ function cloneConversation(conversation) {
1911
+ return JSON.parse(JSON.stringify(conversation));
1912
+ }
1913
+ /**
1914
+ * @internal
1915
+ */
1916
+ function getTargetType(conversationReference) {
1917
+ var _a;
1918
+ const conversationType = (_a = conversationReference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
1919
+ if (conversationType === "personal") {
1920
+ return "Person";
1921
+ }
1922
+ else if (conversationType === "groupChat") {
1923
+ return "Group";
1924
+ }
1925
+ else if (conversationType === "channel") {
1926
+ return "Channel";
1927
+ }
1928
+ else {
1929
+ return undefined;
1930
+ }
1931
+ }
1932
+ /**
1933
+ * @internal
1934
+ */
1935
+ function getTeamsBotInstallationId(context) {
1936
+ var _a, _b, _c, _d;
1937
+ return (_d = (_c = (_b = (_a = context.activity) === null || _a === void 0 ? void 0 : _a.channelData) === null || _b === void 0 ? void 0 : _b.team) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : context.activity.conversation.id;
1938
+ }
1939
+
1905
1940
  // Copyright (c) Microsoft Corporation.
1906
1941
  /**
1907
1942
  * @internal
@@ -1931,6 +1966,10 @@ class NotificationMiddleware {
1931
1966
  await this.conversationReferenceStore.set(reference);
1932
1967
  break;
1933
1968
  }
1969
+ case ActivityType.CurrentBotMessaged: {
1970
+ await this.tryAddMessagedReference(context);
1971
+ break;
1972
+ }
1934
1973
  case ActivityType.CurrentBotUninstalled:
1935
1974
  case ActivityType.TeamDeleted: {
1936
1975
  const reference = TurnContext.getConversationReference(context.activity);
@@ -1961,8 +2000,31 @@ class NotificationMiddleware {
1961
2000
  return ActivityType.TeamRestored;
1962
2001
  }
1963
2002
  }
2003
+ else if (activityType === "message") {
2004
+ return ActivityType.CurrentBotMessaged;
2005
+ }
1964
2006
  return ActivityType.Unknown;
1965
2007
  }
2008
+ async tryAddMessagedReference(context) {
2009
+ var _a, _b, _c, _d;
2010
+ const reference = TurnContext.getConversationReference(context.activity);
2011
+ const conversationType = (_a = reference === null || reference === void 0 ? void 0 : reference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
2012
+ if (conversationType === "personal" || conversationType === "groupChat") {
2013
+ if (!(await this.conversationReferenceStore.check(reference))) {
2014
+ await this.conversationReferenceStore.set(reference);
2015
+ }
2016
+ }
2017
+ else if (conversationType === "channel") {
2018
+ 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;
2019
+ if (teamId !== undefined) {
2020
+ const teamReference = cloneConversation(reference);
2021
+ teamReference.conversation.id = teamId;
2022
+ if (!(await this.conversationReferenceStore.check(teamReference))) {
2023
+ await this.conversationReferenceStore.set(teamReference);
2024
+ }
2025
+ }
2026
+ }
2027
+ }
1966
2028
  }
1967
2029
  class CommandResponseMiddleware {
1968
2030
  constructor(handlers) {
@@ -2201,41 +2263,6 @@ class ConversationReferenceStore {
2201
2263
  }
2202
2264
  }
2203
2265
 
2204
- // Copyright (c) Microsoft Corporation.
2205
- // Licensed under the MIT license.
2206
- /**
2207
- * @internal
2208
- */
2209
- function cloneConversation(conversation) {
2210
- return Object.assign({}, conversation);
2211
- }
2212
- /**
2213
- * @internal
2214
- */
2215
- function getTargetType(conversationReference) {
2216
- var _a;
2217
- const conversationType = (_a = conversationReference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
2218
- if (conversationType === "personal") {
2219
- return "Person";
2220
- }
2221
- else if (conversationType === "groupChat") {
2222
- return "Group";
2223
- }
2224
- else if (conversationType === "channel") {
2225
- return "Channel";
2226
- }
2227
- else {
2228
- return undefined;
2229
- }
2230
- }
2231
- /**
2232
- * @internal
2233
- */
2234
- function getTeamsBotInstallationId(context) {
2235
- var _a, _b, _c, _d;
2236
- return (_d = (_c = (_b = (_a = context.activity) === null || _a === void 0 ? void 0 : _a.channelData) === null || _b === void 0 ? void 0 : _b.team) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : context.activity.conversation.id;
2237
- }
2238
-
2239
2266
  // Copyright (c) Microsoft Corporation.
2240
2267
  /**
2241
2268
  * Send a plain text message to a notification target.
@@ -2555,12 +2582,12 @@ class NotificationBot {
2555
2582
  if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
2556
2583
  throw new Error("NotificationBot has not been initialized.");
2557
2584
  }
2558
- const references = (await this.conversationReferenceStore.getAll()).values();
2585
+ const references = await this.conversationReferenceStore.getAll();
2559
2586
  const targets = [];
2560
2587
  for (const reference of references) {
2561
2588
  // validate connection
2562
2589
  let valid = true;
2563
- this.adapter.continueConversation(reference, async (context) => {
2590
+ await this.adapter.continueConversation(reference, async (context) => {
2564
2591
  try {
2565
2592
  // try get member to see if the installation is still valid
2566
2593
  await TeamsInfo.getPagedMembers(context, 1);
@@ -2575,7 +2602,7 @@ class NotificationBot {
2575
2602
  targets.push(new TeamsBotInstallation(this.adapter, reference));
2576
2603
  }
2577
2604
  else {
2578
- this.conversationReferenceStore.delete(reference);
2605
+ await this.conversationReferenceStore.delete(reference);
2579
2606
  }
2580
2607
  }
2581
2608
  return targets;