@microsoft/teamsfx 0.6.3-beta.08b0a4e6b.0 → 0.7.0-beta.1

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.
@@ -15,6 +15,7 @@ var axios = require('axios');
15
15
  var https = require('https');
16
16
  var path = require('path');
17
17
  var fs = require('fs');
18
+ var adaptivecardsTools = require('@microsoft/adaptivecards-tools');
18
19
 
19
20
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
21
 
@@ -1968,6 +1969,41 @@ class TeamsFx {
1968
1969
  }
1969
1970
  }
1970
1971
 
1972
+ // Copyright (c) Microsoft Corporation.
1973
+ // Licensed under the MIT license.
1974
+ /**
1975
+ * @internal
1976
+ */
1977
+ function cloneConversation(conversation) {
1978
+ return JSON.parse(JSON.stringify(conversation));
1979
+ }
1980
+ /**
1981
+ * @internal
1982
+ */
1983
+ function getTargetType(conversationReference) {
1984
+ var _a;
1985
+ const conversationType = (_a = conversationReference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
1986
+ if (conversationType === "personal") {
1987
+ return "Person";
1988
+ }
1989
+ else if (conversationType === "groupChat") {
1990
+ return "Group";
1991
+ }
1992
+ else if (conversationType === "channel") {
1993
+ return "Channel";
1994
+ }
1995
+ else {
1996
+ return undefined;
1997
+ }
1998
+ }
1999
+ /**
2000
+ * @internal
2001
+ */
2002
+ function getTeamsBotInstallationId(context) {
2003
+ var _a, _b, _c, _d;
2004
+ 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;
2005
+ }
2006
+
1971
2007
  // Copyright (c) Microsoft Corporation.
1972
2008
  /**
1973
2009
  * @internal
@@ -1998,6 +2034,10 @@ class NotificationMiddleware {
1998
2034
  yield this.conversationReferenceStore.set(reference);
1999
2035
  break;
2000
2036
  }
2037
+ case ActivityType.CurrentBotMessaged: {
2038
+ yield this.tryAddMessagedReference(context);
2039
+ break;
2040
+ }
2001
2041
  case ActivityType.CurrentBotUninstalled:
2002
2042
  case ActivityType.TeamDeleted: {
2003
2043
  const reference = botbuilder.TurnContext.getConversationReference(context.activity);
@@ -2029,8 +2069,33 @@ class NotificationMiddleware {
2029
2069
  return ActivityType.TeamRestored;
2030
2070
  }
2031
2071
  }
2072
+ else if (activityType === "message") {
2073
+ return ActivityType.CurrentBotMessaged;
2074
+ }
2032
2075
  return ActivityType.Unknown;
2033
2076
  }
2077
+ tryAddMessagedReference(context) {
2078
+ var _a, _b, _c, _d;
2079
+ return tslib.__awaiter(this, void 0, void 0, function* () {
2080
+ const reference = botbuilder.TurnContext.getConversationReference(context.activity);
2081
+ const conversationType = (_a = reference === null || reference === void 0 ? void 0 : reference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
2082
+ if (conversationType === "personal" || conversationType === "groupChat") {
2083
+ if (!(yield this.conversationReferenceStore.check(reference))) {
2084
+ yield this.conversationReferenceStore.set(reference);
2085
+ }
2086
+ }
2087
+ else if (conversationType === "channel") {
2088
+ 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;
2089
+ if (teamId !== undefined) {
2090
+ const teamReference = cloneConversation(reference);
2091
+ teamReference.conversation.id = teamId;
2092
+ if (!(yield this.conversationReferenceStore.check(teamReference))) {
2093
+ yield this.conversationReferenceStore.set(teamReference);
2094
+ }
2095
+ }
2096
+ }
2097
+ });
2098
+ }
2034
2099
  }
2035
2100
  class CommandResponseMiddleware {
2036
2101
  constructor(handlers) {
@@ -2041,36 +2106,34 @@ class CommandResponseMiddleware {
2041
2106
  }
2042
2107
  onTurn(context, next) {
2043
2108
  return tslib.__awaiter(this, void 0, void 0, function* () {
2044
- const type = this.classifyActivity(context.activity);
2045
- switch (type) {
2046
- case ActivityType.CurrentBotMessaged:
2047
- // Invoke corresponding command handler for the command response
2048
- const commandText = this.getActivityText(context.activity);
2049
- const message = {
2050
- text: commandText,
2051
- };
2052
- for (const handler of this.commandHandlers) {
2053
- const matchResult = this.shouldTrigger(handler.triggerPatterns, commandText);
2054
- // It is important to note that the command bot will stop processing handlers
2055
- // when the first command handler is matched.
2056
- if (!!matchResult) {
2057
- message.matches = Array.isArray(matchResult) ? matchResult : void 0;
2058
- const response = yield handler.handleCommandReceived(context, message);
2109
+ if (context.activity.type === botbuilder.ActivityTypes.Message) {
2110
+ // Invoke corresponding command handler for the command response
2111
+ const commandText = this.getActivityText(context.activity);
2112
+ const message = {
2113
+ text: commandText,
2114
+ };
2115
+ for (const handler of this.commandHandlers) {
2116
+ const matchResult = this.shouldTrigger(handler.triggerPatterns, commandText);
2117
+ // It is important to note that the command bot will stop processing handlers
2118
+ // when the first command handler is matched.
2119
+ if (!!matchResult) {
2120
+ message.matches = Array.isArray(matchResult) ? matchResult : void 0;
2121
+ const response = yield handler.handleCommandReceived(context, message);
2122
+ if (typeof response === "string") {
2059
2123
  yield context.sendActivity(response);
2060
- break;
2124
+ }
2125
+ else {
2126
+ const replyActivity = response;
2127
+ if (replyActivity) {
2128
+ yield context.sendActivity(replyActivity);
2129
+ }
2061
2130
  }
2062
2131
  }
2063
- break;
2132
+ }
2064
2133
  }
2065
2134
  yield next();
2066
2135
  });
2067
2136
  }
2068
- classifyActivity(activity) {
2069
- if (activity.type === botbuilder.ActivityTypes.Message) {
2070
- return ActivityType.CurrentBotMessaged;
2071
- }
2072
- return ActivityType.Unknown;
2073
- }
2074
2137
  matchPattern(pattern, text) {
2075
2138
  if (text) {
2076
2139
  if (typeof pattern === "string") {
@@ -2285,41 +2348,6 @@ class ConversationReferenceStore {
2285
2348
  }
2286
2349
  }
2287
2350
 
2288
- // Copyright (c) Microsoft Corporation.
2289
- // Licensed under the MIT license.
2290
- /**
2291
- * @internal
2292
- */
2293
- function cloneConversation(conversation) {
2294
- return Object.assign({}, conversation);
2295
- }
2296
- /**
2297
- * @internal
2298
- */
2299
- function getTargetType(conversationReference) {
2300
- var _a;
2301
- const conversationType = (_a = conversationReference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
2302
- if (conversationType === "personal") {
2303
- return "Person";
2304
- }
2305
- else if (conversationType === "groupChat") {
2306
- return "Group";
2307
- }
2308
- else if (conversationType === "channel") {
2309
- return "Channel";
2310
- }
2311
- else {
2312
- return undefined;
2313
- }
2314
- }
2315
- /**
2316
- * @internal
2317
- */
2318
- function getTeamsBotInstallationId(context) {
2319
- var _a, _b, _c, _d;
2320
- 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;
2321
- }
2322
-
2323
2351
  // Copyright (c) Microsoft Corporation.
2324
2352
  /**
2325
2353
  * Send a plain text message to a notification target.
@@ -2355,7 +2383,7 @@ function sendAdaptiveCard(target, card) {
2355
2383
  */
2356
2384
  class Channel {
2357
2385
  /**
2358
- * Constuctor.
2386
+ * Constructor.
2359
2387
  *
2360
2388
  * @remarks
2361
2389
  * It's recommended to get channels from {@link TeamsBotInstallation.channels()}, instead of using this constructor.
@@ -2433,7 +2461,7 @@ class Channel {
2433
2461
  */
2434
2462
  class Member {
2435
2463
  /**
2436
- * Constuctor.
2464
+ * Constructor.
2437
2465
  *
2438
2466
  * @remarks
2439
2467
  * It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
@@ -2652,12 +2680,12 @@ class NotificationBot {
2652
2680
  if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
2653
2681
  throw new Error("NotificationBot has not been initialized.");
2654
2682
  }
2655
- const references = (yield this.conversationReferenceStore.getAll()).values();
2683
+ const references = yield this.conversationReferenceStore.getAll();
2656
2684
  const targets = [];
2657
2685
  for (const reference of references) {
2658
2686
  // validate connection
2659
2687
  let valid = true;
2660
- this.adapter.continueConversation(reference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
2688
+ yield this.adapter.continueConversation(reference, (context) => tslib.__awaiter(this, void 0, void 0, function* () {
2661
2689
  try {
2662
2690
  // try get member to see if the installation is still valid
2663
2691
  yield botbuilder.TeamsInfo.getPagedMembers(context, 1);
@@ -2672,7 +2700,7 @@ class NotificationBot {
2672
2700
  targets.push(new TeamsBotInstallation(this.adapter, reference));
2673
2701
  }
2674
2702
  else {
2675
- this.conversationReferenceStore.delete(reference);
2703
+ yield this.conversationReferenceStore.delete(reference);
2676
2704
  }
2677
2705
  }
2678
2706
  return targets;
@@ -2814,7 +2842,6 @@ class ConversationBot {
2814
2842
  }
2815
2843
 
2816
2844
  // Copyright (c) Microsoft Corporation.
2817
- const { AdaptiveCards } = require("@microsoft/adaptivecards-tools");
2818
2845
  /**
2819
2846
  * Provides utility method to build bot message with cards that supported in Teams.
2820
2847
  */
@@ -2859,7 +2886,7 @@ class MessageBuilder {
2859
2886
  */
2860
2887
  static attachAdaptiveCard(cardTemplate, data) {
2861
2888
  return {
2862
- attachments: [botbuilder.CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(data))],
2889
+ attachments: [botbuilder.CardFactory.adaptiveCard(adaptivecardsTools.AdaptiveCards.declare(cardTemplate).render(data))],
2863
2890
  };
2864
2891
  }
2865
2892
  /**
@@ -2872,7 +2899,7 @@ class MessageBuilder {
2872
2899
  */
2873
2900
  static attachAdaptiveCardWithoutData(card) {
2874
2901
  return {
2875
- attachments: [botbuilder.CardFactory.adaptiveCard(AdaptiveCards.declareWithoutData(card).render())],
2902
+ attachments: [botbuilder.CardFactory.adaptiveCard(adaptivecardsTools.AdaptiveCards.declareWithoutData(card).render())],
2876
2903
  };
2877
2904
  }
2878
2905
  /**