@microsoft/teamsfx 0.7.1-beta.c23501411.0 → 1.0.0-alpha.3511f64fb.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) {
@@ -2201,41 +2268,6 @@ class ConversationReferenceStore {
2201
2268
  }
2202
2269
  }
2203
2270
 
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
2271
  // Copyright (c) Microsoft Corporation.
2240
2272
  /**
2241
2273
  * Send a plain text message to a notification target.
@@ -2271,7 +2303,7 @@ function sendAdaptiveCard(target, card) {
2271
2303
  */
2272
2304
  class Channel {
2273
2305
  /**
2274
- * Constuctor.
2306
+ * Constructor.
2275
2307
  *
2276
2308
  * @remarks
2277
2309
  * It's recommended to get channels from {@link TeamsBotInstallation.channels()}, instead of using this constructor.
@@ -2345,7 +2377,7 @@ class Channel {
2345
2377
  */
2346
2378
  class Member {
2347
2379
  /**
2348
- * Constuctor.
2380
+ * Constructor.
2349
2381
  *
2350
2382
  * @remarks
2351
2383
  * It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
@@ -2555,12 +2587,12 @@ class NotificationBot {
2555
2587
  if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
2556
2588
  throw new Error("NotificationBot has not been initialized.");
2557
2589
  }
2558
- const references = (await this.conversationReferenceStore.getAll()).values();
2590
+ const references = await this.conversationReferenceStore.getAll();
2559
2591
  const targets = [];
2560
2592
  for (const reference of references) {
2561
2593
  // validate connection
2562
2594
  let valid = true;
2563
- this.adapter.continueConversation(reference, async (context) => {
2595
+ await this.adapter.continueConversation(reference, async (context) => {
2564
2596
  try {
2565
2597
  // try get member to see if the installation is still valid
2566
2598
  await TeamsInfo.getPagedMembers(context, 1);
@@ -2575,7 +2607,7 @@ class NotificationBot {
2575
2607
  targets.push(new TeamsBotInstallation(this.adapter, reference));
2576
2608
  }
2577
2609
  else {
2578
- this.conversationReferenceStore.delete(reference);
2610
+ await this.conversationReferenceStore.delete(reference);
2579
2611
  }
2580
2612
  }
2581
2613
  return targets;
@@ -2714,7 +2746,6 @@ class ConversationBot {
2714
2746
  }
2715
2747
 
2716
2748
  // Copyright (c) Microsoft Corporation.
2717
- const { AdaptiveCards } = require("@microsoft/adaptivecards-tools");
2718
2749
  /**
2719
2750
  * Provides utility method to build bot message with cards that supported in Teams.
2720
2751
  */