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