@microsoft/teamsfx 0.6.3-alpha.8d048e1f1.0 → 0.6.3-alpha.dabb22057.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 +194 -6
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +348 -42
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +202 -5
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +360 -40
- package/dist/index.node.cjs.js.map +1 -1
- package/package.json +3 -3
- package/types/teamsfx.d.ts +233 -36
package/dist/index.node.cjs.js
CHANGED
|
@@ -12,6 +12,7 @@ var botbuilder = require('botbuilder');
|
|
|
12
12
|
var botbuilderDialogs = require('botbuilder-dialogs');
|
|
13
13
|
var uuid = require('uuid');
|
|
14
14
|
var axios = require('axios');
|
|
15
|
+
var https = require('https');
|
|
15
16
|
var path = require('path');
|
|
16
17
|
var fs = require('fs');
|
|
17
18
|
|
|
@@ -100,6 +101,10 @@ exports.ErrorCode = void 0;
|
|
|
100
101
|
* Identity type error.
|
|
101
102
|
*/
|
|
102
103
|
ErrorCode["IdentityTypeNotSupported"] = "IdentityTypeNotSupported";
|
|
104
|
+
/**
|
|
105
|
+
* Authentication info already exists error.
|
|
106
|
+
*/
|
|
107
|
+
ErrorCode["AuthorizationInfoAlreadyExists"] = "AuthorizationInfoAlreadyExists";
|
|
103
108
|
})(exports.ErrorCode || (exports.ErrorCode = {}));
|
|
104
109
|
/**
|
|
105
110
|
* @internal
|
|
@@ -121,6 +126,14 @@ ErrorMessage.FailToAcquireTokenOnBehalfOfUser = "Failed to acquire access token
|
|
|
121
126
|
ErrorMessage.OnlyMSTeamsChannelSupported = "{0} is only supported in MS Teams Channel";
|
|
122
127
|
// IdentityTypeNotSupported Error
|
|
123
128
|
ErrorMessage.IdentityTypeNotSupported = "{0} identity is not supported in {1}";
|
|
129
|
+
// AuthorizationInfoError
|
|
130
|
+
ErrorMessage.AuthorizationHeaderAlreadyExists = "Authorization header already exists!";
|
|
131
|
+
ErrorMessage.BasicCredentialAlreadyExists = "Basic credential already exists!";
|
|
132
|
+
// InvalidParameter Error
|
|
133
|
+
ErrorMessage.EmptyParameter = "Parameter {0} is empty";
|
|
134
|
+
ErrorMessage.DuplicateHttpsOptionProperty = "Axios HTTPS agent already defined value for property {0}";
|
|
135
|
+
ErrorMessage.DuplicateApiKeyInHeader = "The request already defined api key in request header with name {0}.";
|
|
136
|
+
ErrorMessage.DuplicateApiKeyInQueryParam = "The request already defined api key in query parameter with name {0}.";
|
|
124
137
|
/**
|
|
125
138
|
* Error class with code and message thrown by the SDK.
|
|
126
139
|
*
|
|
@@ -1476,7 +1489,7 @@ function createApiClient(apiEndpoint, authProvider) {
|
|
|
1476
1489
|
*/
|
|
1477
1490
|
class BearerTokenAuthProvider {
|
|
1478
1491
|
/**
|
|
1479
|
-
* @param getToken Function that returns the content of bearer token used in http request
|
|
1492
|
+
* @param { () => Promise<string> } getToken - Function that returns the content of bearer token used in http request
|
|
1480
1493
|
*
|
|
1481
1494
|
* @beta
|
|
1482
1495
|
*/
|
|
@@ -1486,9 +1499,13 @@ class BearerTokenAuthProvider {
|
|
|
1486
1499
|
/**
|
|
1487
1500
|
* Adds authentication info to http requests
|
|
1488
1501
|
*
|
|
1489
|
-
* @param config - Contains all the request information and can be updated to include extra authentication info.
|
|
1502
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1490
1503
|
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1491
1504
|
*
|
|
1505
|
+
* @returns Updated axios request config.
|
|
1506
|
+
*
|
|
1507
|
+
* @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header already exists in request configuration.
|
|
1508
|
+
*
|
|
1492
1509
|
* @beta
|
|
1493
1510
|
*/
|
|
1494
1511
|
AddAuthenticationInfo(config) {
|
|
@@ -1498,7 +1515,7 @@ class BearerTokenAuthProvider {
|
|
|
1498
1515
|
config.headers = {};
|
|
1499
1516
|
}
|
|
1500
1517
|
if (config.headers["Authorization"]) {
|
|
1501
|
-
throw new
|
|
1518
|
+
throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1502
1519
|
}
|
|
1503
1520
|
config.headers["Authorization"] = `Bearer ${token}`;
|
|
1504
1521
|
return config;
|
|
@@ -1507,6 +1524,265 @@ class BearerTokenAuthProvider {
|
|
|
1507
1524
|
}
|
|
1508
1525
|
|
|
1509
1526
|
// Copyright (c) Microsoft Corporation.
|
|
1527
|
+
/**
|
|
1528
|
+
* Provider that handles Basic authentication
|
|
1529
|
+
*
|
|
1530
|
+
* @beta
|
|
1531
|
+
*/
|
|
1532
|
+
class BasicAuthProvider {
|
|
1533
|
+
/**
|
|
1534
|
+
*
|
|
1535
|
+
* @param { string } userName - Username used in basic auth
|
|
1536
|
+
* @param { string } password - Password used in basic auth
|
|
1537
|
+
*
|
|
1538
|
+
* @throws {@link ErrorCode|InvalidParameter} - when username or password is empty.
|
|
1539
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1540
|
+
*
|
|
1541
|
+
* @beta
|
|
1542
|
+
*/
|
|
1543
|
+
constructor(userName, password) {
|
|
1544
|
+
if (!userName) {
|
|
1545
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "username"), exports.ErrorCode.InvalidParameter);
|
|
1546
|
+
}
|
|
1547
|
+
if (!password) {
|
|
1548
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "password"), exports.ErrorCode.InvalidParameter);
|
|
1549
|
+
}
|
|
1550
|
+
this.userName = userName;
|
|
1551
|
+
this.password = password;
|
|
1552
|
+
}
|
|
1553
|
+
/**
|
|
1554
|
+
* Adds authentication info to http requests
|
|
1555
|
+
*
|
|
1556
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1557
|
+
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1558
|
+
*
|
|
1559
|
+
* @returns Updated axios request config.
|
|
1560
|
+
*
|
|
1561
|
+
* @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header or auth property already exists in request configuration.
|
|
1562
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1563
|
+
*
|
|
1564
|
+
* @beta
|
|
1565
|
+
*/
|
|
1566
|
+
AddAuthenticationInfo(config) {
|
|
1567
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1568
|
+
if (config.headers && config.headers["Authorization"]) {
|
|
1569
|
+
throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1570
|
+
}
|
|
1571
|
+
if (config.auth) {
|
|
1572
|
+
throw new ErrorWithCode(ErrorMessage.BasicCredentialAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1573
|
+
}
|
|
1574
|
+
config.auth = {
|
|
1575
|
+
username: this.userName,
|
|
1576
|
+
password: this.password,
|
|
1577
|
+
};
|
|
1578
|
+
return config;
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
// Copyright (c) Microsoft Corporation.
|
|
1584
|
+
/**
|
|
1585
|
+
* Provider that handles API Key authentication
|
|
1586
|
+
*
|
|
1587
|
+
* @beta
|
|
1588
|
+
*/
|
|
1589
|
+
class ApiKeyProvider {
|
|
1590
|
+
/**
|
|
1591
|
+
*
|
|
1592
|
+
* @param { string } keyName - The name of request header or query parameter that specifies API Key
|
|
1593
|
+
* @param { string } keyValue - The value of API Key
|
|
1594
|
+
* @param { ApiKeyLocation } keyLocation - The location of API Key: request header or query parameter.
|
|
1595
|
+
*
|
|
1596
|
+
* @throws {@link ErrorCode|InvalidParameter} - when key name or key value is empty.
|
|
1597
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1598
|
+
*
|
|
1599
|
+
* @beta
|
|
1600
|
+
*/
|
|
1601
|
+
constructor(keyName, keyValue, keyLocation) {
|
|
1602
|
+
if (!keyName) {
|
|
1603
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "keyName"), exports.ErrorCode.InvalidParameter);
|
|
1604
|
+
}
|
|
1605
|
+
if (!keyValue) {
|
|
1606
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "keyVaule"), exports.ErrorCode.InvalidParameter);
|
|
1607
|
+
}
|
|
1608
|
+
this.keyName = keyName;
|
|
1609
|
+
this.keyValue = keyValue;
|
|
1610
|
+
this.keyLocation = keyLocation;
|
|
1611
|
+
}
|
|
1612
|
+
/**
|
|
1613
|
+
* Adds authentication info to http requests
|
|
1614
|
+
*
|
|
1615
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1616
|
+
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1617
|
+
*
|
|
1618
|
+
* @returns Updated axios request config.
|
|
1619
|
+
*
|
|
1620
|
+
* @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when API key already exists in request header or url query parameter.
|
|
1621
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1622
|
+
*
|
|
1623
|
+
* @beta
|
|
1624
|
+
*/
|
|
1625
|
+
AddAuthenticationInfo(config) {
|
|
1626
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1627
|
+
switch (this.keyLocation) {
|
|
1628
|
+
case exports.ApiKeyLocation.Header:
|
|
1629
|
+
if (!config.headers) {
|
|
1630
|
+
config.headers = {};
|
|
1631
|
+
}
|
|
1632
|
+
if (config.headers[this.keyName]) {
|
|
1633
|
+
throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInHeader, this.keyName), exports.ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1634
|
+
}
|
|
1635
|
+
config.headers[this.keyName] = this.keyValue;
|
|
1636
|
+
break;
|
|
1637
|
+
case exports.ApiKeyLocation.QueryParams:
|
|
1638
|
+
if (!config.params) {
|
|
1639
|
+
config.params = {};
|
|
1640
|
+
}
|
|
1641
|
+
const url = new URL(config.url, config.baseURL);
|
|
1642
|
+
if (config.params[this.keyName] || url.searchParams.has(this.keyName)) {
|
|
1643
|
+
throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInQueryParam, this.keyName), exports.ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1644
|
+
}
|
|
1645
|
+
config.params[this.keyName] = this.keyValue;
|
|
1646
|
+
break;
|
|
1647
|
+
}
|
|
1648
|
+
return config;
|
|
1649
|
+
});
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
/**
|
|
1653
|
+
* Define available location for API Key location
|
|
1654
|
+
*
|
|
1655
|
+
* @beta
|
|
1656
|
+
*/
|
|
1657
|
+
exports.ApiKeyLocation = void 0;
|
|
1658
|
+
(function (ApiKeyLocation) {
|
|
1659
|
+
/**
|
|
1660
|
+
* The API Key is placed in request header
|
|
1661
|
+
*/
|
|
1662
|
+
ApiKeyLocation[ApiKeyLocation["Header"] = 0] = "Header";
|
|
1663
|
+
/**
|
|
1664
|
+
* The API Key is placed in query parameter
|
|
1665
|
+
*/
|
|
1666
|
+
ApiKeyLocation[ApiKeyLocation["QueryParams"] = 1] = "QueryParams";
|
|
1667
|
+
})(exports.ApiKeyLocation || (exports.ApiKeyLocation = {}));
|
|
1668
|
+
|
|
1669
|
+
// Copyright (c) Microsoft Corporation.
|
|
1670
|
+
/**
|
|
1671
|
+
* Provider that handles Certificate authentication
|
|
1672
|
+
*
|
|
1673
|
+
* @beta
|
|
1674
|
+
*/
|
|
1675
|
+
class CertificateAuthProvider {
|
|
1676
|
+
/**
|
|
1677
|
+
*
|
|
1678
|
+
* @param { SecureContextOptions } certOption - information about the cert used in http requests
|
|
1679
|
+
*
|
|
1680
|
+
* @throws {@link ErrorCode|InvalidParameter} - when cert option is empty.
|
|
1681
|
+
*
|
|
1682
|
+
* @beta
|
|
1683
|
+
*/
|
|
1684
|
+
constructor(certOption) {
|
|
1685
|
+
if (certOption && Object.keys(certOption).length !== 0) {
|
|
1686
|
+
this.certOption = certOption;
|
|
1687
|
+
}
|
|
1688
|
+
else {
|
|
1689
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "certOption"), exports.ErrorCode.InvalidParameter);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1693
|
+
* Adds authentication info to http requests.
|
|
1694
|
+
*
|
|
1695
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1696
|
+
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1697
|
+
*
|
|
1698
|
+
* @returns Updated axios request config.
|
|
1699
|
+
*
|
|
1700
|
+
* @throws {@link ErrorCode|InvalidParameter} - when custom httpsAgent in the request has duplicate properties with certOption provided in constructor.
|
|
1701
|
+
*
|
|
1702
|
+
* @beta
|
|
1703
|
+
*/
|
|
1704
|
+
AddAuthenticationInfo(config) {
|
|
1705
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1706
|
+
if (!config.httpsAgent) {
|
|
1707
|
+
config.httpsAgent = new https.Agent(this.certOption);
|
|
1708
|
+
}
|
|
1709
|
+
else {
|
|
1710
|
+
const existingProperties = new Set(Object.keys(config.httpsAgent.options));
|
|
1711
|
+
for (const property of Object.keys(this.certOption)) {
|
|
1712
|
+
if (existingProperties.has(property)) {
|
|
1713
|
+
throw new ErrorWithCode(formatString(ErrorMessage.DuplicateHttpsOptionProperty, property), exports.ErrorCode.InvalidParameter);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
Object.assign(config.httpsAgent.options, this.certOption);
|
|
1717
|
+
}
|
|
1718
|
+
return config;
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
* Helper to create SecureContextOptions from PEM format cert
|
|
1724
|
+
*
|
|
1725
|
+
* @param { string | Buffer } cert - The cert chain in PEM format
|
|
1726
|
+
* @param { string | Buffer } key - The private key for the cert chain
|
|
1727
|
+
* @param { {passphrase?: string; ca?: string | Buffer} } options - Optional settings when create the cert options.
|
|
1728
|
+
*
|
|
1729
|
+
* @returns Instance of SecureContextOptions
|
|
1730
|
+
*
|
|
1731
|
+
* @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
|
|
1732
|
+
*
|
|
1733
|
+
*/
|
|
1734
|
+
function createPemCertOption(cert, key, options) {
|
|
1735
|
+
if (cert.length === 0) {
|
|
1736
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "cert"), exports.ErrorCode.InvalidParameter);
|
|
1737
|
+
}
|
|
1738
|
+
if (key.length === 0) {
|
|
1739
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "key"), exports.ErrorCode.InvalidParameter);
|
|
1740
|
+
}
|
|
1741
|
+
return {
|
|
1742
|
+
cert,
|
|
1743
|
+
key,
|
|
1744
|
+
passphrase: options === null || options === void 0 ? void 0 : options.passphrase,
|
|
1745
|
+
ca: options === null || options === void 0 ? void 0 : options.ca,
|
|
1746
|
+
};
|
|
1747
|
+
}
|
|
1748
|
+
/**
|
|
1749
|
+
* Helper to create SecureContextOptions from PFX format cert
|
|
1750
|
+
*
|
|
1751
|
+
* @param { string | Buffer } pfx - The content of .pfx file
|
|
1752
|
+
* @param { {passphrase?: string} } options - Optional settings when create the cert options.
|
|
1753
|
+
*
|
|
1754
|
+
* @returns Instance of SecureContextOptions
|
|
1755
|
+
*
|
|
1756
|
+
* @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
|
|
1757
|
+
*
|
|
1758
|
+
*/
|
|
1759
|
+
function createPfxCertOption(pfx, options) {
|
|
1760
|
+
if (pfx.length === 0) {
|
|
1761
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "pfx"), exports.ErrorCode.InvalidParameter);
|
|
1762
|
+
}
|
|
1763
|
+
return {
|
|
1764
|
+
pfx,
|
|
1765
|
+
passphrase: options === null || options === void 0 ? void 0 : options.passphrase,
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
// Copyright (c) Microsoft Corporation.
|
|
1770
|
+
// Following keys are used by SDK internally
|
|
1771
|
+
const ReservedKey = new Set([
|
|
1772
|
+
"authorityHost",
|
|
1773
|
+
"tenantId",
|
|
1774
|
+
"clientId",
|
|
1775
|
+
"clientSecret",
|
|
1776
|
+
"initiateLoginEndpoint",
|
|
1777
|
+
"applicationIdUri",
|
|
1778
|
+
"apiEndpoint",
|
|
1779
|
+
"apiName",
|
|
1780
|
+
"sqlServerEndpoint",
|
|
1781
|
+
"sqlUsername",
|
|
1782
|
+
"sqlPassword",
|
|
1783
|
+
"sqlDatabaseName",
|
|
1784
|
+
"sqlIdentityId",
|
|
1785
|
+
]);
|
|
1510
1786
|
/**
|
|
1511
1787
|
* A class providing credential and configuration.
|
|
1512
1788
|
* @beta
|
|
@@ -1684,10 +1960,10 @@ class TeamsFx {
|
|
|
1684
1960
|
this.configuration.set("sqlDatabaseName", env.SQL_DATABASE_NAME);
|
|
1685
1961
|
this.configuration.set("sqlIdentityId", env.IDENTITY_ID);
|
|
1686
1962
|
Object.keys(env).forEach((key) => {
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
this.configuration.set(key.substring(8), value);
|
|
1963
|
+
if (ReservedKey.has(key)) {
|
|
1964
|
+
internalLogger.warn(`The name of environment variable ${key} is preserved. Will not load it as configuration.`);
|
|
1690
1965
|
}
|
|
1966
|
+
this.configuration.set(key, env[key]);
|
|
1691
1967
|
});
|
|
1692
1968
|
}
|
|
1693
1969
|
}
|
|
@@ -1722,13 +1998,6 @@ class NotificationMiddleware {
|
|
|
1722
1998
|
yield this.conversationReferenceStore.set(reference);
|
|
1723
1999
|
break;
|
|
1724
2000
|
}
|
|
1725
|
-
case ActivityType.CurrentBotMessaged: {
|
|
1726
|
-
const reference = botbuilder.TurnContext.getConversationReference(context.activity);
|
|
1727
|
-
if (!(yield this.conversationReferenceStore.check(reference))) {
|
|
1728
|
-
yield this.conversationReferenceStore.set(reference);
|
|
1729
|
-
}
|
|
1730
|
-
break;
|
|
1731
|
-
}
|
|
1732
2001
|
case ActivityType.CurrentBotUninstalled:
|
|
1733
2002
|
case ActivityType.TeamDeleted: {
|
|
1734
2003
|
const reference = botbuilder.TurnContext.getConversationReference(context.activity);
|
|
@@ -1751,9 +2020,6 @@ class NotificationMiddleware {
|
|
|
1751
2020
|
return ActivityType.CurrentBotUninstalled;
|
|
1752
2021
|
}
|
|
1753
2022
|
}
|
|
1754
|
-
else if (activityType === "message") {
|
|
1755
|
-
return ActivityType.CurrentBotMessaged;
|
|
1756
|
-
}
|
|
1757
2023
|
else if (activityType === "conversationUpdate") {
|
|
1758
2024
|
const eventType = (_b = activity.channelData) === null || _b === void 0 ? void 0 : _b.eventType;
|
|
1759
2025
|
if (eventType === "teamDeleted") {
|
|
@@ -2347,7 +2613,7 @@ class TeamsBotInstallation {
|
|
|
2347
2613
|
}
|
|
2348
2614
|
}
|
|
2349
2615
|
/**
|
|
2350
|
-
* Provide utilities to send notification to varies targets (e.g., member,
|
|
2616
|
+
* Provide utilities to send notification to varies targets (e.g., member, group, channel).
|
|
2351
2617
|
*
|
|
2352
2618
|
* @beta
|
|
2353
2619
|
*/
|
|
@@ -2418,7 +2684,7 @@ class NotificationBot {
|
|
|
2418
2684
|
/**
|
|
2419
2685
|
* Provide utilities for bot conversation, including:
|
|
2420
2686
|
* - handle command and response.
|
|
2421
|
-
* - send notification to varies targets (e.g., member,
|
|
2687
|
+
* - send notification to varies targets (e.g., member, group, channel).
|
|
2422
2688
|
*
|
|
2423
2689
|
* @example
|
|
2424
2690
|
* For command and response, you can register your commands through the constructor, or use the `registerCommand` and `registerCommands` API to add commands later.
|
|
@@ -2428,9 +2694,7 @@ class NotificationBot {
|
|
|
2428
2694
|
* const conversationBot = new ConversationBot({
|
|
2429
2695
|
* command: {
|
|
2430
2696
|
* enabled: true,
|
|
2431
|
-
*
|
|
2432
|
-
* commands: [ new HelloWorldCommandHandler() ],
|
|
2433
|
-
* },
|
|
2697
|
+
* commands: [ new HelloWorldCommandHandler() ],
|
|
2434
2698
|
* },
|
|
2435
2699
|
* });
|
|
2436
2700
|
*
|
|
@@ -2438,7 +2702,7 @@ class NotificationBot {
|
|
|
2438
2702
|
* conversationBot.command.registerCommand(new HelpCommandHandler());
|
|
2439
2703
|
* ```
|
|
2440
2704
|
*
|
|
2441
|
-
* For notification, you can enable notification at initialization, then send
|
|
2705
|
+
* For notification, you can enable notification at initialization, then send notifications at any time.
|
|
2442
2706
|
*
|
|
2443
2707
|
* ```typescript
|
|
2444
2708
|
* // enable through constructor
|
|
@@ -2466,7 +2730,7 @@ class NotificationBot {
|
|
|
2466
2730
|
*
|
|
2467
2731
|
* 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.
|
|
2468
2732
|
*
|
|
2469
|
-
* For notification, set `notification.
|
|
2733
|
+
* For notification, set `notification.storage` in {@link ConversationOptions} to use your own storage implementation.
|
|
2470
2734
|
*
|
|
2471
2735
|
* @beta
|
|
2472
2736
|
*/
|
|
@@ -2474,27 +2738,79 @@ class ConversationBot {
|
|
|
2474
2738
|
/**
|
|
2475
2739
|
* Creates new instance of the `ConversationBot`.
|
|
2476
2740
|
*
|
|
2741
|
+
* @remarks
|
|
2742
|
+
* It's recommended to create your own adapter and storage for production environment instead of the default one.
|
|
2743
|
+
*
|
|
2477
2744
|
* @param options - initialize options
|
|
2478
2745
|
*
|
|
2479
2746
|
* @beta
|
|
2480
2747
|
*/
|
|
2481
2748
|
constructor(options) {
|
|
2749
|
+
var _a, _b;
|
|
2482
2750
|
if (options.adapter) {
|
|
2483
2751
|
this.adapter = options.adapter;
|
|
2484
2752
|
}
|
|
2485
2753
|
else {
|
|
2486
|
-
this.adapter =
|
|
2487
|
-
appId: process.env.BOT_ID,
|
|
2488
|
-
appPassword: process.env.BOT_PASSWORD,
|
|
2489
|
-
});
|
|
2754
|
+
this.adapter = this.createDefaultAdapter(options.adapterConfig);
|
|
2490
2755
|
}
|
|
2491
|
-
if (options.command.enabled) {
|
|
2492
|
-
this.command = new CommandBot(this.adapter, options.command
|
|
2756
|
+
if ((_a = options.command) === null || _a === void 0 ? void 0 : _a.enabled) {
|
|
2757
|
+
this.command = new CommandBot(this.adapter, options.command);
|
|
2493
2758
|
}
|
|
2494
|
-
if (options.notification.enabled) {
|
|
2495
|
-
this.notification = new NotificationBot(this.adapter, options.notification
|
|
2759
|
+
if ((_b = options.notification) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
2760
|
+
this.notification = new NotificationBot(this.adapter, options.notification);
|
|
2496
2761
|
}
|
|
2497
2762
|
}
|
|
2763
|
+
createDefaultAdapter(adapterConfig) {
|
|
2764
|
+
const adapter = adapterConfig === undefined
|
|
2765
|
+
? new botbuilder.BotFrameworkAdapter({
|
|
2766
|
+
appId: process.env.BOT_ID,
|
|
2767
|
+
appPassword: process.env.BOT_PASSWORD,
|
|
2768
|
+
})
|
|
2769
|
+
: new botbuilder.BotFrameworkAdapter(adapterConfig);
|
|
2770
|
+
// the default error handler
|
|
2771
|
+
adapter.onTurnError = (context, error) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
2772
|
+
// This check writes out errors to console.
|
|
2773
|
+
console.error(`[onTurnError] unhandled error: ${error}`);
|
|
2774
|
+
// Send a trace activity, which will be displayed in Bot Framework Emulator
|
|
2775
|
+
yield context.sendTraceActivity("OnTurnError Trace", `${error}`, "https://www.botframework.com/schemas/error", "TurnError");
|
|
2776
|
+
// Send a message to the user
|
|
2777
|
+
yield context.sendActivity(`The bot encountered unhandled error: ${error.message}`);
|
|
2778
|
+
yield context.sendActivity("To continue to run this bot, please fix the bot source code.");
|
|
2779
|
+
});
|
|
2780
|
+
return adapter;
|
|
2781
|
+
}
|
|
2782
|
+
/**
|
|
2783
|
+
* The request handler to integrate with web request.
|
|
2784
|
+
*
|
|
2785
|
+
* @param req - an Express or Restify style request object.
|
|
2786
|
+
* @param res - an Express or Restify style response object.
|
|
2787
|
+
* @param logic - the additional function to handle bot context.
|
|
2788
|
+
*
|
|
2789
|
+
* @example
|
|
2790
|
+
* For example, to use with Restify:
|
|
2791
|
+
* ``` typescript
|
|
2792
|
+
* // The default/empty behavior
|
|
2793
|
+
* server.post("api/messages", conversationBot.requestHandler);
|
|
2794
|
+
*
|
|
2795
|
+
* // Or, add your own logic
|
|
2796
|
+
* server.post("api/messages", async (req, res) => {
|
|
2797
|
+
* await conversationBot.requestHandler(req, res, async (context) => {
|
|
2798
|
+
* // your-own-context-logic
|
|
2799
|
+
* });
|
|
2800
|
+
* });
|
|
2801
|
+
* ```
|
|
2802
|
+
*
|
|
2803
|
+
* @beta
|
|
2804
|
+
*/
|
|
2805
|
+
requestHandler(req, res, logic) {
|
|
2806
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
2807
|
+
if (logic === undefined) {
|
|
2808
|
+
// create empty logic
|
|
2809
|
+
logic = () => tslib.__awaiter(this, void 0, void 0, function* () { });
|
|
2810
|
+
}
|
|
2811
|
+
yield this.adapter.processActivity(req, res, logic);
|
|
2812
|
+
});
|
|
2813
|
+
}
|
|
2498
2814
|
}
|
|
2499
2815
|
|
|
2500
2816
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -2506,8 +2822,8 @@ class MessageBuilder {
|
|
|
2506
2822
|
/**
|
|
2507
2823
|
* Build a bot message activity attached with adaptive card.
|
|
2508
2824
|
*
|
|
2509
|
-
* @param getCardData Function to prepare your card data.
|
|
2510
2825
|
* @param cardTemplate The adaptive card template.
|
|
2826
|
+
* @param data card data used to render the template.
|
|
2511
2827
|
* @returns A bot message activity attached with an adaptive card.
|
|
2512
2828
|
*
|
|
2513
2829
|
* @example
|
|
@@ -2532,19 +2848,18 @@ class MessageBuilder {
|
|
|
2532
2848
|
* title: string,
|
|
2533
2849
|
* description: string
|
|
2534
2850
|
* };
|
|
2535
|
-
* const card = MessageBuilder.attachAdaptiveCard<CardData>(
|
|
2536
|
-
*
|
|
2537
|
-
*
|
|
2538
|
-
*
|
|
2539
|
-
*
|
|
2851
|
+
* const card = MessageBuilder.attachAdaptiveCard<CardData>(
|
|
2852
|
+
* cardTemplate, {
|
|
2853
|
+
* title: "sample card title",
|
|
2854
|
+
* description: "sample card description"
|
|
2855
|
+
* });
|
|
2540
2856
|
* ```
|
|
2541
2857
|
*
|
|
2542
2858
|
* @beta
|
|
2543
2859
|
*/
|
|
2544
|
-
static attachAdaptiveCard(
|
|
2545
|
-
const cardData = getCardData();
|
|
2860
|
+
static attachAdaptiveCard(cardTemplate, data) {
|
|
2546
2861
|
return {
|
|
2547
|
-
attachments: [botbuilder.CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(
|
|
2862
|
+
attachments: [botbuilder.CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(data))],
|
|
2548
2863
|
};
|
|
2549
2864
|
}
|
|
2550
2865
|
/**
|
|
@@ -2651,8 +2966,11 @@ class MessageBuilder {
|
|
|
2651
2966
|
}
|
|
2652
2967
|
}
|
|
2653
2968
|
|
|
2969
|
+
exports.ApiKeyProvider = ApiKeyProvider;
|
|
2654
2970
|
exports.AppCredential = AppCredential;
|
|
2971
|
+
exports.BasicAuthProvider = BasicAuthProvider;
|
|
2655
2972
|
exports.BearerTokenAuthProvider = BearerTokenAuthProvider;
|
|
2973
|
+
exports.CertificateAuthProvider = CertificateAuthProvider;
|
|
2656
2974
|
exports.Channel = Channel;
|
|
2657
2975
|
exports.CommandBot = CommandBot;
|
|
2658
2976
|
exports.ConversationBot = ConversationBot;
|
|
@@ -2668,6 +2986,8 @@ exports.TeamsFx = TeamsFx;
|
|
|
2668
2986
|
exports.TeamsUserCredential = TeamsUserCredential;
|
|
2669
2987
|
exports.createApiClient = createApiClient;
|
|
2670
2988
|
exports.createMicrosoftGraphClient = createMicrosoftGraphClient;
|
|
2989
|
+
exports.createPemCertOption = createPemCertOption;
|
|
2990
|
+
exports.createPfxCertOption = createPfxCertOption;
|
|
2671
2991
|
exports.getLogLevel = getLogLevel;
|
|
2672
2992
|
exports.getTediousConnectionConfig = getTediousConnectionConfig;
|
|
2673
2993
|
exports.sendAdaptiveCard = sendAdaptiveCard;
|