@microsoft/teamsfx 0.6.2-alpha.83ce60286.0 → 0.6.2-alpha.aafc68d57.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.
@@ -3,6 +3,7 @@ import jwt_decode from 'jwt-decode';
3
3
  import * as microsoftTeams from '@microsoft/teams-js';
4
4
  import { PublicClientApplication } from '@azure/msal-browser';
5
5
  import { Client } from '@microsoft/microsoft-graph-client';
6
+ import axios from 'axios';
6
7
 
7
8
  // Copyright (c) Microsoft Corporation.
8
9
  // Licensed under the MIT license.
@@ -1075,6 +1076,72 @@ class TeamsBotSsoPrompt {
1075
1076
  }
1076
1077
  }
1077
1078
 
1079
+ // Copyright (c) Microsoft Corporation.
1080
+ /**
1081
+ * Initializes new Axios instance with specific auth provider
1082
+ *
1083
+ * @param apiEndpoint - Base url of the API
1084
+ * @param authProvider - Auth provider that injects authentication info to each request
1085
+ * @returns axios instance configured with specfic auth provider
1086
+ *
1087
+ * @example
1088
+ * ```typescript
1089
+ * const client = createApiClient("https://my-api-endpoint-base-url", new BasicAuthProvider("xxx","xxx"));
1090
+ * ```
1091
+ *
1092
+ * @beta
1093
+ */
1094
+ function createApiClient(apiEndpoint, authProvider) {
1095
+ // Add a request interceptor
1096
+ const instance = axios.create({
1097
+ baseURL: apiEndpoint,
1098
+ });
1099
+ instance.interceptors.request.use(function (config) {
1100
+ return __awaiter(this, void 0, void 0, function* () {
1101
+ return yield authProvider.AddAuthenticationInfo(config);
1102
+ });
1103
+ });
1104
+ return instance;
1105
+ }
1106
+
1107
+ // Copyright (c) Microsoft Corporation.
1108
+ /**
1109
+ * Provider that handles Bearer Token authentication
1110
+ *
1111
+ * @beta
1112
+ */
1113
+ class BearerTokenAuthProvider {
1114
+ /**
1115
+ * @param getToken Function that returns the content of bearer token used in http request
1116
+ *
1117
+ * @beta
1118
+ */
1119
+ constructor(getToken) {
1120
+ this.getToken = getToken;
1121
+ }
1122
+ /**
1123
+ * Adds authentication info to http requests
1124
+ *
1125
+ * @param config - Contains all the request information and can be updated to include extra authentication info.
1126
+ * Refer https://axios-http.com/docs/req_config for detailed document.
1127
+ *
1128
+ * @beta
1129
+ */
1130
+ AddAuthenticationInfo(config) {
1131
+ return __awaiter(this, void 0, void 0, function* () {
1132
+ const token = yield this.getToken();
1133
+ if (!config.headers) {
1134
+ config.headers = {};
1135
+ }
1136
+ if (config.headers["Authorization"]) {
1137
+ throw new Error("Authorization header already exists!");
1138
+ }
1139
+ config.headers["Authorization"] = `Bearer ${token}`;
1140
+ return config;
1141
+ });
1142
+ }
1143
+ }
1144
+
1078
1145
  // Copyright (c) Microsoft Corporation.
1079
1146
  // Licensed under the MIT license.
1080
1147
  /**
@@ -1195,5 +1262,371 @@ class TeamsFx {
1195
1262
  }
1196
1263
  }
1197
1264
 
1198
- export { AppCredential, ErrorCode, ErrorWithCode, IdentityType, LogLevel, MsGraphAuthProvider, OnBehalfOfUserCredential, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createMicrosoftGraphClient, getLogLevel, getTediousConnectionConfig, setLogFunction, setLogLevel, setLogger };
1265
+ // Copyright (c) Microsoft Corporation.
1266
+ /**
1267
+ * Send a plain text message to a notification target.
1268
+ *
1269
+ * @remarks
1270
+ * Only work on server side.
1271
+ *
1272
+ * @param target - the notification target.
1273
+ * @param text - the plain text message.
1274
+ * @returns A `Promise` representing the asynchronous operation.
1275
+ *
1276
+ * @beta
1277
+ */
1278
+ function sendMessage(target, text) {
1279
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "sendMessage"), ErrorCode.RuntimeNotSupported);
1280
+ }
1281
+ /**
1282
+ * Send an adaptive card message to a notification target.
1283
+ *
1284
+ * @remarks
1285
+ * Only work on server side.
1286
+ *
1287
+ * @param target - the notification target.
1288
+ * @param card - the adaptive card raw JSON.
1289
+ * @returns A `Promise` representing the asynchronous operation.
1290
+ *
1291
+ * @beta
1292
+ */
1293
+ function sendAdaptiveCard(target, card) {
1294
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "sendAdaptiveCard"), ErrorCode.RuntimeNotSupported);
1295
+ }
1296
+ /**
1297
+ * A {@link NotificationTarget} that represents a team channel.
1298
+ *
1299
+ * @remarks
1300
+ * Only work on server side.
1301
+ *
1302
+ * It's recommended to get channels from {@link TeamsBotInstallation.channels()}.
1303
+ *
1304
+ * @beta
1305
+ */
1306
+ class Channel {
1307
+ /**
1308
+ * Constuctor.
1309
+ *
1310
+ * @remarks
1311
+ * Only work on server side.
1312
+ *
1313
+ * It's recommended to get channels from {@link TeamsBotInstallation.channels()}, instead of using this constructor.
1314
+ *
1315
+ * @param parent - The parent {@link TeamsBotInstallation} where this channel is created from.
1316
+ * @param info - Detailed channel information.
1317
+ *
1318
+ * @beta
1319
+ */
1320
+ constructor(parent, info) {
1321
+ /**
1322
+ * Notification target type. For channel it's always "Channel".
1323
+ *
1324
+ * @remarks
1325
+ * Only work on server side.
1326
+ *
1327
+ * @beta
1328
+ */
1329
+ this.type = "Channel";
1330
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Channel"), ErrorCode.RuntimeNotSupported);
1331
+ }
1332
+ /**
1333
+ * Send a plain text message.
1334
+ *
1335
+ * @remarks
1336
+ * Only work on server side.
1337
+ *
1338
+ * @param text - the plain text message.
1339
+ * @returns A `Promise` representing the asynchronous operation.
1340
+ *
1341
+ * @beta
1342
+ */
1343
+ sendMessage(text) {
1344
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Channel"), ErrorCode.RuntimeNotSupported);
1345
+ }
1346
+ /**
1347
+ * Send an adaptive card message.
1348
+ *
1349
+ * @remarks
1350
+ * Only work on server side.
1351
+ *
1352
+ * @param card - the adaptive card raw JSON.
1353
+ * @returns A `Promise` representing the asynchronous operation.
1354
+ *
1355
+ * @beta
1356
+ */
1357
+ sendAdaptiveCard(card) {
1358
+ return __awaiter(this, void 0, void 0, function* () {
1359
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Channel"), ErrorCode.RuntimeNotSupported);
1360
+ });
1361
+ }
1362
+ }
1363
+ /**
1364
+ * A {@link NotificationTarget} that represents a team member.
1365
+ *
1366
+ * @remarks
1367
+ * Only work on server side.
1368
+ *
1369
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}.
1370
+ *
1371
+ * @beta
1372
+ */
1373
+ class Member {
1374
+ /**
1375
+ * Constuctor.
1376
+ *
1377
+ * @remarks
1378
+ * Only work on server side.
1379
+ *
1380
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
1381
+ *
1382
+ * @param parent - The parent {@link TeamsBotInstallation} where this member is created from.
1383
+ * @param account - Detailed member account information.
1384
+ *
1385
+ * @beta
1386
+ */
1387
+ constructor(parent, account) {
1388
+ /**
1389
+ * Notification target type. For member it's always "Person".
1390
+ *
1391
+ * @remarks
1392
+ * Only work on server side.
1393
+ *
1394
+ * @beta
1395
+ */
1396
+ this.type = "Person";
1397
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Member"), ErrorCode.RuntimeNotSupported);
1398
+ }
1399
+ /**
1400
+ * Send a plain text message.
1401
+ *
1402
+ * @remarks
1403
+ * Only work on server side.
1404
+ *
1405
+ * @param text - the plain text message.
1406
+ * @returns A `Promise` representing the asynchronous operation.
1407
+ *
1408
+ * @beta
1409
+ */
1410
+ sendMessage(text) {
1411
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Member"), ErrorCode.RuntimeNotSupported);
1412
+ }
1413
+ /**
1414
+ * Send an adaptive card message.
1415
+ *
1416
+ * @remarks
1417
+ * Only work on server side.
1418
+ *
1419
+ * @param card - the adaptive card raw JSON.
1420
+ * @returns A `Promise` representing the asynchronous operation.
1421
+ *
1422
+ * @beta
1423
+ */
1424
+ sendAdaptiveCard(card) {
1425
+ return __awaiter(this, void 0, void 0, function* () {
1426
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Member"), ErrorCode.RuntimeNotSupported);
1427
+ });
1428
+ }
1429
+ }
1430
+ /**
1431
+ * A {@link NotificationTarget} that represents a bot installation. Teams Bot could be installed into
1432
+ * - Personal chat
1433
+ * - Group chat
1434
+ * - Team (by default the `General` channel)
1435
+ *
1436
+ * @remarks
1437
+ * Only work on server side.
1438
+ *
1439
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}.
1440
+ *
1441
+ * @beta
1442
+ */
1443
+ class TeamsBotInstallation {
1444
+ /**
1445
+ * Constructor
1446
+ *
1447
+ * @remarks
1448
+ * Only work on server side.
1449
+ *
1450
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}, instead of using this constructor.
1451
+ *
1452
+ * @param adapter - the bound `BotFrameworkAdapter`.
1453
+ * @param conversationReference - the bound `ConversationReference`.
1454
+ *
1455
+ * @beta
1456
+ */
1457
+ constructor(adapter, conversationReference) {
1458
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1459
+ }
1460
+ /**
1461
+ * Send a plain text message.
1462
+ *
1463
+ * @remarks
1464
+ * Only work on server side.
1465
+ *
1466
+ * @param text - the plain text message.
1467
+ * @returns A `Promise` representing the asynchronous operation.
1468
+ *
1469
+ * @beta
1470
+ */
1471
+ sendMessage(text) {
1472
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1473
+ }
1474
+ /**
1475
+ * Send an adaptive card message.
1476
+ *
1477
+ * @remarks
1478
+ * Only work on server side.
1479
+ *
1480
+ * @param card - the adaptive card raw JSON.
1481
+ * @returns A `Promise` representing the asynchronous operation.
1482
+ *
1483
+ * @beta
1484
+ */
1485
+ sendAdaptiveCard(card) {
1486
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1487
+ }
1488
+ /**
1489
+ * Get channels from this bot installation.
1490
+ *
1491
+ * @remarks
1492
+ * Only work on server side.
1493
+ *
1494
+ * @returns an array of channels if bot is installed into a team, otherwise returns an empty array.
1495
+ *
1496
+ * @beta
1497
+ */
1498
+ channels() {
1499
+ return __awaiter(this, void 0, void 0, function* () {
1500
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1501
+ });
1502
+ }
1503
+ /**
1504
+ * Get members from this bot installation.
1505
+ *
1506
+ * @remarks
1507
+ * Only work on server side.
1508
+ *
1509
+ * @returns an array of members from where the bot is installed.
1510
+ *
1511
+ * @beta
1512
+ */
1513
+ members() {
1514
+ return __awaiter(this, void 0, void 0, function* () {
1515
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1516
+ });
1517
+ }
1518
+ }
1519
+ /**
1520
+ * Provide static utilities for bot notification.
1521
+ *
1522
+ * @remarks
1523
+ * Only work on server side.
1524
+ *
1525
+ * @example
1526
+ * Here's an example on how to send notification via Teams Bot.
1527
+ * ```typescript
1528
+ * // initialize (it's recommended to be called before handling any bot message)
1529
+ * const notificationBot = new NotificationBot(adapter);
1530
+ *
1531
+ * // get all bot installations and send message
1532
+ * for (const target of await notificationBot.installations()) {
1533
+ * await target.sendMessage("Hello Notification");
1534
+ * }
1535
+ *
1536
+ * // alternative - send message to all members
1537
+ * for (const target of await notificationBot.installations()) {
1538
+ * for (const member of await target.members()) {
1539
+ * await member.sendMessage("Hello Notification");
1540
+ * }
1541
+ * }
1542
+ * ```
1543
+ *
1544
+ * @beta
1545
+ */
1546
+ class NotificationBot {
1547
+ /**
1548
+ * constructor of the notification bot.
1549
+ *
1550
+ * @remarks
1551
+ * Only work on server side.
1552
+ *
1553
+ * To ensure accuracy, it's recommended to initialize before handling any message.
1554
+ *
1555
+ * @param adapter - the bound `BotFrameworkAdapter`
1556
+ * @param options - initialize options
1557
+ *
1558
+ * @beta
1559
+ */
1560
+ constructor(adapter, options) {
1561
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "NotificationBot"), ErrorCode.RuntimeNotSupported);
1562
+ }
1563
+ /**
1564
+ * Get all targets where the bot is installed.
1565
+ *
1566
+ * @remarks
1567
+ * Only work on server side.
1568
+ *
1569
+ * The result is retrieving from the persisted storage.
1570
+ *
1571
+ * @returns - an array of {@link TeamsBotInstallation}.
1572
+ *
1573
+ * @beta
1574
+ */
1575
+ static installations() {
1576
+ return __awaiter(this, void 0, void 0, function* () {
1577
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "NotificationBot"), ErrorCode.RuntimeNotSupported);
1578
+ });
1579
+ }
1580
+ }
1581
+
1582
+ // Copyright (c) Microsoft Corporation.
1583
+ /**
1584
+ * A command bot for receiving commands and sending responses in Teams.
1585
+ *
1586
+ * @remarks
1587
+ * Only work on server side.
1588
+ *
1589
+ * @beta
1590
+ */
1591
+ class CommandBot {
1592
+ /**
1593
+ * Creates a new instance of the `CommandBot`.
1594
+ *
1595
+ * @param adapter The bound `BotFrameworkAdapter`.
1596
+ * @param commands The commands to registered with the command bot. Each command should implement the interface {@link TeamsFxBotCommandHandler} so that it can be correctly handled by this command bot.
1597
+ *
1598
+ * @beta
1599
+ */
1600
+ constructor(adapter, commands) {
1601
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CommandBot"), ErrorCode.RuntimeNotSupported);
1602
+ }
1603
+ /**
1604
+ * Registers a command into the command bot.
1605
+ *
1606
+ * @param command The command to registered.
1607
+ *
1608
+ * @remarks
1609
+ * Only work on server side.
1610
+ *
1611
+ * @beta
1612
+ */
1613
+ registerCommand(command) {
1614
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CommandBot"), ErrorCode.RuntimeNotSupported);
1615
+ }
1616
+ /**
1617
+ * Registers commands into the command bot.
1618
+ *
1619
+ * @param commands The command to registered.
1620
+ *
1621
+ * @remarks
1622
+ * Only work on server side.
1623
+ *
1624
+ * @beta
1625
+ */
1626
+ registerCommands(commands) {
1627
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CommandnBot"), ErrorCode.RuntimeNotSupported);
1628
+ }
1629
+ }
1630
+
1631
+ export { AppCredential, BearerTokenAuthProvider, Channel, CommandBot, ErrorCode, ErrorWithCode, IdentityType, LogLevel, Member, MsGraphAuthProvider, NotificationBot, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
1199
1632
  //# sourceMappingURL=index.esm5.js.map