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