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