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