@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.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,259 @@ 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
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1484
|
+
*
|
|
1485
|
+
* @beta
|
|
1486
|
+
*/
|
|
1487
|
+
constructor(userName, password) {
|
|
1488
|
+
if (!userName) {
|
|
1489
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "username"), ErrorCode.InvalidParameter);
|
|
1490
|
+
}
|
|
1491
|
+
if (!password) {
|
|
1492
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "password"), ErrorCode.InvalidParameter);
|
|
1493
|
+
}
|
|
1494
|
+
this.userName = userName;
|
|
1495
|
+
this.password = password;
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
* Adds authentication info to http requests
|
|
1499
|
+
*
|
|
1500
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1501
|
+
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1502
|
+
*
|
|
1503
|
+
* @returns Updated axios request config.
|
|
1504
|
+
*
|
|
1505
|
+
* @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header or auth property already exists in request configuration.
|
|
1506
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1507
|
+
*
|
|
1508
|
+
* @beta
|
|
1509
|
+
*/
|
|
1510
|
+
async AddAuthenticationInfo(config) {
|
|
1511
|
+
if (config.headers && config.headers["Authorization"]) {
|
|
1512
|
+
throw new ErrorWithCode(ErrorMessage.AuthorizationHeaderAlreadyExists, ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1513
|
+
}
|
|
1514
|
+
if (config.auth) {
|
|
1515
|
+
throw new ErrorWithCode(ErrorMessage.BasicCredentialAlreadyExists, ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1516
|
+
}
|
|
1517
|
+
config.auth = {
|
|
1518
|
+
username: this.userName,
|
|
1519
|
+
password: this.password,
|
|
1520
|
+
};
|
|
1521
|
+
return config;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
// Copyright (c) Microsoft Corporation.
|
|
1526
|
+
/**
|
|
1527
|
+
* Provider that handles API Key authentication
|
|
1528
|
+
*
|
|
1529
|
+
* @beta
|
|
1530
|
+
*/
|
|
1531
|
+
class ApiKeyProvider {
|
|
1532
|
+
/**
|
|
1533
|
+
*
|
|
1534
|
+
* @param { string } keyName - The name of request header or query parameter that specifies API Key
|
|
1535
|
+
* @param { string } keyValue - The value of API Key
|
|
1536
|
+
* @param { ApiKeyLocation } keyLocation - The location of API Key: request header or query parameter.
|
|
1537
|
+
*
|
|
1538
|
+
* @throws {@link ErrorCode|InvalidParameter} - when key name or key value is empty.
|
|
1539
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1540
|
+
*
|
|
1541
|
+
* @beta
|
|
1542
|
+
*/
|
|
1543
|
+
constructor(keyName, keyValue, keyLocation) {
|
|
1544
|
+
if (!keyName) {
|
|
1545
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "keyName"), ErrorCode.InvalidParameter);
|
|
1546
|
+
}
|
|
1547
|
+
if (!keyValue) {
|
|
1548
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "keyVaule"), ErrorCode.InvalidParameter);
|
|
1549
|
+
}
|
|
1550
|
+
this.keyName = keyName;
|
|
1551
|
+
this.keyValue = keyValue;
|
|
1552
|
+
this.keyLocation = keyLocation;
|
|
1553
|
+
}
|
|
1554
|
+
/**
|
|
1555
|
+
* Adds authentication info to http requests
|
|
1556
|
+
*
|
|
1557
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1558
|
+
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1559
|
+
*
|
|
1560
|
+
* @returns Updated axios request config.
|
|
1561
|
+
*
|
|
1562
|
+
* @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when API key already exists in request header or url query parameter.
|
|
1563
|
+
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
|
|
1564
|
+
*
|
|
1565
|
+
* @beta
|
|
1566
|
+
*/
|
|
1567
|
+
async AddAuthenticationInfo(config) {
|
|
1568
|
+
switch (this.keyLocation) {
|
|
1569
|
+
case ApiKeyLocation.Header:
|
|
1570
|
+
if (!config.headers) {
|
|
1571
|
+
config.headers = {};
|
|
1572
|
+
}
|
|
1573
|
+
if (config.headers[this.keyName]) {
|
|
1574
|
+
throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInHeader, this.keyName), ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1575
|
+
}
|
|
1576
|
+
config.headers[this.keyName] = this.keyValue;
|
|
1577
|
+
break;
|
|
1578
|
+
case ApiKeyLocation.QueryParams:
|
|
1579
|
+
if (!config.params) {
|
|
1580
|
+
config.params = {};
|
|
1581
|
+
}
|
|
1582
|
+
const url = new URL(config.url, config.baseURL);
|
|
1583
|
+
if (config.params[this.keyName] || url.searchParams.has(this.keyName)) {
|
|
1584
|
+
throw new ErrorWithCode(formatString(ErrorMessage.DuplicateApiKeyInQueryParam, this.keyName), ErrorCode.AuthorizationInfoAlreadyExists);
|
|
1585
|
+
}
|
|
1586
|
+
config.params[this.keyName] = this.keyValue;
|
|
1587
|
+
break;
|
|
1588
|
+
}
|
|
1589
|
+
return config;
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
/**
|
|
1593
|
+
* Define available location for API Key location
|
|
1594
|
+
*
|
|
1595
|
+
* @beta
|
|
1596
|
+
*/
|
|
1597
|
+
var ApiKeyLocation;
|
|
1598
|
+
(function (ApiKeyLocation) {
|
|
1599
|
+
/**
|
|
1600
|
+
* The API Key is placed in request header
|
|
1601
|
+
*/
|
|
1602
|
+
ApiKeyLocation[ApiKeyLocation["Header"] = 0] = "Header";
|
|
1603
|
+
/**
|
|
1604
|
+
* The API Key is placed in query parameter
|
|
1605
|
+
*/
|
|
1606
|
+
ApiKeyLocation[ApiKeyLocation["QueryParams"] = 1] = "QueryParams";
|
|
1607
|
+
})(ApiKeyLocation || (ApiKeyLocation = {}));
|
|
1608
|
+
|
|
1609
|
+
// Copyright (c) Microsoft Corporation.
|
|
1610
|
+
/**
|
|
1611
|
+
* Provider that handles Certificate authentication
|
|
1612
|
+
*
|
|
1613
|
+
* @beta
|
|
1614
|
+
*/
|
|
1615
|
+
class CertificateAuthProvider {
|
|
1616
|
+
/**
|
|
1617
|
+
*
|
|
1618
|
+
* @param { SecureContextOptions } certOption - information about the cert used in http requests
|
|
1619
|
+
*
|
|
1620
|
+
* @throws {@link ErrorCode|InvalidParameter} - when cert option is empty.
|
|
1621
|
+
*
|
|
1622
|
+
* @beta
|
|
1623
|
+
*/
|
|
1624
|
+
constructor(certOption) {
|
|
1625
|
+
if (certOption && Object.keys(certOption).length !== 0) {
|
|
1626
|
+
this.certOption = certOption;
|
|
1627
|
+
}
|
|
1628
|
+
else {
|
|
1629
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "certOption"), ErrorCode.InvalidParameter);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* Adds authentication info to http requests.
|
|
1634
|
+
*
|
|
1635
|
+
* @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
|
|
1636
|
+
* Refer https://axios-http.com/docs/req_config for detailed document.
|
|
1637
|
+
*
|
|
1638
|
+
* @returns Updated axios request config.
|
|
1639
|
+
*
|
|
1640
|
+
* @throws {@link ErrorCode|InvalidParameter} - when custom httpsAgent in the request has duplicate properties with certOption provided in constructor.
|
|
1641
|
+
*
|
|
1642
|
+
* @beta
|
|
1643
|
+
*/
|
|
1644
|
+
async AddAuthenticationInfo(config) {
|
|
1645
|
+
if (!config.httpsAgent) {
|
|
1646
|
+
config.httpsAgent = new Agent(this.certOption);
|
|
1647
|
+
}
|
|
1648
|
+
else {
|
|
1649
|
+
const existingProperties = new Set(Object.keys(config.httpsAgent.options));
|
|
1650
|
+
for (const property of Object.keys(this.certOption)) {
|
|
1651
|
+
if (existingProperties.has(property)) {
|
|
1652
|
+
throw new ErrorWithCode(formatString(ErrorMessage.DuplicateHttpsOptionProperty, property), ErrorCode.InvalidParameter);
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
Object.assign(config.httpsAgent.options, this.certOption);
|
|
1656
|
+
}
|
|
1657
|
+
return config;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
/**
|
|
1661
|
+
* Helper to create SecureContextOptions from PEM format cert
|
|
1662
|
+
*
|
|
1663
|
+
* @param { string | Buffer } cert - The cert chain in PEM format
|
|
1664
|
+
* @param { string | Buffer } key - The private key for the cert chain
|
|
1665
|
+
* @param { {passphrase?: string; ca?: string | Buffer} } options - Optional settings when create the cert options.
|
|
1666
|
+
*
|
|
1667
|
+
* @returns Instance of SecureContextOptions
|
|
1668
|
+
*
|
|
1669
|
+
* @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
|
|
1670
|
+
*
|
|
1671
|
+
*/
|
|
1672
|
+
function createPemCertOption(cert, key, options) {
|
|
1673
|
+
if (cert.length === 0) {
|
|
1674
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "cert"), ErrorCode.InvalidParameter);
|
|
1675
|
+
}
|
|
1676
|
+
if (key.length === 0) {
|
|
1677
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "key"), ErrorCode.InvalidParameter);
|
|
1678
|
+
}
|
|
1679
|
+
return {
|
|
1680
|
+
cert,
|
|
1681
|
+
key,
|
|
1682
|
+
passphrase: options === null || options === void 0 ? void 0 : options.passphrase,
|
|
1683
|
+
ca: options === null || options === void 0 ? void 0 : options.ca,
|
|
1684
|
+
};
|
|
1685
|
+
}
|
|
1686
|
+
/**
|
|
1687
|
+
* Helper to create SecureContextOptions from PFX format cert
|
|
1688
|
+
*
|
|
1689
|
+
* @param { string | Buffer } pfx - The content of .pfx file
|
|
1690
|
+
* @param { {passphrase?: string} } options - Optional settings when create the cert options.
|
|
1691
|
+
*
|
|
1692
|
+
* @returns Instance of SecureContextOptions
|
|
1693
|
+
*
|
|
1694
|
+
* @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
|
|
1695
|
+
*
|
|
1696
|
+
*/
|
|
1697
|
+
function createPfxCertOption(pfx, options) {
|
|
1698
|
+
if (pfx.length === 0) {
|
|
1699
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "pfx"), ErrorCode.InvalidParameter);
|
|
1700
|
+
}
|
|
1701
|
+
return {
|
|
1702
|
+
pfx,
|
|
1703
|
+
passphrase: options === null || options === void 0 ? void 0 : options.passphrase,
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
// Copyright (c) Microsoft Corporation.
|
|
1708
|
+
// Following keys are used by SDK internally
|
|
1709
|
+
const ReservedKey = new Set([
|
|
1710
|
+
"authorityHost",
|
|
1711
|
+
"tenantId",
|
|
1712
|
+
"clientId",
|
|
1713
|
+
"clientSecret",
|
|
1714
|
+
"initiateLoginEndpoint",
|
|
1715
|
+
"applicationIdUri",
|
|
1716
|
+
"apiEndpoint",
|
|
1717
|
+
"apiName",
|
|
1718
|
+
"sqlServerEndpoint",
|
|
1719
|
+
"sqlUsername",
|
|
1720
|
+
"sqlPassword",
|
|
1721
|
+
"sqlDatabaseName",
|
|
1722
|
+
"sqlIdentityId",
|
|
1723
|
+
]);
|
|
1455
1724
|
/**
|
|
1456
1725
|
* A class providing credential and configuration.
|
|
1457
1726
|
* @beta
|
|
@@ -1625,10 +1894,10 @@ class TeamsFx {
|
|
|
1625
1894
|
this.configuration.set("sqlDatabaseName", env.SQL_DATABASE_NAME);
|
|
1626
1895
|
this.configuration.set("sqlIdentityId", env.IDENTITY_ID);
|
|
1627
1896
|
Object.keys(env).forEach((key) => {
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
this.configuration.set(key.substring(8), value);
|
|
1897
|
+
if (ReservedKey.has(key)) {
|
|
1898
|
+
internalLogger.warn(`The name of environment variable ${key} is preserved. Will not load it as configuration.`);
|
|
1631
1899
|
}
|
|
1900
|
+
this.configuration.set(key, env[key]);
|
|
1632
1901
|
});
|
|
1633
1902
|
}
|
|
1634
1903
|
}
|
|
@@ -1662,13 +1931,6 @@ class NotificationMiddleware {
|
|
|
1662
1931
|
await this.conversationReferenceStore.set(reference);
|
|
1663
1932
|
break;
|
|
1664
1933
|
}
|
|
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
1934
|
case ActivityType.CurrentBotUninstalled:
|
|
1673
1935
|
case ActivityType.TeamDeleted: {
|
|
1674
1936
|
const reference = TurnContext.getConversationReference(context.activity);
|
|
@@ -1690,9 +1952,6 @@ class NotificationMiddleware {
|
|
|
1690
1952
|
return ActivityType.CurrentBotUninstalled;
|
|
1691
1953
|
}
|
|
1692
1954
|
}
|
|
1693
|
-
else if (activityType === "message") {
|
|
1694
|
-
return ActivityType.CurrentBotMessaged;
|
|
1695
|
-
}
|
|
1696
1955
|
else if (activityType === "conversationUpdate") {
|
|
1697
1956
|
const eventType = (_b = activity.channelData) === null || _b === void 0 ? void 0 : _b.eventType;
|
|
1698
1957
|
if (eventType === "teamDeleted") {
|
|
@@ -2260,7 +2519,7 @@ class TeamsBotInstallation {
|
|
|
2260
2519
|
}
|
|
2261
2520
|
}
|
|
2262
2521
|
/**
|
|
2263
|
-
* Provide utilities to send notification to varies targets (e.g., member,
|
|
2522
|
+
* Provide utilities to send notification to varies targets (e.g., member, group, channel).
|
|
2264
2523
|
*
|
|
2265
2524
|
* @beta
|
|
2266
2525
|
*/
|
|
@@ -2329,7 +2588,7 @@ class NotificationBot {
|
|
|
2329
2588
|
/**
|
|
2330
2589
|
* Provide utilities for bot conversation, including:
|
|
2331
2590
|
* - handle command and response.
|
|
2332
|
-
* - send notification to varies targets (e.g., member,
|
|
2591
|
+
* - send notification to varies targets (e.g., member, group, channel).
|
|
2333
2592
|
*
|
|
2334
2593
|
* @example
|
|
2335
2594
|
* 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 +2598,7 @@ class NotificationBot {
|
|
|
2339
2598
|
* const conversationBot = new ConversationBot({
|
|
2340
2599
|
* command: {
|
|
2341
2600
|
* enabled: true,
|
|
2342
|
-
*
|
|
2343
|
-
* commands: [ new HelloWorldCommandHandler() ],
|
|
2344
|
-
* },
|
|
2601
|
+
* commands: [ new HelloWorldCommandHandler() ],
|
|
2345
2602
|
* },
|
|
2346
2603
|
* });
|
|
2347
2604
|
*
|
|
@@ -2349,7 +2606,7 @@ class NotificationBot {
|
|
|
2349
2606
|
* conversationBot.command.registerCommand(new HelpCommandHandler());
|
|
2350
2607
|
* ```
|
|
2351
2608
|
*
|
|
2352
|
-
* For notification, you can enable notification at initialization, then send
|
|
2609
|
+
* For notification, you can enable notification at initialization, then send notifications at any time.
|
|
2353
2610
|
*
|
|
2354
2611
|
* ```typescript
|
|
2355
2612
|
* // enable through constructor
|
|
@@ -2377,7 +2634,7 @@ class NotificationBot {
|
|
|
2377
2634
|
*
|
|
2378
2635
|
* 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
2636
|
*
|
|
2380
|
-
* For notification, set `notification.
|
|
2637
|
+
* For notification, set `notification.storage` in {@link ConversationOptions} to use your own storage implementation.
|
|
2381
2638
|
*
|
|
2382
2639
|
* @beta
|
|
2383
2640
|
*/
|
|
@@ -2385,26 +2642,76 @@ class ConversationBot {
|
|
|
2385
2642
|
/**
|
|
2386
2643
|
* Creates new instance of the `ConversationBot`.
|
|
2387
2644
|
*
|
|
2645
|
+
* @remarks
|
|
2646
|
+
* It's recommended to create your own adapter and storage for production environment instead of the default one.
|
|
2647
|
+
*
|
|
2388
2648
|
* @param options - initialize options
|
|
2389
2649
|
*
|
|
2390
2650
|
* @beta
|
|
2391
2651
|
*/
|
|
2392
2652
|
constructor(options) {
|
|
2653
|
+
var _a, _b;
|
|
2393
2654
|
if (options.adapter) {
|
|
2394
2655
|
this.adapter = options.adapter;
|
|
2395
2656
|
}
|
|
2396
2657
|
else {
|
|
2397
|
-
this.adapter =
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2658
|
+
this.adapter = this.createDefaultAdapter(options.adapterConfig);
|
|
2659
|
+
}
|
|
2660
|
+
if ((_a = options.command) === null || _a === void 0 ? void 0 : _a.enabled) {
|
|
2661
|
+
this.command = new CommandBot(this.adapter, options.command);
|
|
2401
2662
|
}
|
|
2402
|
-
if (options.
|
|
2403
|
-
this.
|
|
2663
|
+
if ((_b = options.notification) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
2664
|
+
this.notification = new NotificationBot(this.adapter, options.notification);
|
|
2404
2665
|
}
|
|
2405
|
-
|
|
2406
|
-
|
|
2666
|
+
}
|
|
2667
|
+
createDefaultAdapter(adapterConfig) {
|
|
2668
|
+
const adapter = adapterConfig === undefined
|
|
2669
|
+
? new BotFrameworkAdapter({
|
|
2670
|
+
appId: process.env.BOT_ID,
|
|
2671
|
+
appPassword: process.env.BOT_PASSWORD,
|
|
2672
|
+
})
|
|
2673
|
+
: new BotFrameworkAdapter(adapterConfig);
|
|
2674
|
+
// the default error handler
|
|
2675
|
+
adapter.onTurnError = async (context, error) => {
|
|
2676
|
+
// This check writes out errors to console.
|
|
2677
|
+
console.error(`[onTurnError] unhandled error: ${error}`);
|
|
2678
|
+
// Send a trace activity, which will be displayed in Bot Framework Emulator
|
|
2679
|
+
await context.sendTraceActivity("OnTurnError Trace", `${error}`, "https://www.botframework.com/schemas/error", "TurnError");
|
|
2680
|
+
// Send a message to the user
|
|
2681
|
+
await context.sendActivity(`The bot encountered unhandled error: ${error.message}`);
|
|
2682
|
+
await context.sendActivity("To continue to run this bot, please fix the bot source code.");
|
|
2683
|
+
};
|
|
2684
|
+
return adapter;
|
|
2685
|
+
}
|
|
2686
|
+
/**
|
|
2687
|
+
* The request handler to integrate with web request.
|
|
2688
|
+
*
|
|
2689
|
+
* @param req - an Express or Restify style request object.
|
|
2690
|
+
* @param res - an Express or Restify style response object.
|
|
2691
|
+
* @param logic - the additional function to handle bot context.
|
|
2692
|
+
*
|
|
2693
|
+
* @example
|
|
2694
|
+
* For example, to use with Restify:
|
|
2695
|
+
* ``` typescript
|
|
2696
|
+
* // The default/empty behavior
|
|
2697
|
+
* server.post("api/messages", conversationBot.requestHandler);
|
|
2698
|
+
*
|
|
2699
|
+
* // Or, add your own logic
|
|
2700
|
+
* server.post("api/messages", async (req, res) => {
|
|
2701
|
+
* await conversationBot.requestHandler(req, res, async (context) => {
|
|
2702
|
+
* // your-own-context-logic
|
|
2703
|
+
* });
|
|
2704
|
+
* });
|
|
2705
|
+
* ```
|
|
2706
|
+
*
|
|
2707
|
+
* @beta
|
|
2708
|
+
*/
|
|
2709
|
+
async requestHandler(req, res, logic) {
|
|
2710
|
+
if (logic === undefined) {
|
|
2711
|
+
// create empty logic
|
|
2712
|
+
logic = async () => { };
|
|
2407
2713
|
}
|
|
2714
|
+
await this.adapter.processActivity(req, res, logic);
|
|
2408
2715
|
}
|
|
2409
2716
|
}
|
|
2410
2717
|
|
|
@@ -2417,8 +2724,8 @@ class MessageBuilder {
|
|
|
2417
2724
|
/**
|
|
2418
2725
|
* Build a bot message activity attached with adaptive card.
|
|
2419
2726
|
*
|
|
2420
|
-
* @param getCardData Function to prepare your card data.
|
|
2421
2727
|
* @param cardTemplate The adaptive card template.
|
|
2728
|
+
* @param data card data used to render the template.
|
|
2422
2729
|
* @returns A bot message activity attached with an adaptive card.
|
|
2423
2730
|
*
|
|
2424
2731
|
* @example
|
|
@@ -2443,19 +2750,18 @@ class MessageBuilder {
|
|
|
2443
2750
|
* title: string,
|
|
2444
2751
|
* description: string
|
|
2445
2752
|
* };
|
|
2446
|
-
* const card = MessageBuilder.attachAdaptiveCard<CardData>(
|
|
2447
|
-
*
|
|
2448
|
-
*
|
|
2449
|
-
*
|
|
2450
|
-
*
|
|
2753
|
+
* const card = MessageBuilder.attachAdaptiveCard<CardData>(
|
|
2754
|
+
* cardTemplate, {
|
|
2755
|
+
* title: "sample card title",
|
|
2756
|
+
* description: "sample card description"
|
|
2757
|
+
* });
|
|
2451
2758
|
* ```
|
|
2452
2759
|
*
|
|
2453
2760
|
* @beta
|
|
2454
2761
|
*/
|
|
2455
|
-
static attachAdaptiveCard(
|
|
2456
|
-
const cardData = getCardData();
|
|
2762
|
+
static attachAdaptiveCard(cardTemplate, data) {
|
|
2457
2763
|
return {
|
|
2458
|
-
attachments: [CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(
|
|
2764
|
+
attachments: [CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(data))],
|
|
2459
2765
|
};
|
|
2460
2766
|
}
|
|
2461
2767
|
/**
|
|
@@ -2562,5 +2868,5 @@ class MessageBuilder {
|
|
|
2562
2868
|
}
|
|
2563
2869
|
}
|
|
2564
2870
|
|
|
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 };
|
|
2871
|
+
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
2872
|
//# sourceMappingURL=index.esm2017.mjs.map
|