@microsoft/teamsfx 0.6.2 → 0.6.3-alpha.768a76f6e.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,415 @@ 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
+ * Provide utilities for bot conversation, including:
1268
+ * - handle command and response.
1269
+ * - send notification to varies targets (e.g., member, group, channel).
1270
+ *
1271
+ * @remarks
1272
+ * Only work on server side.
1273
+ *
1274
+ * @beta
1275
+ */
1276
+ class ConversationBot {
1277
+ /**
1278
+ * Creates new instance of the `ConversationBot`.
1279
+ *
1280
+ * @param options - initialize options
1281
+ *
1282
+ * @remarks
1283
+ * Only work on server side.
1284
+ *
1285
+ * @beta
1286
+ */
1287
+ constructor(options) {
1288
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "ConversationBot"), ErrorCode.RuntimeNotSupported);
1289
+ }
1290
+ /**
1291
+ * The request handler to integrate with web request.
1292
+ *
1293
+ * @param req - an Express or Restify style request object.
1294
+ * @param res - an Express or Restify style response object.
1295
+ * @param logic - the additional function to handle bot context.
1296
+ *
1297
+ * @remarks
1298
+ * Only work on server side.
1299
+ *
1300
+ * @beta
1301
+ */
1302
+ requestHandler(req, res, logic) {
1303
+ return __awaiter(this, void 0, void 0, function* () {
1304
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "ConversationBot"), ErrorCode.RuntimeNotSupported);
1305
+ });
1306
+ }
1307
+ }
1308
+
1309
+ // Copyright (c) Microsoft Corporation.
1310
+ /**
1311
+ * Send a plain text message to a notification target.
1312
+ *
1313
+ * @remarks
1314
+ * Only work on server side.
1315
+ *
1316
+ * @param target - the notification target.
1317
+ * @param text - the plain text message.
1318
+ * @returns A `Promise` representing the asynchronous operation.
1319
+ *
1320
+ * @beta
1321
+ */
1322
+ function sendMessage(target, text) {
1323
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "sendMessage"), ErrorCode.RuntimeNotSupported);
1324
+ }
1325
+ /**
1326
+ * Send an adaptive card message to a notification target.
1327
+ *
1328
+ * @remarks
1329
+ * Only work on server side.
1330
+ *
1331
+ * @param target - the notification target.
1332
+ * @param card - the adaptive card raw JSON.
1333
+ * @returns A `Promise` representing the asynchronous operation.
1334
+ *
1335
+ * @beta
1336
+ */
1337
+ function sendAdaptiveCard(target, card) {
1338
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "sendAdaptiveCard"), ErrorCode.RuntimeNotSupported);
1339
+ }
1340
+ /**
1341
+ * A {@link NotificationTarget} that represents a team channel.
1342
+ *
1343
+ * @remarks
1344
+ * Only work on server side.
1345
+ *
1346
+ * It's recommended to get channels from {@link TeamsBotInstallation.channels()}.
1347
+ *
1348
+ * @beta
1349
+ */
1350
+ class Channel {
1351
+ /**
1352
+ * Constuctor.
1353
+ *
1354
+ * @remarks
1355
+ * Only work on server side.
1356
+ *
1357
+ * It's recommended to get channels from {@link TeamsBotInstallation.channels()}, instead of using this constructor.
1358
+ *
1359
+ * @param parent - The parent {@link TeamsBotInstallation} where this channel is created from.
1360
+ * @param info - Detailed channel information.
1361
+ *
1362
+ * @beta
1363
+ */
1364
+ constructor(parent, info) {
1365
+ /**
1366
+ * Notification target type. For channel it's always "Channel".
1367
+ *
1368
+ * @remarks
1369
+ * Only work on server side.
1370
+ *
1371
+ * @beta
1372
+ */
1373
+ this.type = "Channel";
1374
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Channel"), ErrorCode.RuntimeNotSupported);
1375
+ }
1376
+ /**
1377
+ * Send a plain text message.
1378
+ *
1379
+ * @remarks
1380
+ * Only work on server side.
1381
+ *
1382
+ * @param text - the plain text message.
1383
+ * @returns A `Promise` representing the asynchronous operation.
1384
+ *
1385
+ * @beta
1386
+ */
1387
+ sendMessage(text) {
1388
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Channel"), ErrorCode.RuntimeNotSupported);
1389
+ }
1390
+ /**
1391
+ * Send an adaptive card message.
1392
+ *
1393
+ * @remarks
1394
+ * Only work on server side.
1395
+ *
1396
+ * @param card - the adaptive card raw JSON.
1397
+ * @returns A `Promise` representing the asynchronous operation.
1398
+ *
1399
+ * @beta
1400
+ */
1401
+ sendAdaptiveCard(card) {
1402
+ return __awaiter(this, void 0, void 0, function* () {
1403
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Channel"), ErrorCode.RuntimeNotSupported);
1404
+ });
1405
+ }
1406
+ }
1407
+ /**
1408
+ * A {@link NotificationTarget} that represents a team member.
1409
+ *
1410
+ * @remarks
1411
+ * Only work on server side.
1412
+ *
1413
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}.
1414
+ *
1415
+ * @beta
1416
+ */
1417
+ class Member {
1418
+ /**
1419
+ * Constuctor.
1420
+ *
1421
+ * @remarks
1422
+ * Only work on server side.
1423
+ *
1424
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
1425
+ *
1426
+ * @param parent - The parent {@link TeamsBotInstallation} where this member is created from.
1427
+ * @param account - Detailed member account information.
1428
+ *
1429
+ * @beta
1430
+ */
1431
+ constructor(parent, account) {
1432
+ /**
1433
+ * Notification target type. For member it's always "Person".
1434
+ *
1435
+ * @remarks
1436
+ * Only work on server side.
1437
+ *
1438
+ * @beta
1439
+ */
1440
+ this.type = "Person";
1441
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Member"), ErrorCode.RuntimeNotSupported);
1442
+ }
1443
+ /**
1444
+ * Send a plain text message.
1445
+ *
1446
+ * @remarks
1447
+ * Only work on server side.
1448
+ *
1449
+ * @param text - the plain text message.
1450
+ * @returns A `Promise` representing the asynchronous operation.
1451
+ *
1452
+ * @beta
1453
+ */
1454
+ sendMessage(text) {
1455
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Member"), ErrorCode.RuntimeNotSupported);
1456
+ }
1457
+ /**
1458
+ * Send an adaptive card message.
1459
+ *
1460
+ * @remarks
1461
+ * Only work on server side.
1462
+ *
1463
+ * @param card - the adaptive card raw JSON.
1464
+ * @returns A `Promise` representing the asynchronous operation.
1465
+ *
1466
+ * @beta
1467
+ */
1468
+ sendAdaptiveCard(card) {
1469
+ return __awaiter(this, void 0, void 0, function* () {
1470
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "Member"), ErrorCode.RuntimeNotSupported);
1471
+ });
1472
+ }
1473
+ }
1474
+ /**
1475
+ * A {@link NotificationTarget} that represents a bot installation. Teams Bot could be installed into
1476
+ * - Personal chat
1477
+ * - Group chat
1478
+ * - Team (by default the `General` channel)
1479
+ *
1480
+ * @remarks
1481
+ * Only work on server side.
1482
+ *
1483
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}.
1484
+ *
1485
+ * @beta
1486
+ */
1487
+ class TeamsBotInstallation {
1488
+ /**
1489
+ * Constructor
1490
+ *
1491
+ * @remarks
1492
+ * Only work on server side.
1493
+ *
1494
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}, instead of using this constructor.
1495
+ *
1496
+ * @param adapter - the bound `BotFrameworkAdapter`.
1497
+ * @param conversationReference - the bound `ConversationReference`.
1498
+ *
1499
+ * @beta
1500
+ */
1501
+ constructor(adapter, conversationReference) {
1502
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1503
+ }
1504
+ /**
1505
+ * Send a plain text message.
1506
+ *
1507
+ * @remarks
1508
+ * Only work on server side.
1509
+ *
1510
+ * @param text - the plain text message.
1511
+ * @returns A `Promise` representing the asynchronous operation.
1512
+ *
1513
+ * @beta
1514
+ */
1515
+ sendMessage(text) {
1516
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1517
+ }
1518
+ /**
1519
+ * Send an adaptive card message.
1520
+ *
1521
+ * @remarks
1522
+ * Only work on server side.
1523
+ *
1524
+ * @param card - the adaptive card raw JSON.
1525
+ * @returns A `Promise` representing the asynchronous operation.
1526
+ *
1527
+ * @beta
1528
+ */
1529
+ sendAdaptiveCard(card) {
1530
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1531
+ }
1532
+ /**
1533
+ * Get channels from this bot installation.
1534
+ *
1535
+ * @remarks
1536
+ * Only work on server side.
1537
+ *
1538
+ * @returns an array of channels if bot is installed into a team, otherwise returns an empty array.
1539
+ *
1540
+ * @beta
1541
+ */
1542
+ channels() {
1543
+ return __awaiter(this, void 0, void 0, function* () {
1544
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1545
+ });
1546
+ }
1547
+ /**
1548
+ * Get members from this bot installation.
1549
+ *
1550
+ * @remarks
1551
+ * Only work on server side.
1552
+ *
1553
+ * @returns an array of members from where the bot is installed.
1554
+ *
1555
+ * @beta
1556
+ */
1557
+ members() {
1558
+ return __awaiter(this, void 0, void 0, function* () {
1559
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "TeamsBotInstallation"), ErrorCode.RuntimeNotSupported);
1560
+ });
1561
+ }
1562
+ }
1563
+ /**
1564
+ * Provide static utilities for bot notification.
1565
+ *
1566
+ * @remarks
1567
+ * Only work on server side.
1568
+ *
1569
+ * @example
1570
+ * Here's an example on how to send notification via Teams Bot.
1571
+ * ```typescript
1572
+ * // initialize (it's recommended to be called before handling any bot message)
1573
+ * const notificationBot = new NotificationBot(adapter);
1574
+ *
1575
+ * // get all bot installations and send message
1576
+ * for (const target of await notificationBot.installations()) {
1577
+ * await target.sendMessage("Hello Notification");
1578
+ * }
1579
+ *
1580
+ * // alternative - send message to all members
1581
+ * for (const target of await notificationBot.installations()) {
1582
+ * for (const member of await target.members()) {
1583
+ * await member.sendMessage("Hello Notification");
1584
+ * }
1585
+ * }
1586
+ * ```
1587
+ *
1588
+ * @beta
1589
+ */
1590
+ class NotificationBot {
1591
+ /**
1592
+ * constructor of the notification bot.
1593
+ *
1594
+ * @remarks
1595
+ * Only work on server side.
1596
+ *
1597
+ * To ensure accuracy, it's recommended to initialize before handling any message.
1598
+ *
1599
+ * @param adapter - the bound `BotFrameworkAdapter`
1600
+ * @param options - initialize options
1601
+ *
1602
+ * @beta
1603
+ */
1604
+ constructor(adapter, options) {
1605
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "NotificationBot"), ErrorCode.RuntimeNotSupported);
1606
+ }
1607
+ /**
1608
+ * Get all targets where the bot is installed.
1609
+ *
1610
+ * @remarks
1611
+ * Only work on server side.
1612
+ *
1613
+ * The result is retrieving from the persisted storage.
1614
+ *
1615
+ * @returns - an array of {@link TeamsBotInstallation}.
1616
+ *
1617
+ * @beta
1618
+ */
1619
+ static installations() {
1620
+ return __awaiter(this, void 0, void 0, function* () {
1621
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "NotificationBot"), ErrorCode.RuntimeNotSupported);
1622
+ });
1623
+ }
1624
+ }
1625
+
1626
+ // Copyright (c) Microsoft Corporation.
1627
+ /**
1628
+ * A command bot for receiving commands and sending responses in Teams.
1629
+ *
1630
+ * @remarks
1631
+ * Only work on server side.
1632
+ *
1633
+ * @beta
1634
+ */
1635
+ class CommandBot {
1636
+ /**
1637
+ * Creates a new instance of the `CommandBot`.
1638
+ *
1639
+ * @param adapter The bound `BotFrameworkAdapter`.
1640
+ * @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.
1641
+ *
1642
+ * @beta
1643
+ */
1644
+ constructor(adapter, commands) {
1645
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CommandBot"), ErrorCode.RuntimeNotSupported);
1646
+ }
1647
+ /**
1648
+ * Registers a command into the command bot.
1649
+ *
1650
+ * @param command The command to registered.
1651
+ *
1652
+ * @remarks
1653
+ * Only work on server side.
1654
+ *
1655
+ * @beta
1656
+ */
1657
+ registerCommand(command) {
1658
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CommandBot"), ErrorCode.RuntimeNotSupported);
1659
+ }
1660
+ /**
1661
+ * Registers commands into the command bot.
1662
+ *
1663
+ * @param commands The command to registered.
1664
+ *
1665
+ * @remarks
1666
+ * Only work on server side.
1667
+ *
1668
+ * @beta
1669
+ */
1670
+ registerCommands(commands) {
1671
+ throw new ErrorWithCode(formatString(ErrorMessage.BrowserRuntimeNotSupported, "CommandnBot"), ErrorCode.RuntimeNotSupported);
1672
+ }
1673
+ }
1674
+
1675
+ export { AppCredential, BearerTokenAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, LogLevel, Member, MsGraphAuthProvider, NotificationBot, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
1199
1676
  //# sourceMappingURL=index.esm5.js.map