@microsoft/teamsfx 1.1.2-alpha.062e4a5ea.0 → 1.1.2-alpha.11f97f07d.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 +73 -3
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +379 -102
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +73 -3
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +387 -104
- package/dist/index.node.cjs.js.map +1 -1
- package/package.json +4 -3
- package/types/teamsfx.d.ts +201 -0
package/dist/index.node.cjs.js
CHANGED
|
@@ -1904,135 +1904,284 @@ exports.NotificationTargetType = void 0;
|
|
|
1904
1904
|
* The notification will be sent to a personal chat.
|
|
1905
1905
|
*/
|
|
1906
1906
|
NotificationTargetType["Person"] = "Person";
|
|
1907
|
-
})(exports.NotificationTargetType || (exports.NotificationTargetType = {}));
|
|
1907
|
+
})(exports.NotificationTargetType || (exports.NotificationTargetType = {}));
|
|
1908
|
+
/**
|
|
1909
|
+
* Options used to control how the response card will be sent to users.
|
|
1910
|
+
*/
|
|
1911
|
+
exports.AdaptiveCardResponse = void 0;
|
|
1912
|
+
(function (AdaptiveCardResponse) {
|
|
1913
|
+
/**
|
|
1914
|
+
* The response card will be replaced the current one for the interactor who trigger the action.
|
|
1915
|
+
*/
|
|
1916
|
+
AdaptiveCardResponse[AdaptiveCardResponse["ReplaceForInteractor"] = 0] = "ReplaceForInteractor";
|
|
1917
|
+
/**
|
|
1918
|
+
* The response card will be replaced the current one for all users in the chat.
|
|
1919
|
+
*/
|
|
1920
|
+
AdaptiveCardResponse[AdaptiveCardResponse["ReplaceForAll"] = 1] = "ReplaceForAll";
|
|
1921
|
+
/**
|
|
1922
|
+
* The response card will be sent as a new message for all users in the chat.
|
|
1923
|
+
*/
|
|
1924
|
+
AdaptiveCardResponse[AdaptiveCardResponse["NewForAll"] = 2] = "NewForAll";
|
|
1925
|
+
})(exports.AdaptiveCardResponse || (exports.AdaptiveCardResponse = {}));
|
|
1926
|
+
/**
|
|
1927
|
+
* Status code for an `application/vnd.microsoft.error` invoke response.
|
|
1928
|
+
*/
|
|
1929
|
+
exports.InvokeResponseErrorCode = void 0;
|
|
1930
|
+
(function (InvokeResponseErrorCode) {
|
|
1931
|
+
/**
|
|
1932
|
+
* Invalid request.
|
|
1933
|
+
*/
|
|
1934
|
+
InvokeResponseErrorCode[InvokeResponseErrorCode["BadRequest"] = 400] = "BadRequest";
|
|
1935
|
+
/**
|
|
1936
|
+
* Internal server error.
|
|
1937
|
+
*/
|
|
1938
|
+
InvokeResponseErrorCode[InvokeResponseErrorCode["InternalServerError"] = 500] = "InternalServerError";
|
|
1939
|
+
})(exports.InvokeResponseErrorCode || (exports.InvokeResponseErrorCode = {}));
|
|
1908
1940
|
|
|
1909
|
-
// Copyright (c) Microsoft Corporation.
|
|
1910
1941
|
/**
|
|
1942
|
+
* Available response type for an adaptive card invoke response.
|
|
1911
1943
|
* @internal
|
|
1912
1944
|
*/
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1945
|
+
var InvokeResponseType;
|
|
1946
|
+
(function (InvokeResponseType) {
|
|
1947
|
+
InvokeResponseType["AdaptiveCard"] = "application/vnd.microsoft.card.adaptive";
|
|
1948
|
+
InvokeResponseType["Message"] = "application/vnd.microsoft.activity.message";
|
|
1949
|
+
InvokeResponseType["Error"] = "application/vnd.microsoft.error";
|
|
1950
|
+
})(InvokeResponseType || (InvokeResponseType = {}));
|
|
1916
1951
|
/**
|
|
1917
|
-
*
|
|
1952
|
+
* Provides methods for formatting various invoke responses a bot can send to respond to an invoke request.
|
|
1953
|
+
*
|
|
1954
|
+
* @remarks
|
|
1955
|
+
* All of these functions return an {@link InvokeResponse} object, which can be
|
|
1956
|
+
* passed as input to generate a new `invokeResponse` activity.
|
|
1957
|
+
*
|
|
1958
|
+
* This example sends an invoke response that contains an adaptive card.
|
|
1959
|
+
*
|
|
1960
|
+
* ```typescript
|
|
1961
|
+
*
|
|
1962
|
+
* const myCard: IAdaptiveCard = {
|
|
1963
|
+
* type: "AdaptiveCard",
|
|
1964
|
+
* body: [
|
|
1965
|
+
* {
|
|
1966
|
+
* "type": "TextBlock",
|
|
1967
|
+
* "text": "This is a sample card"
|
|
1968
|
+
* }],
|
|
1969
|
+
* $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
|
|
1970
|
+
* version: "1.4"
|
|
1971
|
+
* };
|
|
1972
|
+
*
|
|
1973
|
+
* const invokeResponse = InvokeResponseFactory.adaptiveCard(myCard);
|
|
1974
|
+
* await context.sendActivity({
|
|
1975
|
+
* type: ActivityTypes.InvokeResponse,
|
|
1976
|
+
* value: invokeResponse,
|
|
1977
|
+
* });
|
|
1978
|
+
* ```
|
|
1918
1979
|
*/
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1980
|
+
class InvokeResponseFactory {
|
|
1981
|
+
/**
|
|
1982
|
+
* Create an invoke response from a text message.
|
|
1983
|
+
* The type of the invoke response is `application/vnd.microsoft.activity.message`
|
|
1984
|
+
* indicates the request was successfully processed.
|
|
1985
|
+
*
|
|
1986
|
+
* @param message A text message included in a invoke response.
|
|
1987
|
+
*
|
|
1988
|
+
* @returns {InvokeResponse} An InvokeResponse object.
|
|
1989
|
+
*/
|
|
1990
|
+
static textMessage(message) {
|
|
1991
|
+
if (!message) {
|
|
1992
|
+
throw new Error("The text message cannot be null or empty");
|
|
1993
|
+
}
|
|
1994
|
+
return {
|
|
1995
|
+
status: botbuilder.StatusCodes.OK,
|
|
1996
|
+
body: {
|
|
1997
|
+
statusCode: botbuilder.StatusCodes.OK,
|
|
1998
|
+
type: InvokeResponseType.Message,
|
|
1999
|
+
value: message,
|
|
2000
|
+
},
|
|
2001
|
+
};
|
|
1924
2002
|
}
|
|
1925
|
-
|
|
1926
|
-
|
|
2003
|
+
/**
|
|
2004
|
+
* Create an invoke response from an adaptive card.
|
|
2005
|
+
*
|
|
2006
|
+
* The type of the invoke response is `application/vnd.microsoft.card.adaptive` indicates
|
|
2007
|
+
* the request was successfully processed, and the response includes an adaptive card
|
|
2008
|
+
* that the client should display in place of the current one.
|
|
2009
|
+
*
|
|
2010
|
+
* @param card The adaptive card JSON payload.
|
|
2011
|
+
*
|
|
2012
|
+
* @returns {InvokeResponse} An InvokeResponse object.
|
|
2013
|
+
*/
|
|
2014
|
+
static adaptiveCard(card) {
|
|
2015
|
+
if (!card) {
|
|
2016
|
+
throw new Error("The adaptive card content cannot be null or undefined");
|
|
2017
|
+
}
|
|
2018
|
+
return {
|
|
2019
|
+
status: botbuilder.StatusCodes.OK,
|
|
2020
|
+
body: {
|
|
2021
|
+
statusCode: botbuilder.StatusCodes.OK,
|
|
2022
|
+
type: InvokeResponseType.AdaptiveCard,
|
|
2023
|
+
value: card,
|
|
2024
|
+
},
|
|
2025
|
+
};
|
|
1927
2026
|
}
|
|
1928
|
-
|
|
1929
|
-
|
|
2027
|
+
/**
|
|
2028
|
+
* Create an invoke response with error code and message.
|
|
2029
|
+
*
|
|
2030
|
+
* The type of the invoke response is `application/vnd.microsoft.error` indicates
|
|
2031
|
+
* the request was failed to processed.
|
|
2032
|
+
*
|
|
2033
|
+
* @param errorCode The status code indicates error, available values:
|
|
2034
|
+
* - 400 (BadRequest): indicate the incoming request was invalid.
|
|
2035
|
+
* - 500 (InternalServerError): indicate an unexpected error occurred.
|
|
2036
|
+
* @param errorMessage The error message.
|
|
2037
|
+
*
|
|
2038
|
+
* @returns {InvokeResponse} An InvokeResponse object.
|
|
2039
|
+
*/
|
|
2040
|
+
static errorResponse(errorCode, errorMessage) {
|
|
2041
|
+
return {
|
|
2042
|
+
status: botbuilder.StatusCodes.OK,
|
|
2043
|
+
body: {
|
|
2044
|
+
statusCode: errorCode,
|
|
2045
|
+
type: InvokeResponseType.Error,
|
|
2046
|
+
value: {
|
|
2047
|
+
code: errorCode.toString(),
|
|
2048
|
+
message: errorMessage,
|
|
2049
|
+
},
|
|
2050
|
+
},
|
|
2051
|
+
};
|
|
1930
2052
|
}
|
|
1931
|
-
|
|
1932
|
-
|
|
2053
|
+
/**
|
|
2054
|
+
* Create an invoke response with status code and response value.
|
|
2055
|
+
* @param statusCode The status code.
|
|
2056
|
+
* @param body The value of the response body.
|
|
2057
|
+
*
|
|
2058
|
+
* @returns {InvokeResponse} An InvokeResponse object.
|
|
2059
|
+
*/
|
|
2060
|
+
static createInvokeResponse(statusCode, body) {
|
|
2061
|
+
return {
|
|
2062
|
+
status: statusCode,
|
|
2063
|
+
body: body,
|
|
2064
|
+
};
|
|
1933
2065
|
}
|
|
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
2066
|
}
|
|
1942
2067
|
|
|
1943
|
-
// Copyright (c) Microsoft Corporation.
|
|
1944
|
-
/**
|
|
1945
|
-
* @internal
|
|
1946
|
-
*/
|
|
1947
|
-
var ActivityType;
|
|
1948
|
-
(function (ActivityType) {
|
|
1949
|
-
ActivityType[ActivityType["CurrentBotInstalled"] = 0] = "CurrentBotInstalled";
|
|
1950
|
-
ActivityType[ActivityType["CurrentBotMessaged"] = 1] = "CurrentBotMessaged";
|
|
1951
|
-
ActivityType[ActivityType["CurrentBotUninstalled"] = 2] = "CurrentBotUninstalled";
|
|
1952
|
-
ActivityType[ActivityType["TeamDeleted"] = 3] = "TeamDeleted";
|
|
1953
|
-
ActivityType[ActivityType["TeamRestored"] = 4] = "TeamRestored";
|
|
1954
|
-
ActivityType[ActivityType["Unknown"] = 5] = "Unknown";
|
|
1955
|
-
})(ActivityType || (ActivityType = {}));
|
|
1956
2068
|
/**
|
|
1957
2069
|
* @internal
|
|
1958
2070
|
*/
|
|
1959
|
-
class
|
|
1960
|
-
constructor(
|
|
1961
|
-
this.
|
|
2071
|
+
class CardActionMiddleware {
|
|
2072
|
+
constructor(handlers) {
|
|
2073
|
+
this.actionHandlers = [];
|
|
2074
|
+
this.defaultMessage = "Your response was sent to the app";
|
|
2075
|
+
if (handlers && handlers.length > 0) {
|
|
2076
|
+
this.actionHandlers.push(...handlers);
|
|
2077
|
+
}
|
|
1962
2078
|
}
|
|
1963
2079
|
onTurn(context, next) {
|
|
2080
|
+
var _a, _b, _c;
|
|
1964
2081
|
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
|
-
|
|
2082
|
+
if (context.activity.name === "adaptiveCard/action") {
|
|
2083
|
+
const action = context.activity.value.action;
|
|
2084
|
+
const actionVerb = action.verb;
|
|
2085
|
+
for (const handler of this.actionHandlers) {
|
|
2086
|
+
if (((_a = handler.triggerVerb) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === (actionVerb === null || actionVerb === void 0 ? void 0 : actionVerb.toLowerCase())) {
|
|
2087
|
+
let response;
|
|
2088
|
+
try {
|
|
2089
|
+
response = yield handler.handleActionInvoked(context, action.data);
|
|
2090
|
+
}
|
|
2091
|
+
catch (error) {
|
|
2092
|
+
const errorResponse = InvokeResponseFactory.errorResponse(exports.InvokeResponseErrorCode.InternalServerError, error.message);
|
|
2093
|
+
yield this.sendInvokeResponse(context, errorResponse);
|
|
2094
|
+
throw error;
|
|
2095
|
+
}
|
|
2096
|
+
const responseType = (_b = response.body) === null || _b === void 0 ? void 0 : _b.type;
|
|
2097
|
+
switch (responseType) {
|
|
2098
|
+
case InvokeResponseType.AdaptiveCard:
|
|
2099
|
+
const card = (_c = response.body) === null || _c === void 0 ? void 0 : _c.value;
|
|
2100
|
+
if (!card) {
|
|
2101
|
+
const errorMessage = "Adaptive card content cannot be found in the response body";
|
|
2102
|
+
yield this.sendInvokeResponse(context, InvokeResponseFactory.errorResponse(exports.InvokeResponseErrorCode.InternalServerError, errorMessage));
|
|
2103
|
+
throw new Error(errorMessage);
|
|
2104
|
+
}
|
|
2105
|
+
if (card.refresh && handler.adaptiveCardResponse !== exports.AdaptiveCardResponse.NewForAll) {
|
|
2106
|
+
// Card won't be refreshed with AdaptiveCardResponse.ReplaceForInteractor.
|
|
2107
|
+
// So set to AdaptiveCardResponse.ReplaceForAll here.
|
|
2108
|
+
handler.adaptiveCardResponse = exports.AdaptiveCardResponse.ReplaceForAll;
|
|
2109
|
+
}
|
|
2110
|
+
const activity = botbuilder.MessageFactory.attachment(botbuilder.CardFactory.adaptiveCard(card));
|
|
2111
|
+
if (handler.adaptiveCardResponse === exports.AdaptiveCardResponse.NewForAll) {
|
|
2112
|
+
yield this.sendInvokeResponse(context, InvokeResponseFactory.textMessage(this.defaultMessage));
|
|
2113
|
+
yield context.sendActivity(activity);
|
|
2114
|
+
}
|
|
2115
|
+
else if (handler.adaptiveCardResponse === exports.AdaptiveCardResponse.ReplaceForAll) {
|
|
2116
|
+
activity.id = context.activity.replyToId;
|
|
2117
|
+
yield context.updateActivity(activity);
|
|
2118
|
+
yield this.sendInvokeResponse(context, response);
|
|
2119
|
+
}
|
|
2120
|
+
else {
|
|
2121
|
+
yield this.sendInvokeResponse(context, response);
|
|
2122
|
+
}
|
|
2123
|
+
break;
|
|
2124
|
+
case InvokeResponseType.Message:
|
|
2125
|
+
case InvokeResponseType.Error:
|
|
2126
|
+
default:
|
|
2127
|
+
yield this.sendInvokeResponse(context, response);
|
|
2128
|
+
break;
|
|
2129
|
+
}
|
|
2130
|
+
break;
|
|
2131
|
+
}
|
|
1982
2132
|
}
|
|
1983
2133
|
}
|
|
1984
2134
|
yield next();
|
|
1985
2135
|
});
|
|
1986
2136
|
}
|
|
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;
|
|
2137
|
+
sendInvokeResponse(context, response) {
|
|
2015
2138
|
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
|
-
}
|
|
2139
|
+
yield context.sendActivity({
|
|
2140
|
+
type: botbuilder.ActivityTypes.InvokeResponse,
|
|
2141
|
+
value: response,
|
|
2142
|
+
});
|
|
2033
2143
|
});
|
|
2034
2144
|
}
|
|
2035
|
-
}
|
|
2145
|
+
}
|
|
2146
|
+
|
|
2147
|
+
/**
|
|
2148
|
+
* A card action bot to respond to adaptive card universal actions.
|
|
2149
|
+
*/
|
|
2150
|
+
class CardActionBot {
|
|
2151
|
+
/**
|
|
2152
|
+
* Creates a new instance of the `CardActionBot`.
|
|
2153
|
+
*
|
|
2154
|
+
* @param adapter The bound `BotFrameworkAdapter`.
|
|
2155
|
+
* @param options - initialize options
|
|
2156
|
+
*/
|
|
2157
|
+
constructor(adapter, options) {
|
|
2158
|
+
this.middleware = new CardActionMiddleware(options === null || options === void 0 ? void 0 : options.actions);
|
|
2159
|
+
this.adapter = adapter.use(this.middleware);
|
|
2160
|
+
}
|
|
2161
|
+
/**
|
|
2162
|
+
* Registers a card action handler to the bot.
|
|
2163
|
+
* @param actionHandler A card action handler to be registered.
|
|
2164
|
+
*/
|
|
2165
|
+
registerHandler(actionHandler) {
|
|
2166
|
+
if (actionHandler) {
|
|
2167
|
+
this.middleware.actionHandlers.push(actionHandler);
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
/**
|
|
2171
|
+
* Registers card action handlers to the bot.
|
|
2172
|
+
* @param actionHandlers A set of card action handlers to be registered.
|
|
2173
|
+
*/
|
|
2174
|
+
registerHandlers(actionHandlers) {
|
|
2175
|
+
if (actionHandlers) {
|
|
2176
|
+
this.middleware.actionHandlers.push(...actionHandlers);
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2181
|
+
// Copyright (c) Microsoft Corporation.
|
|
2182
|
+
/**
|
|
2183
|
+
* @internal
|
|
2184
|
+
*/
|
|
2036
2185
|
class CommandResponseMiddleware {
|
|
2037
2186
|
constructor(handlers) {
|
|
2038
2187
|
this.commandHandlers = [];
|
|
@@ -2064,6 +2213,7 @@ class CommandResponseMiddleware {
|
|
|
2064
2213
|
yield context.sendActivity(replyActivity);
|
|
2065
2214
|
}
|
|
2066
2215
|
}
|
|
2216
|
+
break;
|
|
2067
2217
|
}
|
|
2068
2218
|
}
|
|
2069
2219
|
}
|
|
@@ -2145,6 +2295,134 @@ class CommandBot {
|
|
|
2145
2295
|
}
|
|
2146
2296
|
}
|
|
2147
2297
|
|
|
2298
|
+
// Copyright (c) Microsoft Corporation.
|
|
2299
|
+
/**
|
|
2300
|
+
* @internal
|
|
2301
|
+
*/
|
|
2302
|
+
function cloneConversation(conversation) {
|
|
2303
|
+
return JSON.parse(JSON.stringify(conversation));
|
|
2304
|
+
}
|
|
2305
|
+
/**
|
|
2306
|
+
* @internal
|
|
2307
|
+
*/
|
|
2308
|
+
function getTargetType(conversationReference) {
|
|
2309
|
+
var _a;
|
|
2310
|
+
const conversationType = (_a = conversationReference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
|
|
2311
|
+
if (conversationType === "personal") {
|
|
2312
|
+
return exports.NotificationTargetType.Person;
|
|
2313
|
+
}
|
|
2314
|
+
else if (conversationType === "groupChat") {
|
|
2315
|
+
return exports.NotificationTargetType.Group;
|
|
2316
|
+
}
|
|
2317
|
+
else if (conversationType === "channel") {
|
|
2318
|
+
return exports.NotificationTargetType.Channel;
|
|
2319
|
+
}
|
|
2320
|
+
else {
|
|
2321
|
+
return undefined;
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
/**
|
|
2325
|
+
* @internal
|
|
2326
|
+
*/
|
|
2327
|
+
function getTeamsBotInstallationId(context) {
|
|
2328
|
+
var _a, _b, _c, _d;
|
|
2329
|
+
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;
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
// Copyright (c) Microsoft Corporation.
|
|
2333
|
+
/**
|
|
2334
|
+
* @internal
|
|
2335
|
+
*/
|
|
2336
|
+
var ActivityType;
|
|
2337
|
+
(function (ActivityType) {
|
|
2338
|
+
ActivityType[ActivityType["CurrentBotInstalled"] = 0] = "CurrentBotInstalled";
|
|
2339
|
+
ActivityType[ActivityType["CurrentBotMessaged"] = 1] = "CurrentBotMessaged";
|
|
2340
|
+
ActivityType[ActivityType["CurrentBotUninstalled"] = 2] = "CurrentBotUninstalled";
|
|
2341
|
+
ActivityType[ActivityType["TeamDeleted"] = 3] = "TeamDeleted";
|
|
2342
|
+
ActivityType[ActivityType["TeamRestored"] = 4] = "TeamRestored";
|
|
2343
|
+
ActivityType[ActivityType["Unknown"] = 5] = "Unknown";
|
|
2344
|
+
})(ActivityType || (ActivityType = {}));
|
|
2345
|
+
/**
|
|
2346
|
+
* @internal
|
|
2347
|
+
*/
|
|
2348
|
+
class NotificationMiddleware {
|
|
2349
|
+
constructor(options) {
|
|
2350
|
+
this.conversationReferenceStore = options.conversationReferenceStore;
|
|
2351
|
+
}
|
|
2352
|
+
onTurn(context, next) {
|
|
2353
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
2354
|
+
const type = this.classifyActivity(context.activity);
|
|
2355
|
+
switch (type) {
|
|
2356
|
+
case ActivityType.CurrentBotInstalled:
|
|
2357
|
+
case ActivityType.TeamRestored: {
|
|
2358
|
+
const reference = botbuilder.TurnContext.getConversationReference(context.activity);
|
|
2359
|
+
yield this.conversationReferenceStore.set(reference);
|
|
2360
|
+
break;
|
|
2361
|
+
}
|
|
2362
|
+
case ActivityType.CurrentBotMessaged: {
|
|
2363
|
+
yield this.tryAddMessagedReference(context);
|
|
2364
|
+
break;
|
|
2365
|
+
}
|
|
2366
|
+
case ActivityType.CurrentBotUninstalled:
|
|
2367
|
+
case ActivityType.TeamDeleted: {
|
|
2368
|
+
const reference = botbuilder.TurnContext.getConversationReference(context.activity);
|
|
2369
|
+
yield this.conversationReferenceStore.delete(reference);
|
|
2370
|
+
break;
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
yield next();
|
|
2374
|
+
});
|
|
2375
|
+
}
|
|
2376
|
+
classifyActivity(activity) {
|
|
2377
|
+
var _a, _b;
|
|
2378
|
+
const activityType = activity.type;
|
|
2379
|
+
if (activityType === "installationUpdate") {
|
|
2380
|
+
const action = (_a = activity.action) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
2381
|
+
if (action === "add") {
|
|
2382
|
+
return ActivityType.CurrentBotInstalled;
|
|
2383
|
+
}
|
|
2384
|
+
else {
|
|
2385
|
+
return ActivityType.CurrentBotUninstalled;
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
else if (activityType === "conversationUpdate") {
|
|
2389
|
+
const eventType = (_b = activity.channelData) === null || _b === void 0 ? void 0 : _b.eventType;
|
|
2390
|
+
if (eventType === "teamDeleted") {
|
|
2391
|
+
return ActivityType.TeamDeleted;
|
|
2392
|
+
}
|
|
2393
|
+
else if (eventType === "teamRestored") {
|
|
2394
|
+
return ActivityType.TeamRestored;
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
else if (activityType === "message") {
|
|
2398
|
+
return ActivityType.CurrentBotMessaged;
|
|
2399
|
+
}
|
|
2400
|
+
return ActivityType.Unknown;
|
|
2401
|
+
}
|
|
2402
|
+
tryAddMessagedReference(context) {
|
|
2403
|
+
var _a, _b, _c, _d;
|
|
2404
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
2405
|
+
const reference = botbuilder.TurnContext.getConversationReference(context.activity);
|
|
2406
|
+
const conversationType = (_a = reference === null || reference === void 0 ? void 0 : reference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
|
|
2407
|
+
if (conversationType === "personal" || conversationType === "groupChat") {
|
|
2408
|
+
if (!(yield this.conversationReferenceStore.check(reference))) {
|
|
2409
|
+
yield this.conversationReferenceStore.set(reference);
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
else if (conversationType === "channel") {
|
|
2413
|
+
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;
|
|
2414
|
+
if (teamId !== undefined) {
|
|
2415
|
+
const teamReference = cloneConversation(reference);
|
|
2416
|
+
teamReference.conversation.id = teamId;
|
|
2417
|
+
if (!(yield this.conversationReferenceStore.check(teamReference))) {
|
|
2418
|
+
yield this.conversationReferenceStore.set(teamReference);
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
});
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2148
2426
|
// Copyright (c) Microsoft Corporation.
|
|
2149
2427
|
/**
|
|
2150
2428
|
* @internal
|
|
@@ -2682,7 +2960,7 @@ class ConversationBot {
|
|
|
2682
2960
|
* @param options - initialize options
|
|
2683
2961
|
*/
|
|
2684
2962
|
constructor(options) {
|
|
2685
|
-
var _a, _b;
|
|
2963
|
+
var _a, _b, _c;
|
|
2686
2964
|
if (options.adapter) {
|
|
2687
2965
|
this.adapter = options.adapter;
|
|
2688
2966
|
}
|
|
@@ -2695,6 +2973,9 @@ class ConversationBot {
|
|
|
2695
2973
|
if ((_b = options.notification) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
2696
2974
|
this.notification = new NotificationBot(this.adapter, options.notification);
|
|
2697
2975
|
}
|
|
2976
|
+
if ((_c = options.cardAction) === null || _c === void 0 ? void 0 : _c.enabled) {
|
|
2977
|
+
this.cardAction = new CardActionBot(this.adapter, options.cardAction);
|
|
2978
|
+
}
|
|
2698
2979
|
}
|
|
2699
2980
|
createDefaultAdapter(adapterConfig) {
|
|
2700
2981
|
const adapter = adapterConfig === undefined
|
|
@@ -2887,11 +3168,13 @@ exports.ApiKeyProvider = ApiKeyProvider;
|
|
|
2887
3168
|
exports.AppCredential = AppCredential;
|
|
2888
3169
|
exports.BasicAuthProvider = BasicAuthProvider;
|
|
2889
3170
|
exports.BearerTokenAuthProvider = BearerTokenAuthProvider;
|
|
3171
|
+
exports.CardActionBot = CardActionBot;
|
|
2890
3172
|
exports.CertificateAuthProvider = CertificateAuthProvider;
|
|
2891
3173
|
exports.Channel = Channel;
|
|
2892
3174
|
exports.CommandBot = CommandBot;
|
|
2893
3175
|
exports.ConversationBot = ConversationBot;
|
|
2894
3176
|
exports.ErrorWithCode = ErrorWithCode;
|
|
3177
|
+
exports.InvokeResponseFactory = InvokeResponseFactory;
|
|
2895
3178
|
exports.Member = Member;
|
|
2896
3179
|
exports.MessageBuilder = MessageBuilder;
|
|
2897
3180
|
exports.MsGraphAuthProvider = MsGraphAuthProvider;
|