@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.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,262 @@ 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
|
+
*
|
|
1540
|
+
* @beta
|
|
1541
|
+
*/
|
|
1542
|
+
constructor(userName, password) {
|
|
1543
|
+
if (!userName) {
|
|
1544
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "username"), exports.ErrorCode.InvalidParameter);
|
|
1545
|
+
}
|
|
1546
|
+
if (!password) {
|
|
1547
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "password"), exports.ErrorCode.InvalidParameter);
|
|
1548
|
+
}
|
|
1549
|
+
this.userName = userName;
|
|
1550
|
+
this.password = password;
|
|
1551
|
+
}
|
|
1552
|
+
/**
|
|
1553
|
+
* Adds authentication info to http requests
|
|
1554
|
+
*
|
|
1555
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1556
|
+
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1557
|
+
*
|
|
1558
|
+
* @returns Updated axios request config.
|
|
1559
|
+
*
|
|
1560
|
+
* @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header or auth property already exists in request configuration.
|
|
1561
|
+
*
|
|
1562
|
+
* @beta
|
|
1563
|
+
*/
|
|
1564
|
+
AddAuthenticationInfo(config) {
|
|
1565
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1566
|
+
if (config.headers && config.headers["Authorization"]) {
|
|
1567
|
+
throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1568
|
+
}
|
|
1569
|
+
if (config.auth) {
|
|
1570
|
+
throw new ErrorWithCode(ErrorMessage.BasicCredentialAlreadyExists, exports.ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1571
|
+
}
|
|
1572
|
+
config.auth = {
|
|
1573
|
+
username: this.userName,
|
|
1574
|
+
password: this.password,
|
|
1575
|
+
};
|
|
1576
|
+
return config;
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
// Copyright (c) Microsoft Corporation.
|
|
1582
|
+
/**
|
|
1583
|
+
* Provider that handles API Key authentication
|
|
1584
|
+
*
|
|
1585
|
+
* @beta
|
|
1586
|
+
*/
|
|
1587
|
+
class ApiKeyProvider {
|
|
1588
|
+
/**
|
|
1589
|
+
*
|
|
1590
|
+
* @param { string } keyName - The name of request header or query parameter that specifies API Key
|
|
1591
|
+
* @param { string } keyValue - The value of API Key
|
|
1592
|
+
* @param { ApiKeyLocation } keyLocation - The location of API Key: request header or query parameter.
|
|
1593
|
+
*
|
|
1594
|
+
* @throws {@link ErrorCode|InvalidParameter} - when key name or key value is empty.
|
|
1595
|
+
*
|
|
1596
|
+
* @beta
|
|
1597
|
+
*/
|
|
1598
|
+
constructor(keyName, keyValue, keyLocation) {
|
|
1599
|
+
if (!keyName) {
|
|
1600
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "keyName"), exports.ErrorCode.InvalidParameter);
|
|
1601
|
+
}
|
|
1602
|
+
if (!keyValue) {
|
|
1603
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "keyVaule"), exports.ErrorCode.InvalidParameter);
|
|
1604
|
+
}
|
|
1605
|
+
this.keyName = keyName;
|
|
1606
|
+
this.keyValue = keyValue;
|
|
1607
|
+
this.keyLocation = keyLocation;
|
|
1608
|
+
}
|
|
1609
|
+
/**
|
|
1610
|
+
* Adds authentication info to http requests
|
|
1611
|
+
*
|
|
1612
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1613
|
+
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1614
|
+
*
|
|
1615
|
+
* @returns Updated axios request config.
|
|
1616
|
+
*
|
|
1617
|
+
* @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when API key already exists in request header or url query parameter.
|
|
1618
|
+
*
|
|
1619
|
+
* @beta
|
|
1620
|
+
*/
|
|
1621
|
+
AddAuthenticationInfo(config) {
|
|
1622
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1623
|
+
switch (this.keyLocation) {
|
|
1624
|
+
case exports.ApiKeyLocation.Header:
|
|
1625
|
+
if (!config.headers) {
|
|
1626
|
+
config.headers = {};
|
|
1627
|
+
}
|
|
1628
|
+
if (config.headers[this.keyName]) {
|
|
1629
|
+
throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInHeader, this.keyName), exports.ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1630
|
+
}
|
|
1631
|
+
config.headers[this.keyName] = this.keyValue;
|
|
1632
|
+
break;
|
|
1633
|
+
case exports.ApiKeyLocation.QueryParams:
|
|
1634
|
+
if (!config.params) {
|
|
1635
|
+
config.params = {};
|
|
1636
|
+
}
|
|
1637
|
+
const url = new URL(config.url, config.baseURL);
|
|
1638
|
+
if (config.params[this.keyName] || url.searchParams.has(this.keyName)) {
|
|
1639
|
+
throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInQueryParam, this.keyName), exports.ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1640
|
+
}
|
|
1641
|
+
config.params[this.keyName] = this.keyValue;
|
|
1642
|
+
break;
|
|
1643
|
+
}
|
|
1644
|
+
return config;
|
|
1645
|
+
});
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
/**
|
|
1649
|
+
* Define available location for API Key location
|
|
1650
|
+
*
|
|
1651
|
+
* @beta
|
|
1652
|
+
*/
|
|
1653
|
+
exports.ApiKeyLocation = void 0;
|
|
1654
|
+
(function (ApiKeyLocation) {
|
|
1655
|
+
/**
|
|
1656
|
+
* The API Key is placed in request header
|
|
1657
|
+
*/
|
|
1658
|
+
ApiKeyLocation[ApiKeyLocation["Header"] = 0] = "Header";
|
|
1659
|
+
/**
|
|
1660
|
+
* The API Key is placed in query parameter
|
|
1661
|
+
*/
|
|
1662
|
+
ApiKeyLocation[ApiKeyLocation["QueryParams"] = 1] = "QueryParams";
|
|
1663
|
+
})(exports.ApiKeyLocation || (exports.ApiKeyLocation = {}));
|
|
1664
|
+
|
|
1665
|
+
// Copyright (c) Microsoft Corporation.
|
|
1666
|
+
/**
|
|
1667
|
+
* Provider that handles Certificate authentication
|
|
1668
|
+
*
|
|
1669
|
+
* @beta
|
|
1670
|
+
*/
|
|
1671
|
+
class CertificateAuthProvider {
|
|
1672
|
+
/**
|
|
1673
|
+
*
|
|
1674
|
+
* @param { SecureContextOptions } certOption - information about the cert used in http requests
|
|
1675
|
+
*
|
|
1676
|
+
* @throws {@link ErrorCode|InvalidParameter} - when cert option is empty.
|
|
1677
|
+
*
|
|
1678
|
+
* @beta
|
|
1679
|
+
*/
|
|
1680
|
+
constructor(certOption) {
|
|
1681
|
+
if (certOption && Object.keys(certOption).length !== 0) {
|
|
1682
|
+
this.certOption = certOption;
|
|
1683
|
+
}
|
|
1684
|
+
else {
|
|
1685
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "certOption"), exports.ErrorCode.InvalidParameter);
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
/**
|
|
1689
|
+
* Adds authentication info to http requests.
|
|
1690
|
+
*
|
|
1691
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1692
|
+
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1693
|
+
*
|
|
1694
|
+
* @returns Updated axios request config.
|
|
1695
|
+
*
|
|
1696
|
+
* @throws {@link ErrorCode|InvalidParameter} - when custom httpsAgent in the request has duplicate properties with certOption provided in constructor.
|
|
1697
|
+
*
|
|
1698
|
+
* @beta
|
|
1699
|
+
*/
|
|
1700
|
+
AddAuthenticationInfo(config) {
|
|
1701
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1702
|
+
if (!config.httpsAgent) {
|
|
1703
|
+
config.httpsAgent = new https.Agent(this.certOption);
|
|
1704
|
+
}
|
|
1705
|
+
else {
|
|
1706
|
+
const existingProperties = new Set(Object.keys(config.httpsAgent.options));
|
|
1707
|
+
for (const property of Object.keys(this.certOption)) {
|
|
1708
|
+
if (existingProperties.has(property)) {
|
|
1709
|
+
throw new ErrorWithCode(formatString(ErrorMessage.DuplicateHttpsOptionProperty, property), exports.ErrorCode.InvalidParameter);
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
Object.assign(config.httpsAgent.options, this.certOption);
|
|
1713
|
+
}
|
|
1714
|
+
return config;
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
/**
|
|
1719
|
+
* Helper to create SecureContextOptions from PEM format cert
|
|
1720
|
+
*
|
|
1721
|
+
* @param { string | Buffer } cert - The cert chain in PEM format
|
|
1722
|
+
* @param { string | Buffer } key - The private key for the cert chain
|
|
1723
|
+
* @param { string? } passphrase - The passphrase for private key
|
|
1724
|
+
* @param { string? | Buffer? } ca - Overrides the trusted CA certificates
|
|
1725
|
+
*
|
|
1726
|
+
* @returns Instance of SecureContextOptions
|
|
1727
|
+
*
|
|
1728
|
+
* @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
|
|
1729
|
+
*
|
|
1730
|
+
*/
|
|
1731
|
+
function createPemCertOption(cert, key, passphrase, ca) {
|
|
1732
|
+
if (cert.length === 0) {
|
|
1733
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "cert"), exports.ErrorCode.InvalidParameter);
|
|
1734
|
+
}
|
|
1735
|
+
if (key.length === 0) {
|
|
1736
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "key"), exports.ErrorCode.InvalidParameter);
|
|
1737
|
+
}
|
|
1738
|
+
return {
|
|
1739
|
+
cert,
|
|
1740
|
+
key,
|
|
1741
|
+
passphrase,
|
|
1742
|
+
ca,
|
|
1743
|
+
};
|
|
1744
|
+
}
|
|
1745
|
+
/**
|
|
1746
|
+
* Helper to create SecureContextOptions from PFX format cert
|
|
1747
|
+
*
|
|
1748
|
+
* @param { string | Buffer } pfx - The content of .pfx file
|
|
1749
|
+
* @param { string? } passphrase - Optional. The passphrase of .pfx file
|
|
1750
|
+
*
|
|
1751
|
+
* @returns Instance of SecureContextOptions
|
|
1752
|
+
*
|
|
1753
|
+
* @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
|
|
1754
|
+
*
|
|
1755
|
+
*/
|
|
1756
|
+
function createPfxCertOption(pfx, passphrase) {
|
|
1757
|
+
if (pfx.length === 0) {
|
|
1758
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "pfx"), exports.ErrorCode.InvalidParameter);
|
|
1759
|
+
}
|
|
1760
|
+
return {
|
|
1761
|
+
pfx,
|
|
1762
|
+
passphrase,
|
|
1763
|
+
};
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
// Copyright (c) Microsoft Corporation.
|
|
1767
|
+
// Following keys are used by SDK internally
|
|
1768
|
+
const ReservedKey = new Set([
|
|
1769
|
+
"authorityHost",
|
|
1770
|
+
"tenantId",
|
|
1771
|
+
"clientId",
|
|
1772
|
+
"clientSecret",
|
|
1773
|
+
"initiateLoginEndpoint",
|
|
1774
|
+
"applicationIdUri",
|
|
1775
|
+
"apiEndpoint",
|
|
1776
|
+
"apiName",
|
|
1777
|
+
"sqlServerEndpoint",
|
|
1778
|
+
"sqlUsername",
|
|
1779
|
+
"sqlPassword",
|
|
1780
|
+
"sqlDatabaseName",
|
|
1781
|
+
"sqlIdentityId",
|
|
1782
|
+
]);
|
|
1510
1783
|
/**
|
|
1511
1784
|
* A class providing credential and configuration.
|
|
1512
1785
|
* @beta
|
|
@@ -1684,10 +1957,10 @@ class TeamsFx {
|
|
|
1684
1957
|
this.configuration.set("sqlDatabaseName", env.SQL_DATABASE_NAME);
|
|
1685
1958
|
this.configuration.set("sqlIdentityId", env.IDENTITY_ID);
|
|
1686
1959
|
Object.keys(env).forEach((key) => {
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
this.configuration.set(key.substring(8), value);
|
|
1960
|
+
if (ReservedKey.has(key)) {
|
|
1961
|
+
internalLogger.warn(`The name of environment variable ${key} is preserved. Will not load it as configuration.`);
|
|
1690
1962
|
}
|
|
1963
|
+
this.configuration.set(key, env[key]);
|
|
1691
1964
|
});
|
|
1692
1965
|
}
|
|
1693
1966
|
}
|
|
@@ -1722,13 +1995,6 @@ class NotificationMiddleware {
|
|
|
1722
1995
|
yield this.conversationReferenceStore.set(reference);
|
|
1723
1996
|
break;
|
|
1724
1997
|
}
|
|
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
1998
|
case ActivityType.CurrentBotUninstalled:
|
|
1733
1999
|
case ActivityType.TeamDeleted: {
|
|
1734
2000
|
const reference = botbuilder.TurnContext.getConversationReference(context.activity);
|
|
@@ -1751,9 +2017,6 @@ class NotificationMiddleware {
|
|
|
1751
2017
|
return ActivityType.CurrentBotUninstalled;
|
|
1752
2018
|
}
|
|
1753
2019
|
}
|
|
1754
|
-
else if (activityType === "message") {
|
|
1755
|
-
return ActivityType.CurrentBotMessaged;
|
|
1756
|
-
}
|
|
1757
2020
|
else if (activityType === "conversationUpdate") {
|
|
1758
2021
|
const eventType = (_b = activity.channelData) === null || _b === void 0 ? void 0 : _b.eventType;
|
|
1759
2022
|
if (eventType === "teamDeleted") {
|
|
@@ -2347,7 +2610,7 @@ class TeamsBotInstallation {
|
|
|
2347
2610
|
}
|
|
2348
2611
|
}
|
|
2349
2612
|
/**
|
|
2350
|
-
* Provide utilities to send notification to varies targets (e.g., member,
|
|
2613
|
+
* Provide utilities to send notification to varies targets (e.g., member, group, channel).
|
|
2351
2614
|
*
|
|
2352
2615
|
* @beta
|
|
2353
2616
|
*/
|
|
@@ -2418,7 +2681,7 @@ class NotificationBot {
|
|
|
2418
2681
|
/**
|
|
2419
2682
|
* Provide utilities for bot conversation, including:
|
|
2420
2683
|
* - handle command and response.
|
|
2421
|
-
* - send notification to varies targets (e.g., member,
|
|
2684
|
+
* - send notification to varies targets (e.g., member, group, channel).
|
|
2422
2685
|
*
|
|
2423
2686
|
* @example
|
|
2424
2687
|
* 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 +2691,7 @@ class NotificationBot {
|
|
|
2428
2691
|
* const conversationBot = new ConversationBot({
|
|
2429
2692
|
* command: {
|
|
2430
2693
|
* enabled: true,
|
|
2431
|
-
*
|
|
2432
|
-
* commands: [ new HelloWorldCommandHandler() ],
|
|
2433
|
-
* },
|
|
2694
|
+
* commands: [ new HelloWorldCommandHandler() ],
|
|
2434
2695
|
* },
|
|
2435
2696
|
* });
|
|
2436
2697
|
*
|
|
@@ -2438,7 +2699,7 @@ class NotificationBot {
|
|
|
2438
2699
|
* conversationBot.command.registerCommand(new HelpCommandHandler());
|
|
2439
2700
|
* ```
|
|
2440
2701
|
*
|
|
2441
|
-
* For notification, you can enable notification at initialization, then send
|
|
2702
|
+
* For notification, you can enable notification at initialization, then send notifications at any time.
|
|
2442
2703
|
*
|
|
2443
2704
|
* ```typescript
|
|
2444
2705
|
* // enable through constructor
|
|
@@ -2466,7 +2727,7 @@ class NotificationBot {
|
|
|
2466
2727
|
*
|
|
2467
2728
|
* 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
2729
|
*
|
|
2469
|
-
* For notification, set `notification.
|
|
2730
|
+
* For notification, set `notification.storage` in {@link ConversationOptions} to use your own storage implementation.
|
|
2470
2731
|
*
|
|
2471
2732
|
* @beta
|
|
2472
2733
|
*/
|
|
@@ -2474,27 +2735,79 @@ class ConversationBot {
|
|
|
2474
2735
|
/**
|
|
2475
2736
|
* Creates new instance of the `ConversationBot`.
|
|
2476
2737
|
*
|
|
2738
|
+
* @remarks
|
|
2739
|
+
* It's recommended to create your own adapter and storage for production environment instead of the default one.
|
|
2740
|
+
*
|
|
2477
2741
|
* @param options - initialize options
|
|
2478
2742
|
*
|
|
2479
2743
|
* @beta
|
|
2480
2744
|
*/
|
|
2481
2745
|
constructor(options) {
|
|
2746
|
+
var _a, _b;
|
|
2482
2747
|
if (options.adapter) {
|
|
2483
2748
|
this.adapter = options.adapter;
|
|
2484
2749
|
}
|
|
2485
2750
|
else {
|
|
2486
|
-
this.adapter =
|
|
2487
|
-
appId: process.env.BOT_ID,
|
|
2488
|
-
appPassword: process.env.BOT_PASSWORD,
|
|
2489
|
-
});
|
|
2751
|
+
this.adapter = this.createDefaultAdapter(options.adapterConfig);
|
|
2490
2752
|
}
|
|
2491
|
-
if (options.command.enabled) {
|
|
2492
|
-
this.command = new CommandBot(this.adapter, options.command
|
|
2753
|
+
if ((_a = options.command) === null || _a === void 0 ? void 0 : _a.enabled) {
|
|
2754
|
+
this.command = new CommandBot(this.adapter, options.command);
|
|
2493
2755
|
}
|
|
2494
|
-
if (options.notification.enabled) {
|
|
2495
|
-
this.notification = new NotificationBot(this.adapter, options.notification
|
|
2756
|
+
if ((_b = options.notification) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
2757
|
+
this.notification = new NotificationBot(this.adapter, options.notification);
|
|
2496
2758
|
}
|
|
2497
2759
|
}
|
|
2760
|
+
createDefaultAdapter(adapterConfig) {
|
|
2761
|
+
const adapter = adapterConfig === undefined
|
|
2762
|
+
? new botbuilder.BotFrameworkAdapter({
|
|
2763
|
+
appId: process.env.BOT_ID,
|
|
2764
|
+
appPassword: process.env.BOT_PASSWORD,
|
|
2765
|
+
})
|
|
2766
|
+
: new botbuilder.BotFrameworkAdapter(adapterConfig);
|
|
2767
|
+
// the default error handler
|
|
2768
|
+
adapter.onTurnError = (context, error) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
2769
|
+
// This check writes out errors to console.
|
|
2770
|
+
console.error(`[onTurnError] unhandled error: ${error}`);
|
|
2771
|
+
// Send a trace activity, which will be displayed in Bot Framework Emulator
|
|
2772
|
+
yield context.sendTraceActivity("OnTurnError Trace", `${error}`, "https://www.botframework.com/schemas/error", "TurnError");
|
|
2773
|
+
// Send a message to the user
|
|
2774
|
+
yield context.sendActivity(`The bot encountered unhandled error: ${error.message}`);
|
|
2775
|
+
yield context.sendActivity("To continue to run this bot, please fix the bot source code.");
|
|
2776
|
+
});
|
|
2777
|
+
return adapter;
|
|
2778
|
+
}
|
|
2779
|
+
/**
|
|
2780
|
+
* The request handler to integrate with web request.
|
|
2781
|
+
*
|
|
2782
|
+
* @param req - an Express or Restify style request object.
|
|
2783
|
+
* @param res - an Express or Restify style response object.
|
|
2784
|
+
* @param logic - the additional function to handle bot context.
|
|
2785
|
+
*
|
|
2786
|
+
* @example
|
|
2787
|
+
* For example, to use with Restify:
|
|
2788
|
+
* ``` typescript
|
|
2789
|
+
* // The default/empty behavior
|
|
2790
|
+
* server.post("api/messages", conversationBot.requestHandler);
|
|
2791
|
+
*
|
|
2792
|
+
* // Or, add your own logic
|
|
2793
|
+
* server.post("api/messages", async (req, res) => {
|
|
2794
|
+
* await conversationBot.requestHandler(req, res, async (context) => {
|
|
2795
|
+
* // your-own-context-logic
|
|
2796
|
+
* });
|
|
2797
|
+
* });
|
|
2798
|
+
* ```
|
|
2799
|
+
*
|
|
2800
|
+
* @beta
|
|
2801
|
+
*/
|
|
2802
|
+
requestHandler(req, res, logic) {
|
|
2803
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
2804
|
+
if (logic === undefined) {
|
|
2805
|
+
// create empty logic
|
|
2806
|
+
logic = () => tslib.__awaiter(this, void 0, void 0, function* () { });
|
|
2807
|
+
}
|
|
2808
|
+
yield this.adapter.processActivity(req, res, logic);
|
|
2809
|
+
});
|
|
2810
|
+
}
|
|
2498
2811
|
}
|
|
2499
2812
|
|
|
2500
2813
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -2506,8 +2819,8 @@ class MessageBuilder {
|
|
|
2506
2819
|
/**
|
|
2507
2820
|
* Build a bot message activity attached with adaptive card.
|
|
2508
2821
|
*
|
|
2509
|
-
* @param getCardData Function to prepare your card data.
|
|
2510
2822
|
* @param cardTemplate The adaptive card template.
|
|
2823
|
+
* @param data card data used to render the template.
|
|
2511
2824
|
* @returns A bot message activity attached with an adaptive card.
|
|
2512
2825
|
*
|
|
2513
2826
|
* @example
|
|
@@ -2532,19 +2845,18 @@ class MessageBuilder {
|
|
|
2532
2845
|
* title: string,
|
|
2533
2846
|
* description: string
|
|
2534
2847
|
* };
|
|
2535
|
-
* const card = MessageBuilder.attachAdaptiveCard<CardData>(
|
|
2536
|
-
*
|
|
2537
|
-
*
|
|
2538
|
-
*
|
|
2539
|
-
*
|
|
2848
|
+
* const card = MessageBuilder.attachAdaptiveCard<CardData>(
|
|
2849
|
+
* cardTemplate, {
|
|
2850
|
+
* title: "sample card title",
|
|
2851
|
+
* description: "sample card description"
|
|
2852
|
+
* });
|
|
2540
2853
|
* ```
|
|
2541
2854
|
*
|
|
2542
2855
|
* @beta
|
|
2543
2856
|
*/
|
|
2544
|
-
static attachAdaptiveCard(
|
|
2545
|
-
const cardData = getCardData();
|
|
2857
|
+
static attachAdaptiveCard(cardTemplate, data) {
|
|
2546
2858
|
return {
|
|
2547
|
-
attachments: [botbuilder.CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(
|
|
2859
|
+
attachments: [botbuilder.CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(data))],
|
|
2548
2860
|
};
|
|
2549
2861
|
}
|
|
2550
2862
|
/**
|
|
@@ -2651,8 +2963,11 @@ class MessageBuilder {
|
|
|
2651
2963
|
}
|
|
2652
2964
|
}
|
|
2653
2965
|
|
|
2966
|
+
exports.ApiKeyProvider = ApiKeyProvider;
|
|
2654
2967
|
exports.AppCredential = AppCredential;
|
|
2968
|
+
exports.BasicAuthProvider = BasicAuthProvider;
|
|
2655
2969
|
exports.BearerTokenAuthProvider = BearerTokenAuthProvider;
|
|
2970
|
+
exports.CertificateAuthProvider = CertificateAuthProvider;
|
|
2656
2971
|
exports.Channel = Channel;
|
|
2657
2972
|
exports.CommandBot = CommandBot;
|
|
2658
2973
|
exports.ConversationBot = ConversationBot;
|
|
@@ -2668,6 +2983,8 @@ exports.TeamsFx = TeamsFx;
|
|
|
2668
2983
|
exports.TeamsUserCredential = TeamsUserCredential;
|
|
2669
2984
|
exports.createApiClient = createApiClient;
|
|
2670
2985
|
exports.createMicrosoftGraphClient = createMicrosoftGraphClient;
|
|
2986
|
+
exports.createPemCertOption = createPemCertOption;
|
|
2987
|
+
exports.createPfxCertOption = createPfxCertOption;
|
|
2671
2988
|
exports.getLogLevel = getLogLevel;
|
|
2672
2989
|
exports.getTediousConnectionConfig = getTediousConnectionConfig;
|
|
2673
2990
|
exports.sendAdaptiveCard = sendAdaptiveCard;
|