@microsoft/teamsfx 0.7.1-beta.adb483893.0 → 1.0.0-beta.ea516ab4c.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.
@@ -10,6 +10,7 @@ import axios from 'axios';
10
10
  import { Agent } from 'https';
11
11
  import * as path from 'path';
12
12
  import * as fs from 'fs';
13
+ import { AdaptiveCards } from '@microsoft/adaptivecards-tools';
13
14
 
14
15
  // Copyright (c) Microsoft Corporation.
15
16
  // Licensed under the MIT license.
@@ -1902,6 +1903,41 @@ class TeamsFx {
1902
1903
  }
1903
1904
  }
1904
1905
 
1906
+ // Copyright (c) Microsoft Corporation.
1907
+ // Licensed under the MIT license.
1908
+ /**
1909
+ * @internal
1910
+ */
1911
+ function cloneConversation(conversation) {
1912
+ return JSON.parse(JSON.stringify(conversation));
1913
+ }
1914
+ /**
1915
+ * @internal
1916
+ */
1917
+ function getTargetType(conversationReference) {
1918
+ var _a;
1919
+ const conversationType = (_a = conversationReference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
1920
+ if (conversationType === "personal") {
1921
+ return "Person";
1922
+ }
1923
+ else if (conversationType === "groupChat") {
1924
+ return "Group";
1925
+ }
1926
+ else if (conversationType === "channel") {
1927
+ return "Channel";
1928
+ }
1929
+ else {
1930
+ return undefined;
1931
+ }
1932
+ }
1933
+ /**
1934
+ * @internal
1935
+ */
1936
+ function getTeamsBotInstallationId(context) {
1937
+ var _a, _b, _c, _d;
1938
+ 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;
1939
+ }
1940
+
1905
1941
  // Copyright (c) Microsoft Corporation.
1906
1942
  /**
1907
1943
  * @internal
@@ -1931,6 +1967,10 @@ class NotificationMiddleware {
1931
1967
  await this.conversationReferenceStore.set(reference);
1932
1968
  break;
1933
1969
  }
1970
+ case ActivityType.CurrentBotMessaged: {
1971
+ await this.tryAddMessagedReference(context);
1972
+ break;
1973
+ }
1934
1974
  case ActivityType.CurrentBotUninstalled:
1935
1975
  case ActivityType.TeamDeleted: {
1936
1976
  const reference = TurnContext.getConversationReference(context.activity);
@@ -1961,8 +2001,31 @@ class NotificationMiddleware {
1961
2001
  return ActivityType.TeamRestored;
1962
2002
  }
1963
2003
  }
2004
+ else if (activityType === "message") {
2005
+ return ActivityType.CurrentBotMessaged;
2006
+ }
1964
2007
  return ActivityType.Unknown;
1965
2008
  }
2009
+ async tryAddMessagedReference(context) {
2010
+ var _a, _b, _c, _d;
2011
+ const reference = TurnContext.getConversationReference(context.activity);
2012
+ const conversationType = (_a = reference === null || reference === void 0 ? void 0 : reference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
2013
+ if (conversationType === "personal" || conversationType === "groupChat") {
2014
+ if (!(await this.conversationReferenceStore.check(reference))) {
2015
+ await this.conversationReferenceStore.set(reference);
2016
+ }
2017
+ }
2018
+ else if (conversationType === "channel") {
2019
+ 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;
2020
+ if (teamId !== undefined) {
2021
+ const teamReference = cloneConversation(reference);
2022
+ teamReference.conversation.id = teamId;
2023
+ if (!(await this.conversationReferenceStore.check(teamReference))) {
2024
+ await this.conversationReferenceStore.set(teamReference);
2025
+ }
2026
+ }
2027
+ }
2028
+ }
1966
2029
  }
1967
2030
  class CommandResponseMiddleware {
1968
2031
  constructor(handlers) {
@@ -1972,35 +2035,33 @@ class CommandResponseMiddleware {
1972
2035
  }
1973
2036
  }
1974
2037
  async onTurn(context, next) {
1975
- const type = this.classifyActivity(context.activity);
1976
- switch (type) {
1977
- case ActivityType.CurrentBotMessaged:
1978
- // Invoke corresponding command handler for the command response
1979
- const commandText = this.getActivityText(context.activity);
1980
- const message = {
1981
- text: commandText,
1982
- };
1983
- for (const handler of this.commandHandlers) {
1984
- const matchResult = this.shouldTrigger(handler.triggerPatterns, commandText);
1985
- // It is important to note that the command bot will stop processing handlers
1986
- // when the first command handler is matched.
1987
- if (!!matchResult) {
1988
- message.matches = Array.isArray(matchResult) ? matchResult : void 0;
1989
- const response = await handler.handleCommandReceived(context, message);
2038
+ if (context.activity.type === ActivityTypes.Message) {
2039
+ // Invoke corresponding command handler for the command response
2040
+ const commandText = this.getActivityText(context.activity);
2041
+ const message = {
2042
+ text: commandText,
2043
+ };
2044
+ for (const handler of this.commandHandlers) {
2045
+ const matchResult = this.shouldTrigger(handler.triggerPatterns, commandText);
2046
+ // It is important to note that the command bot will stop processing handlers
2047
+ // when the first command handler is matched.
2048
+ if (!!matchResult) {
2049
+ message.matches = Array.isArray(matchResult) ? matchResult : void 0;
2050
+ const response = await handler.handleCommandReceived(context, message);
2051
+ if (typeof response === "string") {
1990
2052
  await context.sendActivity(response);
1991
- break;
2053
+ }
2054
+ else {
2055
+ const replyActivity = response;
2056
+ if (replyActivity) {
2057
+ await context.sendActivity(replyActivity);
2058
+ }
1992
2059
  }
1993
2060
  }
1994
- break;
2061
+ }
1995
2062
  }
1996
2063
  await next();
1997
2064
  }
1998
- classifyActivity(activity) {
1999
- if (activity.type === ActivityTypes.Message) {
2000
- return ActivityType.CurrentBotMessaged;
2001
- }
2002
- return ActivityType.Unknown;
2003
- }
2004
2065
  matchPattern(pattern, text) {
2005
2066
  if (text) {
2006
2067
  if (typeof pattern === "string") {
@@ -2203,41 +2264,6 @@ class ConversationReferenceStore {
2203
2264
  }
2204
2265
  }
2205
2266
 
2206
- // Copyright (c) Microsoft Corporation.
2207
- // Licensed under the MIT license.
2208
- /**
2209
- * @internal
2210
- */
2211
- function cloneConversation(conversation) {
2212
- return Object.assign({}, conversation);
2213
- }
2214
- /**
2215
- * @internal
2216
- */
2217
- function getTargetType(conversationReference) {
2218
- var _a;
2219
- const conversationType = (_a = conversationReference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
2220
- if (conversationType === "personal") {
2221
- return "Person";
2222
- }
2223
- else if (conversationType === "groupChat") {
2224
- return "Group";
2225
- }
2226
- else if (conversationType === "channel") {
2227
- return "Channel";
2228
- }
2229
- else {
2230
- return undefined;
2231
- }
2232
- }
2233
- /**
2234
- * @internal
2235
- */
2236
- function getTeamsBotInstallationId(context) {
2237
- var _a, _b, _c, _d;
2238
- 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;
2239
- }
2240
-
2241
2267
  // Copyright (c) Microsoft Corporation.
2242
2268
  /**
2243
2269
  * Send a plain text message to a notification target.
@@ -2273,7 +2299,7 @@ function sendAdaptiveCard(target, card) {
2273
2299
  */
2274
2300
  class Channel {
2275
2301
  /**
2276
- * Constuctor.
2302
+ * Constructor.
2277
2303
  *
2278
2304
  * @remarks
2279
2305
  * It's recommended to get channels from {@link TeamsBotInstallation.channels()}, instead of using this constructor.
@@ -2347,7 +2373,7 @@ class Channel {
2347
2373
  */
2348
2374
  class Member {
2349
2375
  /**
2350
- * Constuctor.
2376
+ * Constructor.
2351
2377
  *
2352
2378
  * @remarks
2353
2379
  * It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
@@ -2557,12 +2583,12 @@ class NotificationBot {
2557
2583
  if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
2558
2584
  throw new Error("NotificationBot has not been initialized.");
2559
2585
  }
2560
- const references = (await this.conversationReferenceStore.getAll()).values();
2586
+ const references = await this.conversationReferenceStore.getAll();
2561
2587
  const targets = [];
2562
2588
  for (const reference of references) {
2563
2589
  // validate connection
2564
2590
  let valid = true;
2565
- this.adapter.continueConversation(reference, async (context) => {
2591
+ await this.adapter.continueConversation(reference, async (context) => {
2566
2592
  try {
2567
2593
  // try get member to see if the installation is still valid
2568
2594
  await TeamsInfo.getPagedMembers(context, 1);
@@ -2577,7 +2603,7 @@ class NotificationBot {
2577
2603
  targets.push(new TeamsBotInstallation(this.adapter, reference));
2578
2604
  }
2579
2605
  else {
2580
- this.conversationReferenceStore.delete(reference);
2606
+ await this.conversationReferenceStore.delete(reference);
2581
2607
  }
2582
2608
  }
2583
2609
  return targets;
@@ -2716,7 +2742,6 @@ class ConversationBot {
2716
2742
  }
2717
2743
 
2718
2744
  // Copyright (c) Microsoft Corporation.
2719
- const { AdaptiveCards } = require("@microsoft/adaptivecards-tools");
2720
2745
  /**
2721
2746
  * Provides utility method to build bot message with cards that supported in Teams.
2722
2747
  */