@microsoft/teamsfx 0.6.3-alpha.8d048e1f1.0 → 0.6.3-alpha.b31d198d3.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 +195 -6
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +349 -42
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +203 -5
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +361 -40
- package/dist/index.node.cjs.js.map +1 -1
- package/package.json +3 -3
- package/types/teamsfx.d.ts +1432 -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,260 @@ 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 { string? } passphrase - The passphrase for private key
|
|
1666
|
+
* @param { string? | Buffer? } ca - Overrides the trusted CA certificates
|
|
1667
|
+
*
|
|
1668
|
+
* @returns Instance of SecureContextOptions
|
|
1669
|
+
*
|
|
1670
|
+
* @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
|
|
1671
|
+
*
|
|
1672
|
+
*/
|
|
1673
|
+
function createPemCertOption(cert, key, passphrase, ca) {
|
|
1674
|
+
if (cert.length === 0) {
|
|
1675
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "cert"), ErrorCode.InvalidParameter);
|
|
1676
|
+
}
|
|
1677
|
+
if (key.length === 0) {
|
|
1678
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "key"), ErrorCode.InvalidParameter);
|
|
1679
|
+
}
|
|
1680
|
+
return {
|
|
1681
|
+
cert,
|
|
1682
|
+
key,
|
|
1683
|
+
passphrase,
|
|
1684
|
+
ca,
|
|
1685
|
+
};
|
|
1686
|
+
}
|
|
1687
|
+
/**
|
|
1688
|
+
* Helper to create SecureContextOptions from PFX format cert
|
|
1689
|
+
*
|
|
1690
|
+
* @param { string | Buffer } pfx - The content of .pfx file
|
|
1691
|
+
* @param { string? } passphrase - Optional. The passphrase of .pfx file
|
|
1692
|
+
*
|
|
1693
|
+
* @returns Instance of SecureContextOptions
|
|
1694
|
+
*
|
|
1695
|
+
* @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
|
|
1696
|
+
*
|
|
1697
|
+
*/
|
|
1698
|
+
function createPfxCertOption(pfx, passphrase) {
|
|
1699
|
+
if (pfx.length === 0) {
|
|
1700
|
+
throw new ErrorWithCode(formatString(ErrorMessage.EmptyParameter, "pfx"), ErrorCode.InvalidParameter);
|
|
1701
|
+
}
|
|
1702
|
+
return {
|
|
1703
|
+
pfx,
|
|
1704
|
+
passphrase,
|
|
1705
|
+
};
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
// Copyright (c) Microsoft Corporation.
|
|
1709
|
+
// Following keys are used by SDK internally
|
|
1710
|
+
const ReservedKey = new Set([
|
|
1711
|
+
"authorityHost",
|
|
1712
|
+
"tenantId",
|
|
1713
|
+
"clientId",
|
|
1714
|
+
"clientSecret",
|
|
1715
|
+
"initiateLoginEndpoint",
|
|
1716
|
+
"applicationIdUri",
|
|
1717
|
+
"apiEndpoint",
|
|
1718
|
+
"apiName",
|
|
1719
|
+
"sqlServerEndpoint",
|
|
1720
|
+
"sqlUsername",
|
|
1721
|
+
"sqlPassword",
|
|
1722
|
+
"sqlDatabaseName",
|
|
1723
|
+
"sqlIdentityId",
|
|
1724
|
+
]);
|
|
1455
1725
|
/**
|
|
1456
1726
|
* A class providing credential and configuration.
|
|
1457
1727
|
* @beta
|
|
@@ -1625,10 +1895,10 @@ class TeamsFx {
|
|
|
1625
1895
|
this.configuration.set("sqlDatabaseName", env.SQL_DATABASE_NAME);
|
|
1626
1896
|
this.configuration.set("sqlIdentityId", env.IDENTITY_ID);
|
|
1627
1897
|
Object.keys(env).forEach((key) => {
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
this.configuration.set(key.substring(8), value);
|
|
1898
|
+
if (ReservedKey.has(key)) {
|
|
1899
|
+
internalLogger.warn(`The name of environment variable ${key} is preserved. Will not load it as configuration.`);
|
|
1631
1900
|
}
|
|
1901
|
+
this.configuration.set(key, env[key]);
|
|
1632
1902
|
});
|
|
1633
1903
|
}
|
|
1634
1904
|
}
|
|
@@ -1662,13 +1932,6 @@ class NotificationMiddleware {
|
|
|
1662
1932
|
await this.conversationReferenceStore.set(reference);
|
|
1663
1933
|
break;
|
|
1664
1934
|
}
|
|
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
1935
|
case ActivityType.CurrentBotUninstalled:
|
|
1673
1936
|
case ActivityType.TeamDeleted: {
|
|
1674
1937
|
const reference = TurnContext.getConversationReference(context.activity);
|
|
@@ -1690,9 +1953,6 @@ class NotificationMiddleware {
|
|
|
1690
1953
|
return ActivityType.CurrentBotUninstalled;
|
|
1691
1954
|
}
|
|
1692
1955
|
}
|
|
1693
|
-
else if (activityType === "message") {
|
|
1694
|
-
return ActivityType.CurrentBotMessaged;
|
|
1695
|
-
}
|
|
1696
1956
|
else if (activityType === "conversationUpdate") {
|
|
1697
1957
|
const eventType = (_b = activity.channelData) === null || _b === void 0 ? void 0 : _b.eventType;
|
|
1698
1958
|
if (eventType === "teamDeleted") {
|
|
@@ -2260,7 +2520,7 @@ class TeamsBotInstallation {
|
|
|
2260
2520
|
}
|
|
2261
2521
|
}
|
|
2262
2522
|
/**
|
|
2263
|
-
* Provide utilities to send notification to varies targets (e.g., member,
|
|
2523
|
+
* Provide utilities to send notification to varies targets (e.g., member, group, channel).
|
|
2264
2524
|
*
|
|
2265
2525
|
* @beta
|
|
2266
2526
|
*/
|
|
@@ -2329,7 +2589,7 @@ class NotificationBot {
|
|
|
2329
2589
|
/**
|
|
2330
2590
|
* Provide utilities for bot conversation, including:
|
|
2331
2591
|
* - handle command and response.
|
|
2332
|
-
* - send notification to varies targets (e.g., member,
|
|
2592
|
+
* - send notification to varies targets (e.g., member, group, channel).
|
|
2333
2593
|
*
|
|
2334
2594
|
* @example
|
|
2335
2595
|
* 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 +2599,7 @@ class NotificationBot {
|
|
|
2339
2599
|
* const conversationBot = new ConversationBot({
|
|
2340
2600
|
* command: {
|
|
2341
2601
|
* enabled: true,
|
|
2342
|
-
*
|
|
2343
|
-
* commands: [ new HelloWorldCommandHandler() ],
|
|
2344
|
-
* },
|
|
2602
|
+
* commands: [ new HelloWorldCommandHandler() ],
|
|
2345
2603
|
* },
|
|
2346
2604
|
* });
|
|
2347
2605
|
*
|
|
@@ -2349,7 +2607,7 @@ class NotificationBot {
|
|
|
2349
2607
|
* conversationBot.command.registerCommand(new HelpCommandHandler());
|
|
2350
2608
|
* ```
|
|
2351
2609
|
*
|
|
2352
|
-
* For notification, you can enable notification at initialization, then send
|
|
2610
|
+
* For notification, you can enable notification at initialization, then send notifications at any time.
|
|
2353
2611
|
*
|
|
2354
2612
|
* ```typescript
|
|
2355
2613
|
* // enable through constructor
|
|
@@ -2377,7 +2635,7 @@ class NotificationBot {
|
|
|
2377
2635
|
*
|
|
2378
2636
|
* 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
2637
|
*
|
|
2380
|
-
* For notification, set `notification.
|
|
2638
|
+
* For notification, set `notification.storage` in {@link ConversationOptions} to use your own storage implementation.
|
|
2381
2639
|
*
|
|
2382
2640
|
* @beta
|
|
2383
2641
|
*/
|
|
@@ -2385,26 +2643,76 @@ class ConversationBot {
|
|
|
2385
2643
|
/**
|
|
2386
2644
|
* Creates new instance of the `ConversationBot`.
|
|
2387
2645
|
*
|
|
2646
|
+
* @remarks
|
|
2647
|
+
* It's recommended to create your own adapter and storage for production environment instead of the default one.
|
|
2648
|
+
*
|
|
2388
2649
|
* @param options - initialize options
|
|
2389
2650
|
*
|
|
2390
2651
|
* @beta
|
|
2391
2652
|
*/
|
|
2392
2653
|
constructor(options) {
|
|
2654
|
+
var _a, _b;
|
|
2393
2655
|
if (options.adapter) {
|
|
2394
2656
|
this.adapter = options.adapter;
|
|
2395
2657
|
}
|
|
2396
2658
|
else {
|
|
2397
|
-
this.adapter =
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2659
|
+
this.adapter = this.createDefaultAdapter(options.adapterConfig);
|
|
2660
|
+
}
|
|
2661
|
+
if ((_a = options.command) === null || _a === void 0 ? void 0 : _a.enabled) {
|
|
2662
|
+
this.command = new CommandBot(this.adapter, options.command);
|
|
2401
2663
|
}
|
|
2402
|
-
if (options.
|
|
2403
|
-
this.
|
|
2664
|
+
if ((_b = options.notification) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
2665
|
+
this.notification = new NotificationBot(this.adapter, options.notification);
|
|
2404
2666
|
}
|
|
2405
|
-
|
|
2406
|
-
|
|
2667
|
+
}
|
|
2668
|
+
createDefaultAdapter(adapterConfig) {
|
|
2669
|
+
const adapter = adapterConfig === undefined
|
|
2670
|
+
? new BotFrameworkAdapter({
|
|
2671
|
+
appId: process.env.BOT_ID,
|
|
2672
|
+
appPassword: process.env.BOT_PASSWORD,
|
|
2673
|
+
})
|
|
2674
|
+
: new BotFrameworkAdapter(adapterConfig);
|
|
2675
|
+
// the default error handler
|
|
2676
|
+
adapter.onTurnError = async (context, error) => {
|
|
2677
|
+
// This check writes out errors to console.
|
|
2678
|
+
console.error(`[onTurnError] unhandled error: ${error}`);
|
|
2679
|
+
// Send a trace activity, which will be displayed in Bot Framework Emulator
|
|
2680
|
+
await context.sendTraceActivity("OnTurnError Trace", `${error}`, "https://www.botframework.com/schemas/error", "TurnError");
|
|
2681
|
+
// Send a message to the user
|
|
2682
|
+
await context.sendActivity(`The bot encountered unhandled error: ${error.message}`);
|
|
2683
|
+
await context.sendActivity("To continue to run this bot, please fix the bot source code.");
|
|
2684
|
+
};
|
|
2685
|
+
return adapter;
|
|
2686
|
+
}
|
|
2687
|
+
/**
|
|
2688
|
+
* The request handler to integrate with web request.
|
|
2689
|
+
*
|
|
2690
|
+
* @param req - an Express or Restify style request object.
|
|
2691
|
+
* @param res - an Express or Restify style response object.
|
|
2692
|
+
* @param logic - the additional function to handle bot context.
|
|
2693
|
+
*
|
|
2694
|
+
* @example
|
|
2695
|
+
* For example, to use with Restify:
|
|
2696
|
+
* ``` typescript
|
|
2697
|
+
* // The default/empty behavior
|
|
2698
|
+
* server.post("api/messages", conversationBot.requestHandler);
|
|
2699
|
+
*
|
|
2700
|
+
* // Or, add your own logic
|
|
2701
|
+
* server.post("api/messages", async (req, res) => {
|
|
2702
|
+
* await conversationBot.requestHandler(req, res, async (context) => {
|
|
2703
|
+
* // your-own-context-logic
|
|
2704
|
+
* });
|
|
2705
|
+
* });
|
|
2706
|
+
* ```
|
|
2707
|
+
*
|
|
2708
|
+
* @beta
|
|
2709
|
+
*/
|
|
2710
|
+
async requestHandler(req, res, logic) {
|
|
2711
|
+
if (logic === undefined) {
|
|
2712
|
+
// create empty logic
|
|
2713
|
+
logic = async () => { };
|
|
2407
2714
|
}
|
|
2715
|
+
await this.adapter.processActivity(req, res, logic);
|
|
2408
2716
|
}
|
|
2409
2717
|
}
|
|
2410
2718
|
|
|
@@ -2417,8 +2725,8 @@ class MessageBuilder {
|
|
|
2417
2725
|
/**
|
|
2418
2726
|
* Build a bot message activity attached with adaptive card.
|
|
2419
2727
|
*
|
|
2420
|
-
* @param getCardData Function to prepare your card data.
|
|
2421
2728
|
* @param cardTemplate The adaptive card template.
|
|
2729
|
+
* @param data card data used to render the template.
|
|
2422
2730
|
* @returns A bot message activity attached with an adaptive card.
|
|
2423
2731
|
*
|
|
2424
2732
|
* @example
|
|
@@ -2443,19 +2751,18 @@ class MessageBuilder {
|
|
|
2443
2751
|
* title: string,
|
|
2444
2752
|
* description: string
|
|
2445
2753
|
* };
|
|
2446
|
-
* const card = MessageBuilder.attachAdaptiveCard<CardData>(
|
|
2447
|
-
*
|
|
2448
|
-
*
|
|
2449
|
-
*
|
|
2450
|
-
*
|
|
2754
|
+
* const card = MessageBuilder.attachAdaptiveCard<CardData>(
|
|
2755
|
+
* cardTemplate, {
|
|
2756
|
+
* title: "sample card title",
|
|
2757
|
+
* description: "sample card description"
|
|
2758
|
+
* });
|
|
2451
2759
|
* ```
|
|
2452
2760
|
*
|
|
2453
2761
|
* @beta
|
|
2454
2762
|
*/
|
|
2455
|
-
static attachAdaptiveCard(
|
|
2456
|
-
const cardData = getCardData();
|
|
2763
|
+
static attachAdaptiveCard(cardTemplate, data) {
|
|
2457
2764
|
return {
|
|
2458
|
-
attachments: [CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(
|
|
2765
|
+
attachments: [CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(data))],
|
|
2459
2766
|
};
|
|
2460
2767
|
}
|
|
2461
2768
|
/**
|
|
@@ -2562,5 +2869,5 @@ class MessageBuilder {
|
|
|
2562
2869
|
}
|
|
2563
2870
|
}
|
|
2564
2871
|
|
|
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 };
|
|
2872
|
+
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
2873
|
//# sourceMappingURL=index.esm2017.mjs.map
|