@microsoft/teamsfx 0.6.3-alpha.8d048e1f1.0 → 0.6.3-alpha.cc1068ff9.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/dist/index.esm2017.js +234 -6
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +345 -42
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +242 -5
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +357 -40
- package/dist/index.node.cjs.js.map +1 -1
- package/package.json +3 -3
- package/types/teamsfx.d.ts +1428 -1239
package/dist/index.esm2017.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import { ActivityTypes, Channels, TeamsInfo, CardFactory, ActionTypes, MessageFa
|
|
|
7
7
|
import { Dialog } from 'botbuilder-dialogs';
|
|
8
8
|
import { v4 } from 'uuid';
|
|
9
9
|
import axios from 'axios';
|
|
10
|
+
import { Agent } from 'https';
|
|
10
11
|
import * as path from 'path';
|
|
11
12
|
import * as fs from 'fs';
|
|
12
13
|
|
|
@@ -70,6 +71,10 @@ var ErrorCode;
|
|
|
70
71
|
* Identity type error.
|
|
71
72
|
*/
|
|
72
73
|
ErrorCode["IdentityTypeNotSupported"] = "IdentityTypeNotSupported";
|
|
74
|
+
/**
|
|
75
|
+
* Authentication info already exists error.
|
|
76
|
+
*/
|
|
77
|
+
ErrorCode["AuthorizationInfoAlreadyExists"] = "AuthorizationInfoAlreadyExists";
|
|
73
78
|
})(ErrorCode || (ErrorCode = {}));
|
|
74
79
|
/**
|
|
75
80
|
* @internal
|
|
@@ -91,6 +96,14 @@ ErrorMessage.FailToAcquireTokenOnBehalfOfUser = "Failed to acquire access token
|
|
|
91
96
|
ErrorMessage.OnlyMSTeamsChannelSupported = "{0} is only supported in MS Teams Channel";
|
|
92
97
|
// IdentityTypeNotSupported Error
|
|
93
98
|
ErrorMessage.IdentityTypeNotSupported = "{0} identity is not supported in {1}";
|
|
99
|
+
// AuthorizationInfoError
|
|
100
|
+
ErrorMessage.AuthorizationHeaderAlreadyExists = "Authorization header already exists!";
|
|
101
|
+
ErrorMessage.BasicCredentialAlreadyExists = "Basic credential already exists!";
|
|
102
|
+
// InvalidParameter Error
|
|
103
|
+
ErrorMessage.EmptyParameter = "Parameter {0} is empty";
|
|
104
|
+
ErrorMessage.DuplicateHttpsOptionProperty = "Axios HTTPS agent already defined value for property {0}";
|
|
105
|
+
ErrorMessage.DuplicateApiKeyInHeader = "The request already defined api key in request header with name {0}.";
|
|
106
|
+
ErrorMessage.DuplicateApiKeyInQueryParam = "The request already defined api key in query parameter with name {0}.";
|
|
94
107
|
/**
|
|
95
108
|
* Error class with code and message thrown by the SDK.
|
|
96
109
|
*
|
|
@@ -1415,7 +1428,6 @@ function createApiClient(apiEndpoint, authProvider) {
|
|
|
1415
1428
|
}
|
|
1416
1429
|
|
|
1417
1430
|
// Copyright (c) Microsoft Corporation.
|
|
1418
|
-
// Licensed under the MIT license.
|
|
1419
1431
|
/**
|
|
1420
1432
|
* Provider that handles Bearer Token authentication
|
|
1421
1433
|
*
|
|
@@ -1423,7 +1435,7 @@ function createApiClient(apiEndpoint, authProvider) {
|
|
|
1423
1435
|
*/
|
|
1424
1436
|
class BearerTokenAuthProvider {
|
|
1425
1437
|
/**
|
|
1426
|
-
* @param getToken Function that returns the content of bearer token used in http request
|
|
1438
|
+
* @param { () => Promise<string> } getToken - Function that returns the content of bearer token used in http request
|
|
1427
1439
|
*
|
|
1428
1440
|
* @beta
|
|
1429
1441
|
*/
|
|
@@ -1433,9 +1445,13 @@ class BearerTokenAuthProvider {
|
|
|
1433
1445
|
/**
|
|
1434
1446
|
* Adds authentication info to http requests
|
|
1435
1447
|
*
|
|
1436
|
-
* @param config - Contains all the request information and can be updated to include extra authentication info.
|
|
1448
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1437
1449
|
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1438
1450
|
*
|
|
1451
|
+
* @returns Updated axios request config.
|
|
1452
|
+
*
|
|
1453
|
+
* @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header already exists in request configuration.
|
|
1454
|
+
*
|
|
1439
1455
|
* @beta
|
|
1440
1456
|
*/
|
|
1441
1457
|
async AddAuthenticationInfo(config) {
|
|
@@ -1444,7 +1460,7 @@ class BearerTokenAuthProvider {
|
|
|
1444
1460
|
config.headers = {};
|
|
1445
1461
|
}
|
|
1446
1462
|
if (config.headers["Authorization"]) {
|
|
1447
|
-
throw new
|
|
1463
|
+
throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1448
1464
|
}
|
|
1449
1465
|
config.headers["Authorization"] = `Bearer ${token}`;
|
|
1450
1466
|
return config;
|
|
@@ -1452,6 +1468,256 @@ class BearerTokenAuthProvider {
|
|
|
1452
1468
|
}
|
|
1453
1469
|
|
|
1454
1470
|
// Copyright (c) Microsoft Corporation.
|
|
1471
|
+
/**
|
|
1472
|
+
* Provider that handles Basic authentication
|
|
1473
|
+
*
|
|
1474
|
+
* @beta
|
|
1475
|
+
*/
|
|
1476
|
+
class BasicAuthProvider {
|
|
1477
|
+
/**
|
|
1478
|
+
*
|
|
1479
|
+
* @param { string } userName - Username used in basic auth
|
|
1480
|
+
* @param { string } password - Password used in basic auth
|
|
1481
|
+
*
|
|
1482
|
+
* @throws {@link ErrorCode|InvalidParameter} - when username or password is empty.
|
|
1483
|
+
*
|
|
1484
|
+
* @beta
|
|
1485
|
+
*/
|
|
1486
|
+
constructor(userName, password) {
|
|
1487
|
+
if (!userName) {
|
|
1488
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "username"), ErrorCode.InvalidParameter);
|
|
1489
|
+
}
|
|
1490
|
+
if (!password) {
|
|
1491
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "password"), ErrorCode.InvalidParameter);
|
|
1492
|
+
}
|
|
1493
|
+
this.userName = userName;
|
|
1494
|
+
this.password = password;
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* Adds authentication info to http requests
|
|
1498
|
+
*
|
|
1499
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1500
|
+
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1501
|
+
*
|
|
1502
|
+
* @returns Updated axios request config.
|
|
1503
|
+
*
|
|
1504
|
+
* @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header or auth property already exists in request configuration.
|
|
1505
|
+
*
|
|
1506
|
+
* @beta
|
|
1507
|
+
*/
|
|
1508
|
+
async AddAuthenticationInfo(config) {
|
|
1509
|
+
if (config.headers && config.headers["Authorization"]) {
|
|
1510
|
+
throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1511
|
+
}
|
|
1512
|
+
if (config.auth) {
|
|
1513
|
+
throw new ErrorWithCode(ErrorMessage.BasicCredentialAlreadyExists, ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1514
|
+
}
|
|
1515
|
+
config.auth = {
|
|
1516
|
+
username: this.userName,
|
|
1517
|
+
password: this.password,
|
|
1518
|
+
};
|
|
1519
|
+
return config;
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
// Copyright (c) Microsoft Corporation.
|
|
1524
|
+
/**
|
|
1525
|
+
* Provider that handles API Key authentication
|
|
1526
|
+
*
|
|
1527
|
+
* @beta
|
|
1528
|
+
*/
|
|
1529
|
+
class ApiKeyProvider {
|
|
1530
|
+
/**
|
|
1531
|
+
*
|
|
1532
|
+
* @param { string } keyName - The name of request header or query parameter that specifies API Key
|
|
1533
|
+
* @param { string } keyValue - The value of API Key
|
|
1534
|
+
* @param { ApiKeyLocation } keyLocation - The location of API Key: request header or query parameter.
|
|
1535
|
+
*
|
|
1536
|
+
* @throws {@link ErrorCode|InvalidParameter} - when key name or key value is empty.
|
|
1537
|
+
*
|
|
1538
|
+
* @beta
|
|
1539
|
+
*/
|
|
1540
|
+
constructor(keyName, keyValue, keyLocation) {
|
|
1541
|
+
if (!keyName) {
|
|
1542
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "keyName"), ErrorCode.InvalidParameter);
|
|
1543
|
+
}
|
|
1544
|
+
if (!keyValue) {
|
|
1545
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "keyVaule"), ErrorCode.InvalidParameter);
|
|
1546
|
+
}
|
|
1547
|
+
this.keyName = keyName;
|
|
1548
|
+
this.keyValue = keyValue;
|
|
1549
|
+
this.keyLocation = keyLocation;
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
* Adds authentication info to http requests
|
|
1553
|
+
*
|
|
1554
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1555
|
+
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1556
|
+
*
|
|
1557
|
+
* @returns Updated axios request config.
|
|
1558
|
+
*
|
|
1559
|
+
* @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when API key already exists in request header or url query parameter.
|
|
1560
|
+
*
|
|
1561
|
+
* @beta
|
|
1562
|
+
*/
|
|
1563
|
+
async AddAuthenticationInfo(config) {
|
|
1564
|
+
switch (this.keyLocation) {
|
|
1565
|
+
case ApiKeyLocation.Header:
|
|
1566
|
+
if (!config.headers) {
|
|
1567
|
+
config.headers = {};
|
|
1568
|
+
}
|
|
1569
|
+
if (config.headers[this.keyName]) {
|
|
1570
|
+
throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInHeader, this.keyName), ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1571
|
+
}
|
|
1572
|
+
config.headers[this.keyName] = this.keyValue;
|
|
1573
|
+
break;
|
|
1574
|
+
case ApiKeyLocation.QueryParams:
|
|
1575
|
+
if (!config.params) {
|
|
1576
|
+
config.params = {};
|
|
1577
|
+
}
|
|
1578
|
+
const url = new URL(config.url, config.baseURL);
|
|
1579
|
+
if (config.params[this.keyName] || url.searchParams.has(this.keyName)) {
|
|
1580
|
+
throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInQueryParam, this.keyName), ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1581
|
+
}
|
|
1582
|
+
config.params[this.keyName] = this.keyValue;
|
|
1583
|
+
break;
|
|
1584
|
+
}
|
|
1585
|
+
return config;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
/**
|
|
1589
|
+
* Define available location for API Key location
|
|
1590
|
+
*
|
|
1591
|
+
* @beta
|
|
1592
|
+
*/
|
|
1593
|
+
var ApiKeyLocation;
|
|
1594
|
+
(function (ApiKeyLocation) {
|
|
1595
|
+
/**
|
|
1596
|
+
* The API Key is placed in request header
|
|
1597
|
+
*/
|
|
1598
|
+
ApiKeyLocation[ApiKeyLocation["Header"] = 0] = "Header";
|
|
1599
|
+
/**
|
|
1600
|
+
* The API Key is placed in query parameter
|
|
1601
|
+
*/
|
|
1602
|
+
ApiKeyLocation[ApiKeyLocation["QueryParams"] = 1] = "QueryParams";
|
|
1603
|
+
})(ApiKeyLocation || (ApiKeyLocation = {}));
|
|
1604
|
+
|
|
1605
|
+
// Copyright (c) Microsoft Corporation.
|
|
1606
|
+
/**
|
|
1607
|
+
* Provider that handles Certificate authentication
|
|
1608
|
+
*
|
|
1609
|
+
* @beta
|
|
1610
|
+
*/
|
|
1611
|
+
class CertificateAuthProvider {
|
|
1612
|
+
/**
|
|
1613
|
+
*
|
|
1614
|
+
* @param { SecureContextOptions } certOption - information about the cert used in http requests
|
|
1615
|
+
*
|
|
1616
|
+
* @throws {@link ErrorCode|InvalidParameter} - when cert option is empty.
|
|
1617
|
+
*
|
|
1618
|
+
* @beta
|
|
1619
|
+
*/
|
|
1620
|
+
constructor(certOption) {
|
|
1621
|
+
if (certOption && Object.keys(certOption).length !== 0) {
|
|
1622
|
+
this.certOption = certOption;
|
|
1623
|
+
}
|
|
1624
|
+
else {
|
|
1625
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "certOption"), ErrorCode.InvalidParameter);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
/**
|
|
1629
|
+
* Adds authentication info to http requests.
|
|
1630
|
+
*
|
|
1631
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1632
|
+
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1633
|
+
*
|
|
1634
|
+
* @returns Updated axios request config.
|
|
1635
|
+
*
|
|
1636
|
+
* @throws {@link ErrorCode|InvalidParameter} - when custom httpsAgent in the request has duplicate properties with certOption provided in constructor.
|
|
1637
|
+
*
|
|
1638
|
+
* @beta
|
|
1639
|
+
*/
|
|
1640
|
+
async AddAuthenticationInfo(config) {
|
|
1641
|
+
if (!config.httpsAgent) {
|
|
1642
|
+
config.httpsAgent = new Agent(this.certOption);
|
|
1643
|
+
}
|
|
1644
|
+
else {
|
|
1645
|
+
const existingProperties = new Set(Object.keys(config.httpsAgent.options));
|
|
1646
|
+
for (const property of Object.keys(this.certOption)) {
|
|
1647
|
+
if (existingProperties.has(property)) {
|
|
1648
|
+
throw new ErrorWithCode(formatString(ErrorMessage.DuplicateHttpsOptionProperty, property), ErrorCode.InvalidParameter);
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
Object.assign(config.httpsAgent.options, this.certOption);
|
|
1652
|
+
}
|
|
1653
|
+
return config;
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
/**
|
|
1657
|
+
* Helper to create SecureContextOptions from PEM format cert
|
|
1658
|
+
*
|
|
1659
|
+
* @param { string | Buffer } cert - The cert chain in PEM format
|
|
1660
|
+
* @param { string | Buffer } key - The private key for the cert chain
|
|
1661
|
+
* @param { string? } passphrase - The passphrase for private key
|
|
1662
|
+
* @param { string? | Buffer? } ca - Overrides the trusted CA certificates
|
|
1663
|
+
*
|
|
1664
|
+
* @returns Instance of SecureContextOptions
|
|
1665
|
+
*
|
|
1666
|
+
* @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
|
|
1667
|
+
*
|
|
1668
|
+
*/
|
|
1669
|
+
function createPemCertOption(cert, key, passphrase, ca) {
|
|
1670
|
+
if (cert.length === 0) {
|
|
1671
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "cert"), ErrorCode.InvalidParameter);
|
|
1672
|
+
}
|
|
1673
|
+
if (key.length === 0) {
|
|
1674
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "key"), ErrorCode.InvalidParameter);
|
|
1675
|
+
}
|
|
1676
|
+
return {
|
|
1677
|
+
cert,
|
|
1678
|
+
key,
|
|
1679
|
+
passphrase,
|
|
1680
|
+
ca,
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
/**
|
|
1684
|
+
* Helper to create SecureContextOptions from PFX format cert
|
|
1685
|
+
*
|
|
1686
|
+
* @param { string | Buffer } pfx - The content of .pfx file
|
|
1687
|
+
* @param { string? } passphrase - Optional. The passphrase of .pfx file
|
|
1688
|
+
*
|
|
1689
|
+
* @returns Instance of SecureContextOptions
|
|
1690
|
+
*
|
|
1691
|
+
* @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
|
|
1692
|
+
*
|
|
1693
|
+
*/
|
|
1694
|
+
function createPfxCertOption(pfx, passphrase) {
|
|
1695
|
+
if (pfx.length === 0) {
|
|
1696
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "pfx"), ErrorCode.InvalidParameter);
|
|
1697
|
+
}
|
|
1698
|
+
return {
|
|
1699
|
+
pfx,
|
|
1700
|
+
passphrase,
|
|
1701
|
+
};
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
// Copyright (c) Microsoft Corporation.
|
|
1705
|
+
// Following keys are used by SDK internally
|
|
1706
|
+
const ReservedKey = new Set([
|
|
1707
|
+
"authorityHost",
|
|
1708
|
+
"tenantId",
|
|
1709
|
+
"clientId",
|
|
1710
|
+
"clientSecret",
|
|
1711
|
+
"initiateLoginEndpoint",
|
|
1712
|
+
"applicationIdUri",
|
|
1713
|
+
"apiEndpoint",
|
|
1714
|
+
"apiName",
|
|
1715
|
+
"sqlServerEndpoint",
|
|
1716
|
+
"sqlUsername",
|
|
1717
|
+
"sqlPassword",
|
|
1718
|
+
"sqlDatabaseName",
|
|
1719
|
+
"sqlIdentityId",
|
|
1720
|
+
]);
|
|
1455
1721
|
/**
|
|
1456
1722
|
* A class providing credential and configuration.
|
|
1457
1723
|
* @beta
|
|
@@ -1625,10 +1891,10 @@ class TeamsFx {
|
|
|
1625
1891
|
this.configuration.set("sqlDatabaseName", env.SQL_DATABASE_NAME);
|
|
1626
1892
|
this.configuration.set("sqlIdentityId", env.IDENTITY_ID);
|
|
1627
1893
|
Object.keys(env).forEach((key) => {
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
this.configuration.set(key.substring(8), value);
|
|
1894
|
+
if (ReservedKey.has(key)) {
|
|
1895
|
+
internalLogger.warn(`The name of environment variable ${key} is preserved. Will not load it as configuration.`);
|
|
1631
1896
|
}
|
|
1897
|
+
this.configuration.set(key, env[key]);
|
|
1632
1898
|
});
|
|
1633
1899
|
}
|
|
1634
1900
|
}
|
|
@@ -1662,13 +1928,6 @@ class NotificationMiddleware {
|
|
|
1662
1928
|
await this.conversationReferenceStore.set(reference);
|
|
1663
1929
|
break;
|
|
1664
1930
|
}
|
|
1665
|
-
case ActivityType.CurrentBotMessaged: {
|
|
1666
|
-
const reference = TurnContext.getConversationReference(context.activity);
|
|
1667
|
-
if (!(await this.conversationReferenceStore.check(reference))) {
|
|
1668
|
-
await this.conversationReferenceStore.set(reference);
|
|
1669
|
-
}
|
|
1670
|
-
break;
|
|
1671
|
-
}
|
|
1672
1931
|
case ActivityType.CurrentBotUninstalled:
|
|
1673
1932
|
case ActivityType.TeamDeleted: {
|
|
1674
1933
|
const reference = TurnContext.getConversationReference(context.activity);
|
|
@@ -1690,9 +1949,6 @@ class NotificationMiddleware {
|
|
|
1690
1949
|
return ActivityType.CurrentBotUninstalled;
|
|
1691
1950
|
}
|
|
1692
1951
|
}
|
|
1693
|
-
else if (activityType === "message") {
|
|
1694
|
-
return ActivityType.CurrentBotMessaged;
|
|
1695
|
-
}
|
|
1696
1952
|
else if (activityType === "conversationUpdate") {
|
|
1697
1953
|
const eventType = (_b = activity.channelData) === null || _b === void 0 ? void 0 : _b.eventType;
|
|
1698
1954
|
if (eventType === "teamDeleted") {
|
|
@@ -2260,7 +2516,7 @@ class TeamsBotInstallation {
|
|
|
2260
2516
|
}
|
|
2261
2517
|
}
|
|
2262
2518
|
/**
|
|
2263
|
-
* Provide utilities to send notification to varies targets (e.g., member,
|
|
2519
|
+
* Provide utilities to send notification to varies targets (e.g., member, group, channel).
|
|
2264
2520
|
*
|
|
2265
2521
|
* @beta
|
|
2266
2522
|
*/
|
|
@@ -2329,7 +2585,7 @@ class NotificationBot {
|
|
|
2329
2585
|
/**
|
|
2330
2586
|
* Provide utilities for bot conversation, including:
|
|
2331
2587
|
* - handle command and response.
|
|
2332
|
-
* - send notification to varies targets (e.g., member,
|
|
2588
|
+
* - send notification to varies targets (e.g., member, group, channel).
|
|
2333
2589
|
*
|
|
2334
2590
|
* @example
|
|
2335
2591
|
* For command and response, you can register your commands through the constructor, or use the `registerCommand` and `registerCommands` API to add commands later.
|
|
@@ -2339,9 +2595,7 @@ class NotificationBot {
|
|
|
2339
2595
|
* const conversationBot = new ConversationBot({
|
|
2340
2596
|
* command: {
|
|
2341
2597
|
* enabled: true,
|
|
2342
|
-
*
|
|
2343
|
-
* commands: [ new HelloWorldCommandHandler() ],
|
|
2344
|
-
* },
|
|
2598
|
+
* commands: [ new HelloWorldCommandHandler() ],
|
|
2345
2599
|
* },
|
|
2346
2600
|
* });
|
|
2347
2601
|
*
|
|
@@ -2349,7 +2603,7 @@ class NotificationBot {
|
|
|
2349
2603
|
* conversationBot.command.registerCommand(new HelpCommandHandler());
|
|
2350
2604
|
* ```
|
|
2351
2605
|
*
|
|
2352
|
-
* For notification, you can enable notification at initialization, then send
|
|
2606
|
+
* For notification, you can enable notification at initialization, then send notifications at any time.
|
|
2353
2607
|
*
|
|
2354
2608
|
* ```typescript
|
|
2355
2609
|
* // enable through constructor
|
|
@@ -2377,7 +2631,7 @@ class NotificationBot {
|
|
|
2377
2631
|
*
|
|
2378
2632
|
* For command and response, ensure each command should ONLY be registered with the command once, otherwise it'll cause unexpected behavior if you register the same command more than once.
|
|
2379
2633
|
*
|
|
2380
|
-
* For notification, set `notification.
|
|
2634
|
+
* For notification, set `notification.storage` in {@link ConversationOptions} to use your own storage implementation.
|
|
2381
2635
|
*
|
|
2382
2636
|
* @beta
|
|
2383
2637
|
*/
|
|
@@ -2385,26 +2639,76 @@ class ConversationBot {
|
|
|
2385
2639
|
/**
|
|
2386
2640
|
* Creates new instance of the `ConversationBot`.
|
|
2387
2641
|
*
|
|
2642
|
+
* @remarks
|
|
2643
|
+
* It's recommended to create your own adapter and storage for production environment instead of the default one.
|
|
2644
|
+
*
|
|
2388
2645
|
* @param options - initialize options
|
|
2389
2646
|
*
|
|
2390
2647
|
* @beta
|
|
2391
2648
|
*/
|
|
2392
2649
|
constructor(options) {
|
|
2650
|
+
var _a, _b;
|
|
2393
2651
|
if (options.adapter) {
|
|
2394
2652
|
this.adapter = options.adapter;
|
|
2395
2653
|
}
|
|
2396
2654
|
else {
|
|
2397
|
-
this.adapter =
|
|
2398
|
-
appId: process.env.BOT_ID,
|
|
2399
|
-
appPassword: process.env.BOT_PASSWORD,
|
|
2400
|
-
});
|
|
2655
|
+
this.adapter = this.createDefaultAdapter(options.adapterConfig);
|
|
2401
2656
|
}
|
|
2402
|
-
if (options.command.enabled) {
|
|
2403
|
-
this.command = new CommandBot(this.adapter, options.command
|
|
2657
|
+
if ((_a = options.command) === null || _a === void 0 ? void 0 : _a.enabled) {
|
|
2658
|
+
this.command = new CommandBot(this.adapter, options.command);
|
|
2404
2659
|
}
|
|
2405
|
-
if (options.notification.enabled) {
|
|
2406
|
-
this.notification = new NotificationBot(this.adapter, options.notification
|
|
2660
|
+
if ((_b = options.notification) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
2661
|
+
this.notification = new NotificationBot(this.adapter, options.notification);
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
createDefaultAdapter(adapterConfig) {
|
|
2665
|
+
const adapter = adapterConfig === undefined
|
|
2666
|
+
? new BotFrameworkAdapter({
|
|
2667
|
+
appId: process.env.BOT_ID,
|
|
2668
|
+
appPassword: process.env.BOT_PASSWORD,
|
|
2669
|
+
})
|
|
2670
|
+
: new BotFrameworkAdapter(adapterConfig);
|
|
2671
|
+
// the default error handler
|
|
2672
|
+
adapter.onTurnError = async (context, error) => {
|
|
2673
|
+
// This check writes out errors to console.
|
|
2674
|
+
console.error(`[onTurnError] unhandled error: ${error}`);
|
|
2675
|
+
// Send a trace activity, which will be displayed in Bot Framework Emulator
|
|
2676
|
+
await context.sendTraceActivity("OnTurnError Trace", `${error}`, "https://www.botframework.com/schemas/error", "TurnError");
|
|
2677
|
+
// Send a message to the user
|
|
2678
|
+
await context.sendActivity(`The bot encountered unhandled error: ${error.message}`);
|
|
2679
|
+
await context.sendActivity("To continue to run this bot, please fix the bot source code.");
|
|
2680
|
+
};
|
|
2681
|
+
return adapter;
|
|
2682
|
+
}
|
|
2683
|
+
/**
|
|
2684
|
+
* The request handler to integrate with web request.
|
|
2685
|
+
*
|
|
2686
|
+
* @param req - an Express or Restify style request object.
|
|
2687
|
+
* @param res - an Express or Restify style response object.
|
|
2688
|
+
* @param logic - the additional function to handle bot context.
|
|
2689
|
+
*
|
|
2690
|
+
* @example
|
|
2691
|
+
* For example, to use with Restify:
|
|
2692
|
+
* ``` typescript
|
|
2693
|
+
* // The default/empty behavior
|
|
2694
|
+
* server.post("api/messages", conversationBot.requestHandler);
|
|
2695
|
+
*
|
|
2696
|
+
* // Or, add your own logic
|
|
2697
|
+
* server.post("api/messages", async (req, res) => {
|
|
2698
|
+
* await conversationBot.requestHandler(req, res, async (context) => {
|
|
2699
|
+
* // your-own-context-logic
|
|
2700
|
+
* });
|
|
2701
|
+
* });
|
|
2702
|
+
* ```
|
|
2703
|
+
*
|
|
2704
|
+
* @beta
|
|
2705
|
+
*/
|
|
2706
|
+
async requestHandler(req, res, logic) {
|
|
2707
|
+
if (logic === undefined) {
|
|
2708
|
+
// create empty logic
|
|
2709
|
+
logic = async () => { };
|
|
2407
2710
|
}
|
|
2711
|
+
await this.adapter.processActivity(req, res, logic);
|
|
2408
2712
|
}
|
|
2409
2713
|
}
|
|
2410
2714
|
|
|
@@ -2417,8 +2721,8 @@ class MessageBuilder {
|
|
|
2417
2721
|
/**
|
|
2418
2722
|
* Build a bot message activity attached with adaptive card.
|
|
2419
2723
|
*
|
|
2420
|
-
* @param getCardData Function to prepare your card data.
|
|
2421
2724
|
* @param cardTemplate The adaptive card template.
|
|
2725
|
+
* @param data card data used to render the template.
|
|
2422
2726
|
* @returns A bot message activity attached with an adaptive card.
|
|
2423
2727
|
*
|
|
2424
2728
|
* @example
|
|
@@ -2443,19 +2747,18 @@ class MessageBuilder {
|
|
|
2443
2747
|
* title: string,
|
|
2444
2748
|
* description: string
|
|
2445
2749
|
* };
|
|
2446
|
-
* const card = MessageBuilder.attachAdaptiveCard<CardData>(
|
|
2447
|
-
*
|
|
2448
|
-
*
|
|
2449
|
-
*
|
|
2450
|
-
*
|
|
2750
|
+
* const card = MessageBuilder.attachAdaptiveCard<CardData>(
|
|
2751
|
+
* cardTemplate, {
|
|
2752
|
+
* title: "sample card title",
|
|
2753
|
+
* description: "sample card description"
|
|
2754
|
+
* });
|
|
2451
2755
|
* ```
|
|
2452
2756
|
*
|
|
2453
2757
|
* @beta
|
|
2454
2758
|
*/
|
|
2455
|
-
static attachAdaptiveCard(
|
|
2456
|
-
const cardData = getCardData();
|
|
2759
|
+
static attachAdaptiveCard(cardTemplate, data) {
|
|
2457
2760
|
return {
|
|
2458
|
-
attachments: [CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(
|
|
2761
|
+
attachments: [CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(data))],
|
|
2459
2762
|
};
|
|
2460
2763
|
}
|
|
2461
2764
|
/**
|
|
@@ -2562,5 +2865,5 @@ class MessageBuilder {
|
|
|
2562
2865
|
}
|
|
2563
2866
|
}
|
|
2564
2867
|
|
|
2565
|
-
export { AppCredential, BearerTokenAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, LogLevel, Member, MessageBuilder, MsGraphAuthProvider, NotificationBot, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
|
|
2868
|
+
export { ApiKeyLocation, ApiKeyProvider, AppCredential, BasicAuthProvider, BearerTokenAuthProvider, CertificateAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, LogLevel, Member, MessageBuilder, MsGraphAuthProvider, NotificationBot, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
|
|
2566
2869
|
//# sourceMappingURL=index.esm2017.mjs.map
|