@microsoft/teamsfx 0.7.1-beta.adb483893.0 → 1.0.0-alpha.074ce579f.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.
@@ -1579,8 +1580,12 @@ class ApiKeyProvider {
1579
1580
  if (!config.params) {
1580
1581
  config.params = {};
1581
1582
  }
1582
- const url = new URL(config.url, config.baseURL);
1583
- if (config.params[this.keyName] || url.searchParams.has(this.keyName)) {
1583
+ let urlHasDefinedApiKey = false;
1584
+ if (config.url) {
1585
+ const url = new URL(config.url, config.baseURL);
1586
+ urlHasDefinedApiKey = url.searchParams.has(this.keyName);
1587
+ }
1588
+ if (config.params[this.keyName] || urlHasDefinedApiKey) {
1584
1589
  throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInQueryParam, this.keyName), ErrorCode.AuthorizationInfoAlreadyExists);
1585
1590
  }
1586
1591
  config.params[this.keyName] = this.keyValue;
@@ -1902,6 +1907,41 @@ class TeamsFx {
1902
1907
  }
1903
1908
  }
1904
1909
 
1910
+ // Copyright (c) Microsoft Corporation.
1911
+ // Licensed under the MIT license.
1912
+ /**
1913
+ * @internal
1914
+ */
1915
+ function cloneConversation(conversation) {
1916
+ return JSON.parse(JSON.stringify(conversation));
1917
+ }
1918
+ /**
1919
+ * @internal
1920
+ */
1921
+ function getTargetType(conversationReference) {
1922
+ var _a;
1923
+ const conversationType = (_a = conversationReference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
1924
+ if (conversationType === "personal") {
1925
+ return "Person";
1926
+ }
1927
+ else if (conversationType === "groupChat") {
1928
+ return "Group";
1929
+ }
1930
+ else if (conversationType === "channel") {
1931
+ return "Channel";
1932
+ }
1933
+ else {
1934
+ return undefined;
1935
+ }
1936
+ }
1937
+ /**
1938
+ * @internal
1939
+ */
1940
+ function getTeamsBotInstallationId(context) {
1941
+ var _a, _b, _c, _d;
1942
+ 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;
1943
+ }
1944
+
1905
1945
  // Copyright (c) Microsoft Corporation.
1906
1946
  /**
1907
1947
  * @internal
@@ -1931,6 +1971,10 @@ class NotificationMiddleware {
1931
1971
  await this.conversationReferenceStore.set(reference);
1932
1972
  break;
1933
1973
  }
1974
+ case ActivityType.CurrentBotMessaged: {
1975
+ await this.tryAddMessagedReference(context);
1976
+ break;
1977
+ }
1934
1978
  case ActivityType.CurrentBotUninstalled:
1935
1979
  case ActivityType.TeamDeleted: {
1936
1980
  const reference = TurnContext.getConversationReference(context.activity);
@@ -1961,8 +2005,31 @@ class NotificationMiddleware {
1961
2005
  return ActivityType.TeamRestored;
1962
2006
  }
1963
2007
  }
2008
+ else if (activityType === "message") {
2009
+ return ActivityType.CurrentBotMessaged;
2010
+ }
1964
2011
  return ActivityType.Unknown;
1965
2012
  }
2013
+ async tryAddMessagedReference(context) {
2014
+ var _a, _b, _c, _d;
2015
+ const reference = TurnContext.getConversationReference(context.activity);
2016
+ const conversationType = (_a = reference === null || reference === void 0 ? void 0 : reference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
2017
+ if (conversationType === "personal" || conversationType === "groupChat") {
2018
+ if (!(await this.conversationReferenceStore.check(reference))) {
2019
+ await this.conversationReferenceStore.set(reference);
2020
+ }
2021
+ }
2022
+ else if (conversationType === "channel") {
2023
+ 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;
2024
+ if (teamId !== undefined) {
2025
+ const teamReference = cloneConversation(reference);
2026
+ teamReference.conversation.id = teamId;
2027
+ if (!(await this.conversationReferenceStore.check(teamReference))) {
2028
+ await this.conversationReferenceStore.set(teamReference);
2029
+ }
2030
+ }
2031
+ }
2032
+ }
1966
2033
  }
1967
2034
  class CommandResponseMiddleware {
1968
2035
  constructor(handlers) {
@@ -1972,35 +2039,33 @@ class CommandResponseMiddleware {
1972
2039
  }
1973
2040
  }
1974
2041
  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);
2042
+ if (context.activity.type === ActivityTypes.Message) {
2043
+ // Invoke corresponding command handler for the command response
2044
+ const commandText = this.getActivityText(context.activity);
2045
+ const message = {
2046
+ text: commandText,
2047
+ };
2048
+ for (const handler of this.commandHandlers) {
2049
+ const matchResult = this.shouldTrigger(handler.triggerPatterns, commandText);
2050
+ // It is important to note that the command bot will stop processing handlers
2051
+ // when the first command handler is matched.
2052
+ if (!!matchResult) {
2053
+ message.matches = Array.isArray(matchResult) ? matchResult : void 0;
2054
+ const response = await handler.handleCommandReceived(context, message);
2055
+ if (typeof response === "string") {
1990
2056
  await context.sendActivity(response);
1991
- break;
2057
+ }
2058
+ else {
2059
+ const replyActivity = response;
2060
+ if (replyActivity) {
2061
+ await context.sendActivity(replyActivity);
2062
+ }
1992
2063
  }
1993
2064
  }
1994
- break;
2065
+ }
1995
2066
  }
1996
2067
  await next();
1997
2068
  }
1998
- classifyActivity(activity) {
1999
- if (activity.type === ActivityTypes.Message) {
2000
- return ActivityType.CurrentBotMessaged;
2001
- }
2002
- return ActivityType.Unknown;
2003
- }
2004
2069
  matchPattern(pattern, text) {
2005
2070
  if (text) {
2006
2071
  if (typeof pattern === "string") {
@@ -2203,41 +2268,6 @@ class ConversationReferenceStore {
2203
2268
  }
2204
2269
  }
2205
2270
 
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
2271
  // Copyright (c) Microsoft Corporation.
2242
2272
  /**
2243
2273
  * Send a plain text message to a notification target.
@@ -2273,7 +2303,7 @@ function sendAdaptiveCard(target, card) {
2273
2303
  */
2274
2304
  class Channel {
2275
2305
  /**
2276
- * Constuctor.
2306
+ * Constructor.
2277
2307
  *
2278
2308
  * @remarks
2279
2309
  * It's recommended to get channels from {@link TeamsBotInstallation.channels()}, instead of using this constructor.
@@ -2347,7 +2377,7 @@ class Channel {
2347
2377
  */
2348
2378
  class Member {
2349
2379
  /**
2350
- * Constuctor.
2380
+ * Constructor.
2351
2381
  *
2352
2382
  * @remarks
2353
2383
  * It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
@@ -2557,12 +2587,12 @@ class NotificationBot {
2557
2587
  if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
2558
2588
  throw new Error("NotificationBot has not been initialized.");
2559
2589
  }
2560
- const references = (await this.conversationReferenceStore.getAll()).values();
2590
+ const references = await this.conversationReferenceStore.getAll();
2561
2591
  const targets = [];
2562
2592
  for (const reference of references) {
2563
2593
  // validate connection
2564
2594
  let valid = true;
2565
- this.adapter.continueConversation(reference, async (context) => {
2595
+ await this.adapter.continueConversation(reference, async (context) => {
2566
2596
  try {
2567
2597
  // try get member to see if the installation is still valid
2568
2598
  await TeamsInfo.getPagedMembers(context, 1);
@@ -2577,7 +2607,7 @@ class NotificationBot {
2577
2607
  targets.push(new TeamsBotInstallation(this.adapter, reference));
2578
2608
  }
2579
2609
  else {
2580
- this.conversationReferenceStore.delete(reference);
2610
+ await this.conversationReferenceStore.delete(reference);
2581
2611
  }
2582
2612
  }
2583
2613
  return targets;
@@ -2716,7 +2746,6 @@ class ConversationBot {
2716
2746
  }
2717
2747
 
2718
2748
  // Copyright (c) Microsoft Corporation.
2719
- const { AdaptiveCards } = require("@microsoft/adaptivecards-tools");
2720
2749
  /**
2721
2750
  * Provides utility method to build bot message with cards that supported in Teams.
2722
2751
  */