@microsoft/teamsfx 1.1.2-alpha.c46d33f34.0 → 1.1.2-alpha.d61ffd7b2.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 +104 -19
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +394 -108
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +104 -19
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +402 -110
- package/dist/index.node.cjs.js.map +1 -1
- package/package.json +4 -3
- package/types/teamsfx.d.ts +222 -7
package/dist/index.node.cjs.js
CHANGED
|
@@ -728,10 +728,13 @@ class TeamsUserCredential {
|
|
|
728
728
|
}
|
|
729
729
|
/**
|
|
730
730
|
* Popup login page to get user's access token with specific scopes.
|
|
731
|
+
*
|
|
732
|
+
* @param {string[]} resources - The optional list of resources for full trust Teams apps.
|
|
733
|
+
*
|
|
731
734
|
* @remarks
|
|
732
735
|
* Can only be used within Teams.
|
|
733
736
|
*/
|
|
734
|
-
login(scopes) {
|
|
737
|
+
login(scopes, resources) {
|
|
735
738
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
736
739
|
throw new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), exports.ErrorCode.RuntimeNotSupported);
|
|
737
740
|
});
|
|
@@ -748,10 +751,13 @@ class TeamsUserCredential {
|
|
|
748
751
|
}
|
|
749
752
|
/**
|
|
750
753
|
* Get basic user info from SSO token
|
|
754
|
+
*
|
|
755
|
+
* @param {string[]} resources - The optional list of resources for full trust Teams apps.
|
|
756
|
+
*
|
|
751
757
|
* @remarks
|
|
752
758
|
* Can only be used within Teams.
|
|
753
759
|
*/
|
|
754
|
-
getUserInfo() {
|
|
760
|
+
getUserInfo(resources) {
|
|
755
761
|
throw new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "TeamsUserCredential"), exports.ErrorCode.RuntimeNotSupported);
|
|
756
762
|
}
|
|
757
763
|
}
|
|
@@ -1723,8 +1729,9 @@ class TeamsFx {
|
|
|
1723
1729
|
this.configuration = new Map();
|
|
1724
1730
|
this.loadFromEnv();
|
|
1725
1731
|
if (customConfig) {
|
|
1726
|
-
|
|
1727
|
-
|
|
1732
|
+
const myConfig = Object.assign({}, customConfig);
|
|
1733
|
+
for (const key of Object.keys(myConfig)) {
|
|
1734
|
+
const value = myConfig[key];
|
|
1728
1735
|
if (value) {
|
|
1729
1736
|
this.configuration.set(key, value);
|
|
1730
1737
|
}
|
|
@@ -1766,9 +1773,10 @@ class TeamsFx {
|
|
|
1766
1773
|
}
|
|
1767
1774
|
/**
|
|
1768
1775
|
* Get user information.
|
|
1776
|
+
* @param {string[]} resources - The optional list of resources for full trust Teams apps.
|
|
1769
1777
|
* @returns UserInfo object.
|
|
1770
1778
|
*/
|
|
1771
|
-
getUserInfo() {
|
|
1779
|
+
getUserInfo(resources) {
|
|
1772
1780
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1773
1781
|
if (this.identityType !== exports.IdentityType.User) {
|
|
1774
1782
|
const errorMsg = formatString(ErrorMessage.IdentityTypeNotSupported, this.identityType.toString(), "TeamsFx");
|
|
@@ -1792,13 +1800,14 @@ class TeamsFx {
|
|
|
1792
1800
|
* await teamsfx.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
|
|
1793
1801
|
* ```
|
|
1794
1802
|
* @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
|
|
1803
|
+
* @param {string[]} resources - The optional list of resources for full trust Teams apps.
|
|
1795
1804
|
*
|
|
1796
1805
|
* @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
|
|
1797
1806
|
* @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
|
|
1798
1807
|
* @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
|
|
1799
1808
|
* @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
|
|
1800
1809
|
*/
|
|
1801
|
-
login(scopes) {
|
|
1810
|
+
login(scopes, resources) {
|
|
1802
1811
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1803
1812
|
throw new ErrorWithCode(formatString(ErrorMessage.NodejsRuntimeNotSupported, "login"), exports.ErrorCode.RuntimeNotSupported);
|
|
1804
1813
|
});
|
|
@@ -1904,135 +1913,284 @@ exports.NotificationTargetType = void 0;
|
|
|
1904
1913
|
* The notification will be sent to a personal chat.
|
|
1905
1914
|
*/
|
|
1906
1915
|
NotificationTargetType["Person"] = "Person";
|
|
1907
|
-
})(exports.NotificationTargetType || (exports.NotificationTargetType = {}));
|
|
1916
|
+
})(exports.NotificationTargetType || (exports.NotificationTargetType = {}));
|
|
1917
|
+
/**
|
|
1918
|
+
* Options used to control how the response card will be sent to users.
|
|
1919
|
+
*/
|
|
1920
|
+
exports.AdaptiveCardResponse = void 0;
|
|
1921
|
+
(function (AdaptiveCardResponse) {
|
|
1922
|
+
/**
|
|
1923
|
+
* The response card will be replaced the current one for the interactor who trigger the action.
|
|
1924
|
+
*/
|
|
1925
|
+
AdaptiveCardResponse[AdaptiveCardResponse["ReplaceForInteractor"] = 0] = "ReplaceForInteractor";
|
|
1926
|
+
/**
|
|
1927
|
+
* The response card will be replaced the current one for all users in the chat.
|
|
1928
|
+
*/
|
|
1929
|
+
AdaptiveCardResponse[AdaptiveCardResponse["ReplaceForAll"] = 1] = "ReplaceForAll";
|
|
1930
|
+
/**
|
|
1931
|
+
* The response card will be sent as a new message for all users in the chat.
|
|
1932
|
+
*/
|
|
1933
|
+
AdaptiveCardResponse[AdaptiveCardResponse["NewForAll"] = 2] = "NewForAll";
|
|
1934
|
+
})(exports.AdaptiveCardResponse || (exports.AdaptiveCardResponse = {}));
|
|
1935
|
+
/**
|
|
1936
|
+
* Status code for an `application/vnd.microsoft.error` invoke response.
|
|
1937
|
+
*/
|
|
1938
|
+
exports.InvokeResponseErrorCode = void 0;
|
|
1939
|
+
(function (InvokeResponseErrorCode) {
|
|
1940
|
+
/**
|
|
1941
|
+
* Invalid request.
|
|
1942
|
+
*/
|
|
1943
|
+
InvokeResponseErrorCode[InvokeResponseErrorCode["BadRequest"] = 400] = "BadRequest";
|
|
1944
|
+
/**
|
|
1945
|
+
* Internal server error.
|
|
1946
|
+
*/
|
|
1947
|
+
InvokeResponseErrorCode[InvokeResponseErrorCode["InternalServerError"] = 500] = "InternalServerError";
|
|
1948
|
+
})(exports.InvokeResponseErrorCode || (exports.InvokeResponseErrorCode = {}));
|
|
1908
1949
|
|
|
1909
|
-
// Copyright (c) Microsoft Corporation.
|
|
1910
1950
|
/**
|
|
1951
|
+
* Available response type for an adaptive card invoke response.
|
|
1911
1952
|
* @internal
|
|
1912
1953
|
*/
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1954
|
+
var InvokeResponseType;
|
|
1955
|
+
(function (InvokeResponseType) {
|
|
1956
|
+
InvokeResponseType["AdaptiveCard"] = "application/vnd.microsoft.card.adaptive";
|
|
1957
|
+
InvokeResponseType["Message"] = "application/vnd.microsoft.activity.message";
|
|
1958
|
+
InvokeResponseType["Error"] = "application/vnd.microsoft.error";
|
|
1959
|
+
})(InvokeResponseType || (InvokeResponseType = {}));
|
|
1916
1960
|
/**
|
|
1917
|
-
*
|
|
1961
|
+
* Provides methods for formatting various invoke responses a bot can send to respond to an invoke request.
|
|
1962
|
+
*
|
|
1963
|
+
* @remarks
|
|
1964
|
+
* All of these functions return an {@link InvokeResponse} object, which can be
|
|
1965
|
+
* passed as input to generate a new `invokeResponse` activity.
|
|
1966
|
+
*
|
|
1967
|
+
* This example sends an invoke response that contains an adaptive card.
|
|
1968
|
+
*
|
|
1969
|
+
* ```typescript
|
|
1970
|
+
*
|
|
1971
|
+
* const myCard: IAdaptiveCard = {
|
|
1972
|
+
* type: "AdaptiveCard",
|
|
1973
|
+
* body: [
|
|
1974
|
+
* {
|
|
1975
|
+
* "type": "TextBlock",
|
|
1976
|
+
* "text": "This is a sample card"
|
|
1977
|
+
* }],
|
|
1978
|
+
* $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
|
|
1979
|
+
* version: "1.4"
|
|
1980
|
+
* };
|
|
1981
|
+
*
|
|
1982
|
+
* const invokeResponse = InvokeResponseFactory.adaptiveCard(myCard);
|
|
1983
|
+
* await context.sendActivity({
|
|
1984
|
+
* type: ActivityTypes.InvokeResponse,
|
|
1985
|
+
* value: invokeResponse,
|
|
1986
|
+
* });
|
|
1987
|
+
* ```
|
|
1918
1988
|
*/
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1989
|
+
class InvokeResponseFactory {
|
|
1990
|
+
/**
|
|
1991
|
+
* Create an invoke response from a text message.
|
|
1992
|
+
* The type of the invoke response is `application/vnd.microsoft.activity.message`
|
|
1993
|
+
* indicates the request was successfully processed.
|
|
1994
|
+
*
|
|
1995
|
+
* @param message A text message included in a invoke response.
|
|
1996
|
+
*
|
|
1997
|
+
* @returns {InvokeResponse} An InvokeResponse object.
|
|
1998
|
+
*/
|
|
1999
|
+
static textMessage(message) {
|
|
2000
|
+
if (!message) {
|
|
2001
|
+
throw new Error("The text message cannot be null or empty");
|
|
2002
|
+
}
|
|
2003
|
+
return {
|
|
2004
|
+
status: botbuilder.StatusCodes.OK,
|
|
2005
|
+
body: {
|
|
2006
|
+
statusCode: botbuilder.StatusCodes.OK,
|
|
2007
|
+
type: InvokeResponseType.Message,
|
|
2008
|
+
value: message,
|
|
2009
|
+
},
|
|
2010
|
+
};
|
|
1924
2011
|
}
|
|
1925
|
-
|
|
1926
|
-
|
|
2012
|
+
/**
|
|
2013
|
+
* Create an invoke response from an adaptive card.
|
|
2014
|
+
*
|
|
2015
|
+
* The type of the invoke response is `application/vnd.microsoft.card.adaptive` indicates
|
|
2016
|
+
* the request was successfully processed, and the response includes an adaptive card
|
|
2017
|
+
* that the client should display in place of the current one.
|
|
2018
|
+
*
|
|
2019
|
+
* @param card The adaptive card JSON payload.
|
|
2020
|
+
*
|
|
2021
|
+
* @returns {InvokeResponse} An InvokeResponse object.
|
|
2022
|
+
*/
|
|
2023
|
+
static adaptiveCard(card) {
|
|
2024
|
+
if (!card) {
|
|
2025
|
+
throw new Error("The adaptive card content cannot be null or undefined");
|
|
2026
|
+
}
|
|
2027
|
+
return {
|
|
2028
|
+
status: botbuilder.StatusCodes.OK,
|
|
2029
|
+
body: {
|
|
2030
|
+
statusCode: botbuilder.StatusCodes.OK,
|
|
2031
|
+
type: InvokeResponseType.AdaptiveCard,
|
|
2032
|
+
value: card,
|
|
2033
|
+
},
|
|
2034
|
+
};
|
|
1927
2035
|
}
|
|
1928
|
-
|
|
1929
|
-
|
|
2036
|
+
/**
|
|
2037
|
+
* Create an invoke response with error code and message.
|
|
2038
|
+
*
|
|
2039
|
+
* The type of the invoke response is `application/vnd.microsoft.error` indicates
|
|
2040
|
+
* the request was failed to processed.
|
|
2041
|
+
*
|
|
2042
|
+
* @param errorCode The status code indicates error, available values:
|
|
2043
|
+
* - 400 (BadRequest): indicate the incoming request was invalid.
|
|
2044
|
+
* - 500 (InternalServerError): indicate an unexpected error occurred.
|
|
2045
|
+
* @param errorMessage The error message.
|
|
2046
|
+
*
|
|
2047
|
+
* @returns {InvokeResponse} An InvokeResponse object.
|
|
2048
|
+
*/
|
|
2049
|
+
static errorResponse(errorCode, errorMessage) {
|
|
2050
|
+
return {
|
|
2051
|
+
status: botbuilder.StatusCodes.OK,
|
|
2052
|
+
body: {
|
|
2053
|
+
statusCode: errorCode,
|
|
2054
|
+
type: InvokeResponseType.Error,
|
|
2055
|
+
value: {
|
|
2056
|
+
code: errorCode.toString(),
|
|
2057
|
+
message: errorMessage,
|
|
2058
|
+
},
|
|
2059
|
+
},
|
|
2060
|
+
};
|
|
1930
2061
|
}
|
|
1931
|
-
|
|
1932
|
-
|
|
2062
|
+
/**
|
|
2063
|
+
* Create an invoke response with status code and response value.
|
|
2064
|
+
* @param statusCode The status code.
|
|
2065
|
+
* @param body The value of the response body.
|
|
2066
|
+
*
|
|
2067
|
+
* @returns {InvokeResponse} An InvokeResponse object.
|
|
2068
|
+
*/
|
|
2069
|
+
static createInvokeResponse(statusCode, body) {
|
|
2070
|
+
return {
|
|
2071
|
+
status: statusCode,
|
|
2072
|
+
body: body,
|
|
2073
|
+
};
|
|
1933
2074
|
}
|
|
1934
|
-
}
|
|
1935
|
-
/**
|
|
1936
|
-
* @internal
|
|
1937
|
-
*/
|
|
1938
|
-
function getTeamsBotInstallationId(context) {
|
|
1939
|
-
var _a, _b, _c, _d;
|
|
1940
|
-
return (_d = (_c = (_b = (_a = context.activity) === null || _a === void 0 ? void 0 : _a.channelData) === null || _b === void 0 ? void 0 : _b.team) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : context.activity.conversation.id;
|
|
1941
2075
|
}
|
|
1942
2076
|
|
|
1943
|
-
// Copyright (c) Microsoft Corporation.
|
|
1944
2077
|
/**
|
|
1945
2078
|
* @internal
|
|
1946
2079
|
*/
|
|
1947
|
-
|
|
1948
|
-
(
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
ActivityType[ActivityType["Unknown"] = 5] = "Unknown";
|
|
1955
|
-
})(ActivityType || (ActivityType = {}));
|
|
1956
|
-
/**
|
|
1957
|
-
* @internal
|
|
1958
|
-
*/
|
|
1959
|
-
class NotificationMiddleware {
|
|
1960
|
-
constructor(options) {
|
|
1961
|
-
this.conversationReferenceStore = options.conversationReferenceStore;
|
|
2080
|
+
class CardActionMiddleware {
|
|
2081
|
+
constructor(handlers) {
|
|
2082
|
+
this.actionHandlers = [];
|
|
2083
|
+
this.defaultMessage = "Your response was sent to the app";
|
|
2084
|
+
if (handlers && handlers.length > 0) {
|
|
2085
|
+
this.actionHandlers.push(...handlers);
|
|
2086
|
+
}
|
|
1962
2087
|
}
|
|
1963
2088
|
onTurn(context, next) {
|
|
2089
|
+
var _a, _b, _c;
|
|
1964
2090
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
2091
|
+
if (context.activity.name === "adaptiveCard/action") {
|
|
2092
|
+
const action = context.activity.value.action;
|
|
2093
|
+
const actionVerb = action.verb;
|
|
2094
|
+
for (const handler of this.actionHandlers) {
|
|
2095
|
+
if (((_a = handler.triggerVerb) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === (actionVerb === null || actionVerb === void 0 ? void 0 : actionVerb.toLowerCase())) {
|
|
2096
|
+
let response;
|
|
2097
|
+
try {
|
|
2098
|
+
response = yield handler.handleActionInvoked(context, action.data);
|
|
2099
|
+
}
|
|
2100
|
+
catch (error) {
|
|
2101
|
+
const errorResponse = InvokeResponseFactory.errorResponse(exports.InvokeResponseErrorCode.InternalServerError, error.message);
|
|
2102
|
+
yield this.sendInvokeResponse(context, errorResponse);
|
|
2103
|
+
throw error;
|
|
2104
|
+
}
|
|
2105
|
+
const responseType = (_b = response.body) === null || _b === void 0 ? void 0 : _b.type;
|
|
2106
|
+
switch (responseType) {
|
|
2107
|
+
case InvokeResponseType.AdaptiveCard:
|
|
2108
|
+
const card = (_c = response.body) === null || _c === void 0 ? void 0 : _c.value;
|
|
2109
|
+
if (!card) {
|
|
2110
|
+
const errorMessage = "Adaptive card content cannot be found in the response body";
|
|
2111
|
+
yield this.sendInvokeResponse(context, InvokeResponseFactory.errorResponse(exports.InvokeResponseErrorCode.InternalServerError, errorMessage));
|
|
2112
|
+
throw new Error(errorMessage);
|
|
2113
|
+
}
|
|
2114
|
+
if (card.refresh && handler.adaptiveCardResponse !== exports.AdaptiveCardResponse.NewForAll) {
|
|
2115
|
+
// Card won't be refreshed with AdaptiveCardResponse.ReplaceForInteractor.
|
|
2116
|
+
// So set to AdaptiveCardResponse.ReplaceForAll here.
|
|
2117
|
+
handler.adaptiveCardResponse = exports.AdaptiveCardResponse.ReplaceForAll;
|
|
2118
|
+
}
|
|
2119
|
+
const activity = botbuilder.MessageFactory.attachment(botbuilder.CardFactory.adaptiveCard(card));
|
|
2120
|
+
if (handler.adaptiveCardResponse === exports.AdaptiveCardResponse.NewForAll) {
|
|
2121
|
+
yield this.sendInvokeResponse(context, InvokeResponseFactory.textMessage(this.defaultMessage));
|
|
2122
|
+
yield context.sendActivity(activity);
|
|
2123
|
+
}
|
|
2124
|
+
else if (handler.adaptiveCardResponse === exports.AdaptiveCardResponse.ReplaceForAll) {
|
|
2125
|
+
activity.id = context.activity.replyToId;
|
|
2126
|
+
yield context.updateActivity(activity);
|
|
2127
|
+
yield this.sendInvokeResponse(context, response);
|
|
2128
|
+
}
|
|
2129
|
+
else {
|
|
2130
|
+
yield this.sendInvokeResponse(context, response);
|
|
2131
|
+
}
|
|
2132
|
+
break;
|
|
2133
|
+
case InvokeResponseType.Message:
|
|
2134
|
+
case InvokeResponseType.Error:
|
|
2135
|
+
default:
|
|
2136
|
+
yield this.sendInvokeResponse(context, response);
|
|
2137
|
+
break;
|
|
2138
|
+
}
|
|
2139
|
+
break;
|
|
2140
|
+
}
|
|
1982
2141
|
}
|
|
1983
2142
|
}
|
|
1984
2143
|
yield next();
|
|
1985
2144
|
});
|
|
1986
2145
|
}
|
|
1987
|
-
|
|
1988
|
-
var _a, _b;
|
|
1989
|
-
const activityType = activity.type;
|
|
1990
|
-
if (activityType === "installationUpdate") {
|
|
1991
|
-
const action = (_a = activity.action) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
1992
|
-
if (action === "add") {
|
|
1993
|
-
return ActivityType.CurrentBotInstalled;
|
|
1994
|
-
}
|
|
1995
|
-
else {
|
|
1996
|
-
return ActivityType.CurrentBotUninstalled;
|
|
1997
|
-
}
|
|
1998
|
-
}
|
|
1999
|
-
else if (activityType === "conversationUpdate") {
|
|
2000
|
-
const eventType = (_b = activity.channelData) === null || _b === void 0 ? void 0 : _b.eventType;
|
|
2001
|
-
if (eventType === "teamDeleted") {
|
|
2002
|
-
return ActivityType.TeamDeleted;
|
|
2003
|
-
}
|
|
2004
|
-
else if (eventType === "teamRestored") {
|
|
2005
|
-
return ActivityType.TeamRestored;
|
|
2006
|
-
}
|
|
2007
|
-
}
|
|
2008
|
-
else if (activityType === "message") {
|
|
2009
|
-
return ActivityType.CurrentBotMessaged;
|
|
2010
|
-
}
|
|
2011
|
-
return ActivityType.Unknown;
|
|
2012
|
-
}
|
|
2013
|
-
tryAddMessagedReference(context) {
|
|
2014
|
-
var _a, _b, _c, _d;
|
|
2146
|
+
sendInvokeResponse(context, response) {
|
|
2015
2147
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
yield this.conversationReferenceStore.set(reference);
|
|
2021
|
-
}
|
|
2022
|
-
}
|
|
2023
|
-
else if (conversationType === "channel") {
|
|
2024
|
-
const teamId = (_d = (_c = (_b = context.activity) === null || _b === void 0 ? void 0 : _b.channelData) === null || _c === void 0 ? void 0 : _c.team) === null || _d === void 0 ? void 0 : _d.id;
|
|
2025
|
-
if (teamId !== undefined) {
|
|
2026
|
-
const teamReference = cloneConversation(reference);
|
|
2027
|
-
teamReference.conversation.id = teamId;
|
|
2028
|
-
if (!(yield this.conversationReferenceStore.check(teamReference))) {
|
|
2029
|
-
yield this.conversationReferenceStore.set(teamReference);
|
|
2030
|
-
}
|
|
2031
|
-
}
|
|
2032
|
-
}
|
|
2148
|
+
yield context.sendActivity({
|
|
2149
|
+
type: botbuilder.ActivityTypes.InvokeResponse,
|
|
2150
|
+
value: response,
|
|
2151
|
+
});
|
|
2033
2152
|
});
|
|
2034
2153
|
}
|
|
2035
|
-
}
|
|
2154
|
+
}
|
|
2155
|
+
|
|
2156
|
+
/**
|
|
2157
|
+
* A card action bot to respond to adaptive card universal actions.
|
|
2158
|
+
*/
|
|
2159
|
+
class CardActionBot {
|
|
2160
|
+
/**
|
|
2161
|
+
* Creates a new instance of the `CardActionBot`.
|
|
2162
|
+
*
|
|
2163
|
+
* @param adapter The bound `BotFrameworkAdapter`.
|
|
2164
|
+
* @param options - initialize options
|
|
2165
|
+
*/
|
|
2166
|
+
constructor(adapter, options) {
|
|
2167
|
+
this.middleware = new CardActionMiddleware(options === null || options === void 0 ? void 0 : options.actions);
|
|
2168
|
+
this.adapter = adapter.use(this.middleware);
|
|
2169
|
+
}
|
|
2170
|
+
/**
|
|
2171
|
+
* Registers a card action handler to the bot.
|
|
2172
|
+
* @param actionHandler A card action handler to be registered.
|
|
2173
|
+
*/
|
|
2174
|
+
registerHandler(actionHandler) {
|
|
2175
|
+
if (actionHandler) {
|
|
2176
|
+
this.middleware.actionHandlers.push(actionHandler);
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
/**
|
|
2180
|
+
* Registers card action handlers to the bot.
|
|
2181
|
+
* @param actionHandlers A set of card action handlers to be registered.
|
|
2182
|
+
*/
|
|
2183
|
+
registerHandlers(actionHandlers) {
|
|
2184
|
+
if (actionHandlers) {
|
|
2185
|
+
this.middleware.actionHandlers.push(...actionHandlers);
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
// Copyright (c) Microsoft Corporation.
|
|
2191
|
+
/**
|
|
2192
|
+
* @internal
|
|
2193
|
+
*/
|
|
2036
2194
|
class CommandResponseMiddleware {
|
|
2037
2195
|
constructor(handlers) {
|
|
2038
2196
|
this.commandHandlers = [];
|
|
@@ -2064,6 +2222,7 @@ class CommandResponseMiddleware {
|
|
|
2064
2222
|
yield context.sendActivity(replyActivity);
|
|
2065
2223
|
}
|
|
2066
2224
|
}
|
|
2225
|
+
break;
|
|
2067
2226
|
}
|
|
2068
2227
|
}
|
|
2069
2228
|
}
|
|
@@ -2145,6 +2304,134 @@ class CommandBot {
|
|
|
2145
2304
|
}
|
|
2146
2305
|
}
|
|
2147
2306
|
|
|
2307
|
+
// Copyright (c) Microsoft Corporation.
|
|
2308
|
+
/**
|
|
2309
|
+
* @internal
|
|
2310
|
+
*/
|
|
2311
|
+
function cloneConversation(conversation) {
|
|
2312
|
+
return JSON.parse(JSON.stringify(conversation));
|
|
2313
|
+
}
|
|
2314
|
+
/**
|
|
2315
|
+
* @internal
|
|
2316
|
+
*/
|
|
2317
|
+
function getTargetType(conversationReference) {
|
|
2318
|
+
var _a;
|
|
2319
|
+
const conversationType = (_a = conversationReference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
|
|
2320
|
+
if (conversationType === "personal") {
|
|
2321
|
+
return exports.NotificationTargetType.Person;
|
|
2322
|
+
}
|
|
2323
|
+
else if (conversationType === "groupChat") {
|
|
2324
|
+
return exports.NotificationTargetType.Group;
|
|
2325
|
+
}
|
|
2326
|
+
else if (conversationType === "channel") {
|
|
2327
|
+
return exports.NotificationTargetType.Channel;
|
|
2328
|
+
}
|
|
2329
|
+
else {
|
|
2330
|
+
return undefined;
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
/**
|
|
2334
|
+
* @internal
|
|
2335
|
+
*/
|
|
2336
|
+
function getTeamsBotInstallationId(context) {
|
|
2337
|
+
var _a, _b, _c, _d;
|
|
2338
|
+
return (_d = (_c = (_b = (_a = context.activity) === null || _a === void 0 ? void 0 : _a.channelData) === null || _b === void 0 ? void 0 : _b.team) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : context.activity.conversation.id;
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
// Copyright (c) Microsoft Corporation.
|
|
2342
|
+
/**
|
|
2343
|
+
* @internal
|
|
2344
|
+
*/
|
|
2345
|
+
var ActivityType;
|
|
2346
|
+
(function (ActivityType) {
|
|
2347
|
+
ActivityType[ActivityType["CurrentBotInstalled"] = 0] = "CurrentBotInstalled";
|
|
2348
|
+
ActivityType[ActivityType["CurrentBotMessaged"] = 1] = "CurrentBotMessaged";
|
|
2349
|
+
ActivityType[ActivityType["CurrentBotUninstalled"] = 2] = "CurrentBotUninstalled";
|
|
2350
|
+
ActivityType[ActivityType["TeamDeleted"] = 3] = "TeamDeleted";
|
|
2351
|
+
ActivityType[ActivityType["TeamRestored"] = 4] = "TeamRestored";
|
|
2352
|
+
ActivityType[ActivityType["Unknown"] = 5] = "Unknown";
|
|
2353
|
+
})(ActivityType || (ActivityType = {}));
|
|
2354
|
+
/**
|
|
2355
|
+
* @internal
|
|
2356
|
+
*/
|
|
2357
|
+
class NotificationMiddleware {
|
|
2358
|
+
constructor(options) {
|
|
2359
|
+
this.conversationReferenceStore = options.conversationReferenceStore;
|
|
2360
|
+
}
|
|
2361
|
+
onTurn(context, next) {
|
|
2362
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
2363
|
+
const type = this.classifyActivity(context.activity);
|
|
2364
|
+
switch (type) {
|
|
2365
|
+
case ActivityType.CurrentBotInstalled:
|
|
2366
|
+
case ActivityType.TeamRestored: {
|
|
2367
|
+
const reference = botbuilder.TurnContext.getConversationReference(context.activity);
|
|
2368
|
+
yield this.conversationReferenceStore.set(reference);
|
|
2369
|
+
break;
|
|
2370
|
+
}
|
|
2371
|
+
case ActivityType.CurrentBotMessaged: {
|
|
2372
|
+
yield this.tryAddMessagedReference(context);
|
|
2373
|
+
break;
|
|
2374
|
+
}
|
|
2375
|
+
case ActivityType.CurrentBotUninstalled:
|
|
2376
|
+
case ActivityType.TeamDeleted: {
|
|
2377
|
+
const reference = botbuilder.TurnContext.getConversationReference(context.activity);
|
|
2378
|
+
yield this.conversationReferenceStore.delete(reference);
|
|
2379
|
+
break;
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
yield next();
|
|
2383
|
+
});
|
|
2384
|
+
}
|
|
2385
|
+
classifyActivity(activity) {
|
|
2386
|
+
var _a, _b;
|
|
2387
|
+
const activityType = activity.type;
|
|
2388
|
+
if (activityType === "installationUpdate") {
|
|
2389
|
+
const action = (_a = activity.action) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
2390
|
+
if (action === "add") {
|
|
2391
|
+
return ActivityType.CurrentBotInstalled;
|
|
2392
|
+
}
|
|
2393
|
+
else {
|
|
2394
|
+
return ActivityType.CurrentBotUninstalled;
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
else if (activityType === "conversationUpdate") {
|
|
2398
|
+
const eventType = (_b = activity.channelData) === null || _b === void 0 ? void 0 : _b.eventType;
|
|
2399
|
+
if (eventType === "teamDeleted") {
|
|
2400
|
+
return ActivityType.TeamDeleted;
|
|
2401
|
+
}
|
|
2402
|
+
else if (eventType === "teamRestored") {
|
|
2403
|
+
return ActivityType.TeamRestored;
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
else if (activityType === "message") {
|
|
2407
|
+
return ActivityType.CurrentBotMessaged;
|
|
2408
|
+
}
|
|
2409
|
+
return ActivityType.Unknown;
|
|
2410
|
+
}
|
|
2411
|
+
tryAddMessagedReference(context) {
|
|
2412
|
+
var _a, _b, _c, _d;
|
|
2413
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
2414
|
+
const reference = botbuilder.TurnContext.getConversationReference(context.activity);
|
|
2415
|
+
const conversationType = (_a = reference === null || reference === void 0 ? void 0 : reference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
|
|
2416
|
+
if (conversationType === "personal" || conversationType === "groupChat") {
|
|
2417
|
+
if (!(yield this.conversationReferenceStore.check(reference))) {
|
|
2418
|
+
yield this.conversationReferenceStore.set(reference);
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
else if (conversationType === "channel") {
|
|
2422
|
+
const teamId = (_d = (_c = (_b = context.activity) === null || _b === void 0 ? void 0 : _b.channelData) === null || _c === void 0 ? void 0 : _c.team) === null || _d === void 0 ? void 0 : _d.id;
|
|
2423
|
+
if (teamId !== undefined) {
|
|
2424
|
+
const teamReference = cloneConversation(reference);
|
|
2425
|
+
teamReference.conversation.id = teamId;
|
|
2426
|
+
if (!(yield this.conversationReferenceStore.check(teamReference))) {
|
|
2427
|
+
yield this.conversationReferenceStore.set(teamReference);
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
});
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
|
|
2148
2435
|
// Copyright (c) Microsoft Corporation.
|
|
2149
2436
|
/**
|
|
2150
2437
|
* @internal
|
|
@@ -2682,7 +2969,7 @@ class ConversationBot {
|
|
|
2682
2969
|
* @param options - initialize options
|
|
2683
2970
|
*/
|
|
2684
2971
|
constructor(options) {
|
|
2685
|
-
var _a, _b;
|
|
2972
|
+
var _a, _b, _c;
|
|
2686
2973
|
if (options.adapter) {
|
|
2687
2974
|
this.adapter = options.adapter;
|
|
2688
2975
|
}
|
|
@@ -2695,6 +2982,9 @@ class ConversationBot {
|
|
|
2695
2982
|
if ((_b = options.notification) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
2696
2983
|
this.notification = new NotificationBot(this.adapter, options.notification);
|
|
2697
2984
|
}
|
|
2985
|
+
if ((_c = options.cardAction) === null || _c === void 0 ? void 0 : _c.enabled) {
|
|
2986
|
+
this.cardAction = new CardActionBot(this.adapter, options.cardAction);
|
|
2987
|
+
}
|
|
2698
2988
|
}
|
|
2699
2989
|
createDefaultAdapter(adapterConfig) {
|
|
2700
2990
|
const adapter = adapterConfig === undefined
|
|
@@ -2887,11 +3177,13 @@ exports.ApiKeyProvider = ApiKeyProvider;
|
|
|
2887
3177
|
exports.AppCredential = AppCredential;
|
|
2888
3178
|
exports.BasicAuthProvider = BasicAuthProvider;
|
|
2889
3179
|
exports.BearerTokenAuthProvider = BearerTokenAuthProvider;
|
|
3180
|
+
exports.CardActionBot = CardActionBot;
|
|
2890
3181
|
exports.CertificateAuthProvider = CertificateAuthProvider;
|
|
2891
3182
|
exports.Channel = Channel;
|
|
2892
3183
|
exports.CommandBot = CommandBot;
|
|
2893
3184
|
exports.ConversationBot = ConversationBot;
|
|
2894
3185
|
exports.ErrorWithCode = ErrorWithCode;
|
|
3186
|
+
exports.InvokeResponseFactory = InvokeResponseFactory;
|
|
2895
3187
|
exports.Member = Member;
|
|
2896
3188
|
exports.MessageBuilder = MessageBuilder;
|
|
2897
3189
|
exports.MsGraphAuthProvider = MsGraphAuthProvider;
|