@microsoft/teamsfx 1.1.2-alpha.062e4a5ea.0 → 1.1.2-alpha.a639d9f2e.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.esm2017.mjs
CHANGED
|
@@ -1838,131 +1838,280 @@ var NotificationTargetType;
|
|
|
1838
1838
|
* The notification will be sent to a personal chat.
|
|
1839
1839
|
*/
|
|
1840
1840
|
NotificationTargetType["Person"] = "Person";
|
|
1841
|
-
})(NotificationTargetType || (NotificationTargetType = {}));
|
|
1841
|
+
})(NotificationTargetType || (NotificationTargetType = {}));
|
|
1842
|
+
/**
|
|
1843
|
+
* Options used to control how the response card will be sent to users.
|
|
1844
|
+
*/
|
|
1845
|
+
var AdaptiveCardResponse;
|
|
1846
|
+
(function (AdaptiveCardResponse) {
|
|
1847
|
+
/**
|
|
1848
|
+
* The response card will be replaced the current one for the interactor who trigger the action.
|
|
1849
|
+
*/
|
|
1850
|
+
AdaptiveCardResponse[AdaptiveCardResponse["ReplaceForInteractor"] = 0] = "ReplaceForInteractor";
|
|
1851
|
+
/**
|
|
1852
|
+
* The response card will be replaced the current one for all users in the chat.
|
|
1853
|
+
*/
|
|
1854
|
+
AdaptiveCardResponse[AdaptiveCardResponse["ReplaceForAll"] = 1] = "ReplaceForAll";
|
|
1855
|
+
/**
|
|
1856
|
+
* The response card will be sent as a new message for all users in the chat.
|
|
1857
|
+
*/
|
|
1858
|
+
AdaptiveCardResponse[AdaptiveCardResponse["NewForAll"] = 2] = "NewForAll";
|
|
1859
|
+
})(AdaptiveCardResponse || (AdaptiveCardResponse = {}));
|
|
1860
|
+
/**
|
|
1861
|
+
* Status code for an `application/vnd.microsoft.error` invoke response.
|
|
1862
|
+
*/
|
|
1863
|
+
var InvokeResponseErrorCode;
|
|
1864
|
+
(function (InvokeResponseErrorCode) {
|
|
1865
|
+
/**
|
|
1866
|
+
* Invalid request.
|
|
1867
|
+
*/
|
|
1868
|
+
InvokeResponseErrorCode[InvokeResponseErrorCode["BadRequest"] = 400] = "BadRequest";
|
|
1869
|
+
/**
|
|
1870
|
+
* Internal server error.
|
|
1871
|
+
*/
|
|
1872
|
+
InvokeResponseErrorCode[InvokeResponseErrorCode["InternalServerError"] = 500] = "InternalServerError";
|
|
1873
|
+
})(InvokeResponseErrorCode || (InvokeResponseErrorCode = {}));
|
|
1842
1874
|
|
|
1843
|
-
// Copyright (c) Microsoft Corporation.
|
|
1844
1875
|
/**
|
|
1876
|
+
* Available response type for an adaptive card invoke response.
|
|
1845
1877
|
* @internal
|
|
1846
1878
|
*/
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1879
|
+
var InvokeResponseType;
|
|
1880
|
+
(function (InvokeResponseType) {
|
|
1881
|
+
InvokeResponseType["AdaptiveCard"] = "application/vnd.microsoft.card.adaptive";
|
|
1882
|
+
InvokeResponseType["Message"] = "application/vnd.microsoft.activity.message";
|
|
1883
|
+
InvokeResponseType["Error"] = "application/vnd.microsoft.error";
|
|
1884
|
+
})(InvokeResponseType || (InvokeResponseType = {}));
|
|
1850
1885
|
/**
|
|
1851
|
-
*
|
|
1886
|
+
* Provides methods for formatting various invoke responses a bot can send to respond to an invoke request.
|
|
1887
|
+
*
|
|
1888
|
+
* @remarks
|
|
1889
|
+
* All of these functions return an {@link InvokeResponse} object, which can be
|
|
1890
|
+
* passed as input to generate a new `invokeResponse` activity.
|
|
1891
|
+
*
|
|
1892
|
+
* This example sends an invoke response that contains an adaptive card.
|
|
1893
|
+
*
|
|
1894
|
+
* ```typescript
|
|
1895
|
+
*
|
|
1896
|
+
* const myCard: IAdaptiveCard = {
|
|
1897
|
+
* type: "AdaptiveCard",
|
|
1898
|
+
* body: [
|
|
1899
|
+
* {
|
|
1900
|
+
* "type": "TextBlock",
|
|
1901
|
+
* "text": "This is a sample card"
|
|
1902
|
+
* }],
|
|
1903
|
+
* $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
|
|
1904
|
+
* version: "1.4"
|
|
1905
|
+
* };
|
|
1906
|
+
*
|
|
1907
|
+
* const invokeResponse = InvokeResponseFactory.adaptiveCard(myCard);
|
|
1908
|
+
* await context.sendActivity({
|
|
1909
|
+
* type: ActivityTypes.InvokeResponse,
|
|
1910
|
+
* value: invokeResponse,
|
|
1911
|
+
* });
|
|
1912
|
+
* ```
|
|
1852
1913
|
*/
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1914
|
+
class InvokeResponseFactory {
|
|
1915
|
+
/**
|
|
1916
|
+
* Create an invoke response from a text message.
|
|
1917
|
+
* The type of the invoke response is `application/vnd.microsoft.activity.message`
|
|
1918
|
+
* indicates the request was successfully processed.
|
|
1919
|
+
*
|
|
1920
|
+
* @param message A text message included in a invoke response.
|
|
1921
|
+
*
|
|
1922
|
+
* @returns {InvokeResponse} An InvokeResponse object.
|
|
1923
|
+
*/
|
|
1924
|
+
static textMessage(message) {
|
|
1925
|
+
if (!message) {
|
|
1926
|
+
throw new Error("The text message cannot be null or empty");
|
|
1927
|
+
}
|
|
1928
|
+
return {
|
|
1929
|
+
status: StatusCodes.OK,
|
|
1930
|
+
body: {
|
|
1931
|
+
statusCode: StatusCodes.OK,
|
|
1932
|
+
type: InvokeResponseType.Message,
|
|
1933
|
+
value: message,
|
|
1934
|
+
},
|
|
1935
|
+
};
|
|
1858
1936
|
}
|
|
1859
|
-
|
|
1860
|
-
|
|
1937
|
+
/**
|
|
1938
|
+
* Create an invoke response from an adaptive card.
|
|
1939
|
+
*
|
|
1940
|
+
* The type of the invoke response is `application/vnd.microsoft.card.adaptive` indicates
|
|
1941
|
+
* the request was successfully processed, and the response includes an adaptive card
|
|
1942
|
+
* that the client should display in place of the current one.
|
|
1943
|
+
*
|
|
1944
|
+
* @param card The adaptive card JSON payload.
|
|
1945
|
+
*
|
|
1946
|
+
* @returns {InvokeResponse} An InvokeResponse object.
|
|
1947
|
+
*/
|
|
1948
|
+
static adaptiveCard(card) {
|
|
1949
|
+
if (!card) {
|
|
1950
|
+
throw new Error("The adaptive card content cannot be null or undefined");
|
|
1951
|
+
}
|
|
1952
|
+
return {
|
|
1953
|
+
status: StatusCodes.OK,
|
|
1954
|
+
body: {
|
|
1955
|
+
statusCode: StatusCodes.OK,
|
|
1956
|
+
type: InvokeResponseType.AdaptiveCard,
|
|
1957
|
+
value: card,
|
|
1958
|
+
},
|
|
1959
|
+
};
|
|
1861
1960
|
}
|
|
1862
|
-
|
|
1863
|
-
|
|
1961
|
+
/**
|
|
1962
|
+
* Create an invoke response with error code and message.
|
|
1963
|
+
*
|
|
1964
|
+
* The type of the invoke response is `application/vnd.microsoft.error` indicates
|
|
1965
|
+
* the request was failed to processed.
|
|
1966
|
+
*
|
|
1967
|
+
* @param errorCode The status code indicates error, available values:
|
|
1968
|
+
* - 400 (BadRequest): indicate the incoming request was invalid.
|
|
1969
|
+
* - 500 (InternalServerError): indicate an unexpected error occurred.
|
|
1970
|
+
* @param errorMessage The error message.
|
|
1971
|
+
*
|
|
1972
|
+
* @returns {InvokeResponse} An InvokeResponse object.
|
|
1973
|
+
*/
|
|
1974
|
+
static errorResponse(errorCode, errorMessage) {
|
|
1975
|
+
return {
|
|
1976
|
+
status: StatusCodes.OK,
|
|
1977
|
+
body: {
|
|
1978
|
+
statusCode: errorCode,
|
|
1979
|
+
type: InvokeResponseType.Error,
|
|
1980
|
+
value: {
|
|
1981
|
+
code: errorCode.toString(),
|
|
1982
|
+
message: errorMessage,
|
|
1983
|
+
},
|
|
1984
|
+
},
|
|
1985
|
+
};
|
|
1864
1986
|
}
|
|
1865
|
-
|
|
1866
|
-
|
|
1987
|
+
/**
|
|
1988
|
+
* Create an invoke response with status code and response value.
|
|
1989
|
+
* @param statusCode The status code.
|
|
1990
|
+
* @param body The value of the response body.
|
|
1991
|
+
*
|
|
1992
|
+
* @returns {InvokeResponse} An InvokeResponse object.
|
|
1993
|
+
*/
|
|
1994
|
+
static createInvokeResponse(statusCode, body) {
|
|
1995
|
+
return {
|
|
1996
|
+
status: statusCode,
|
|
1997
|
+
body: body,
|
|
1998
|
+
};
|
|
1867
1999
|
}
|
|
1868
|
-
}
|
|
1869
|
-
/**
|
|
1870
|
-
* @internal
|
|
1871
|
-
*/
|
|
1872
|
-
function getTeamsBotInstallationId(context) {
|
|
1873
|
-
var _a, _b, _c, _d;
|
|
1874
|
-
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;
|
|
1875
2000
|
}
|
|
1876
2001
|
|
|
1877
|
-
// Copyright (c) Microsoft Corporation.
|
|
1878
2002
|
/**
|
|
1879
2003
|
* @internal
|
|
1880
2004
|
*/
|
|
1881
|
-
|
|
1882
|
-
(
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
ActivityType[ActivityType["Unknown"] = 5] = "Unknown";
|
|
1889
|
-
})(ActivityType || (ActivityType = {}));
|
|
1890
|
-
/**
|
|
1891
|
-
* @internal
|
|
1892
|
-
*/
|
|
1893
|
-
class NotificationMiddleware {
|
|
1894
|
-
constructor(options) {
|
|
1895
|
-
this.conversationReferenceStore = options.conversationReferenceStore;
|
|
2005
|
+
class CardActionMiddleware {
|
|
2006
|
+
constructor(handlers) {
|
|
2007
|
+
this.actionHandlers = [];
|
|
2008
|
+
this.defaultMessage = "Your response was sent to the app";
|
|
2009
|
+
if (handlers && handlers.length > 0) {
|
|
2010
|
+
this.actionHandlers.push(...handlers);
|
|
2011
|
+
}
|
|
1896
2012
|
}
|
|
1897
2013
|
async onTurn(context, next) {
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
2014
|
+
var _a, _b, _c;
|
|
2015
|
+
if (context.activity.name === "adaptiveCard/action") {
|
|
2016
|
+
const action = context.activity.value.action;
|
|
2017
|
+
const actionVerb = action.verb;
|
|
2018
|
+
for (const handler of this.actionHandlers) {
|
|
2019
|
+
if (((_a = handler.triggerVerb) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === (actionVerb === null || actionVerb === void 0 ? void 0 : actionVerb.toLowerCase())) {
|
|
2020
|
+
let response;
|
|
2021
|
+
try {
|
|
2022
|
+
response = await handler.handleActionInvoked(context, action.data);
|
|
2023
|
+
}
|
|
2024
|
+
catch (error) {
|
|
2025
|
+
const errorResponse = InvokeResponseFactory.errorResponse(InvokeResponseErrorCode.InternalServerError, error.message);
|
|
2026
|
+
await this.sendInvokeResponse(context, errorResponse);
|
|
2027
|
+
throw error;
|
|
2028
|
+
}
|
|
2029
|
+
const responseType = (_b = response.body) === null || _b === void 0 ? void 0 : _b.type;
|
|
2030
|
+
switch (responseType) {
|
|
2031
|
+
case InvokeResponseType.AdaptiveCard:
|
|
2032
|
+
const card = (_c = response.body) === null || _c === void 0 ? void 0 : _c.value;
|
|
2033
|
+
if (!card) {
|
|
2034
|
+
const errorMessage = "Adaptive card content cannot be found in the response body";
|
|
2035
|
+
await this.sendInvokeResponse(context, InvokeResponseFactory.errorResponse(InvokeResponseErrorCode.InternalServerError, errorMessage));
|
|
2036
|
+
throw new Error(errorMessage);
|
|
2037
|
+
}
|
|
2038
|
+
if (card.refresh && handler.adaptiveCardResponse !== AdaptiveCardResponse.NewForAll) {
|
|
2039
|
+
// Card won't be refreshed with AdaptiveCardResponse.ReplaceForInteractor.
|
|
2040
|
+
// So set to AdaptiveCardResponse.ReplaceForAll here.
|
|
2041
|
+
handler.adaptiveCardResponse = AdaptiveCardResponse.ReplaceForAll;
|
|
2042
|
+
}
|
|
2043
|
+
const activity = MessageFactory.attachment(CardFactory.adaptiveCard(card));
|
|
2044
|
+
if (handler.adaptiveCardResponse === AdaptiveCardResponse.NewForAll) {
|
|
2045
|
+
await this.sendInvokeResponse(context, InvokeResponseFactory.textMessage(this.defaultMessage));
|
|
2046
|
+
await context.sendActivity(activity);
|
|
2047
|
+
}
|
|
2048
|
+
else if (handler.adaptiveCardResponse === AdaptiveCardResponse.ReplaceForAll) {
|
|
2049
|
+
activity.id = context.activity.replyToId;
|
|
2050
|
+
await context.updateActivity(activity);
|
|
2051
|
+
await this.sendInvokeResponse(context, response);
|
|
2052
|
+
}
|
|
2053
|
+
else {
|
|
2054
|
+
await this.sendInvokeResponse(context, response);
|
|
2055
|
+
}
|
|
2056
|
+
break;
|
|
2057
|
+
case InvokeResponseType.Message:
|
|
2058
|
+
case InvokeResponseType.Error:
|
|
2059
|
+
default:
|
|
2060
|
+
await this.sendInvokeResponse(context, response);
|
|
2061
|
+
break;
|
|
2062
|
+
}
|
|
2063
|
+
break;
|
|
2064
|
+
}
|
|
1915
2065
|
}
|
|
1916
2066
|
}
|
|
1917
2067
|
await next();
|
|
1918
2068
|
}
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
if (action === "add") {
|
|
1925
|
-
return ActivityType.CurrentBotInstalled;
|
|
1926
|
-
}
|
|
1927
|
-
else {
|
|
1928
|
-
return ActivityType.CurrentBotUninstalled;
|
|
1929
|
-
}
|
|
1930
|
-
}
|
|
1931
|
-
else if (activityType === "conversationUpdate") {
|
|
1932
|
-
const eventType = (_b = activity.channelData) === null || _b === void 0 ? void 0 : _b.eventType;
|
|
1933
|
-
if (eventType === "teamDeleted") {
|
|
1934
|
-
return ActivityType.TeamDeleted;
|
|
1935
|
-
}
|
|
1936
|
-
else if (eventType === "teamRestored") {
|
|
1937
|
-
return ActivityType.TeamRestored;
|
|
1938
|
-
}
|
|
1939
|
-
}
|
|
1940
|
-
else if (activityType === "message") {
|
|
1941
|
-
return ActivityType.CurrentBotMessaged;
|
|
1942
|
-
}
|
|
1943
|
-
return ActivityType.Unknown;
|
|
2069
|
+
async sendInvokeResponse(context, response) {
|
|
2070
|
+
await context.sendActivity({
|
|
2071
|
+
type: ActivityTypes.InvokeResponse,
|
|
2072
|
+
value: response,
|
|
2073
|
+
});
|
|
1944
2074
|
}
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
/**
|
|
2078
|
+
* A card action bot to respond to adaptive card universal actions.
|
|
2079
|
+
*/
|
|
2080
|
+
class CardActionBot {
|
|
2081
|
+
/**
|
|
2082
|
+
* Creates a new instance of the `CardActionBot`.
|
|
2083
|
+
*
|
|
2084
|
+
* @param adapter The bound `BotFrameworkAdapter`.
|
|
2085
|
+
* @param options - initialize options
|
|
2086
|
+
*/
|
|
2087
|
+
constructor(adapter, options) {
|
|
2088
|
+
this.middleware = new CardActionMiddleware(options === null || options === void 0 ? void 0 : options.actions);
|
|
2089
|
+
this.adapter = adapter.use(this.middleware);
|
|
2090
|
+
}
|
|
2091
|
+
/**
|
|
2092
|
+
* Registers a card action handler to the bot.
|
|
2093
|
+
* @param actionHandler A card action handler to be registered.
|
|
2094
|
+
*/
|
|
2095
|
+
registerHandler(actionHandler) {
|
|
2096
|
+
if (actionHandler) {
|
|
2097
|
+
this.middleware.actionHandlers.push(actionHandler);
|
|
1953
2098
|
}
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
}
|
|
2099
|
+
}
|
|
2100
|
+
/**
|
|
2101
|
+
* Registers card action handlers to the bot.
|
|
2102
|
+
* @param actionHandlers A set of card action handlers to be registered.
|
|
2103
|
+
*/
|
|
2104
|
+
registerHandlers(actionHandlers) {
|
|
2105
|
+
if (actionHandlers) {
|
|
2106
|
+
this.middleware.actionHandlers.push(...actionHandlers);
|
|
1963
2107
|
}
|
|
1964
2108
|
}
|
|
1965
|
-
}
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
// Copyright (c) Microsoft Corporation.
|
|
2112
|
+
/**
|
|
2113
|
+
* @internal
|
|
2114
|
+
*/
|
|
1966
2115
|
class CommandResponseMiddleware {
|
|
1967
2116
|
constructor(handlers) {
|
|
1968
2117
|
this.commandHandlers = [];
|
|
@@ -1993,6 +2142,7 @@ class CommandResponseMiddleware {
|
|
|
1993
2142
|
await context.sendActivity(replyActivity);
|
|
1994
2143
|
}
|
|
1995
2144
|
}
|
|
2145
|
+
break;
|
|
1996
2146
|
}
|
|
1997
2147
|
}
|
|
1998
2148
|
}
|
|
@@ -2073,6 +2223,130 @@ class CommandBot {
|
|
|
2073
2223
|
}
|
|
2074
2224
|
}
|
|
2075
2225
|
|
|
2226
|
+
// Copyright (c) Microsoft Corporation.
|
|
2227
|
+
/**
|
|
2228
|
+
* @internal
|
|
2229
|
+
*/
|
|
2230
|
+
function cloneConversation(conversation) {
|
|
2231
|
+
return JSON.parse(JSON.stringify(conversation));
|
|
2232
|
+
}
|
|
2233
|
+
/**
|
|
2234
|
+
* @internal
|
|
2235
|
+
*/
|
|
2236
|
+
function getTargetType(conversationReference) {
|
|
2237
|
+
var _a;
|
|
2238
|
+
const conversationType = (_a = conversationReference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
|
|
2239
|
+
if (conversationType === "personal") {
|
|
2240
|
+
return NotificationTargetType.Person;
|
|
2241
|
+
}
|
|
2242
|
+
else if (conversationType === "groupChat") {
|
|
2243
|
+
return NotificationTargetType.Group;
|
|
2244
|
+
}
|
|
2245
|
+
else if (conversationType === "channel") {
|
|
2246
|
+
return NotificationTargetType.Channel;
|
|
2247
|
+
}
|
|
2248
|
+
else {
|
|
2249
|
+
return undefined;
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
/**
|
|
2253
|
+
* @internal
|
|
2254
|
+
*/
|
|
2255
|
+
function getTeamsBotInstallationId(context) {
|
|
2256
|
+
var _a, _b, _c, _d;
|
|
2257
|
+
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;
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
// Copyright (c) Microsoft Corporation.
|
|
2261
|
+
/**
|
|
2262
|
+
* @internal
|
|
2263
|
+
*/
|
|
2264
|
+
var ActivityType;
|
|
2265
|
+
(function (ActivityType) {
|
|
2266
|
+
ActivityType[ActivityType["CurrentBotInstalled"] = 0] = "CurrentBotInstalled";
|
|
2267
|
+
ActivityType[ActivityType["CurrentBotMessaged"] = 1] = "CurrentBotMessaged";
|
|
2268
|
+
ActivityType[ActivityType["CurrentBotUninstalled"] = 2] = "CurrentBotUninstalled";
|
|
2269
|
+
ActivityType[ActivityType["TeamDeleted"] = 3] = "TeamDeleted";
|
|
2270
|
+
ActivityType[ActivityType["TeamRestored"] = 4] = "TeamRestored";
|
|
2271
|
+
ActivityType[ActivityType["Unknown"] = 5] = "Unknown";
|
|
2272
|
+
})(ActivityType || (ActivityType = {}));
|
|
2273
|
+
/**
|
|
2274
|
+
* @internal
|
|
2275
|
+
*/
|
|
2276
|
+
class NotificationMiddleware {
|
|
2277
|
+
constructor(options) {
|
|
2278
|
+
this.conversationReferenceStore = options.conversationReferenceStore;
|
|
2279
|
+
}
|
|
2280
|
+
async onTurn(context, next) {
|
|
2281
|
+
const type = this.classifyActivity(context.activity);
|
|
2282
|
+
switch (type) {
|
|
2283
|
+
case ActivityType.CurrentBotInstalled:
|
|
2284
|
+
case ActivityType.TeamRestored: {
|
|
2285
|
+
const reference = TurnContext.getConversationReference(context.activity);
|
|
2286
|
+
await this.conversationReferenceStore.set(reference);
|
|
2287
|
+
break;
|
|
2288
|
+
}
|
|
2289
|
+
case ActivityType.CurrentBotMessaged: {
|
|
2290
|
+
await this.tryAddMessagedReference(context);
|
|
2291
|
+
break;
|
|
2292
|
+
}
|
|
2293
|
+
case ActivityType.CurrentBotUninstalled:
|
|
2294
|
+
case ActivityType.TeamDeleted: {
|
|
2295
|
+
const reference = TurnContext.getConversationReference(context.activity);
|
|
2296
|
+
await this.conversationReferenceStore.delete(reference);
|
|
2297
|
+
break;
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
await next();
|
|
2301
|
+
}
|
|
2302
|
+
classifyActivity(activity) {
|
|
2303
|
+
var _a, _b;
|
|
2304
|
+
const activityType = activity.type;
|
|
2305
|
+
if (activityType === "installationUpdate") {
|
|
2306
|
+
const action = (_a = activity.action) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
2307
|
+
if (action === "add") {
|
|
2308
|
+
return ActivityType.CurrentBotInstalled;
|
|
2309
|
+
}
|
|
2310
|
+
else {
|
|
2311
|
+
return ActivityType.CurrentBotUninstalled;
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
else if (activityType === "conversationUpdate") {
|
|
2315
|
+
const eventType = (_b = activity.channelData) === null || _b === void 0 ? void 0 : _b.eventType;
|
|
2316
|
+
if (eventType === "teamDeleted") {
|
|
2317
|
+
return ActivityType.TeamDeleted;
|
|
2318
|
+
}
|
|
2319
|
+
else if (eventType === "teamRestored") {
|
|
2320
|
+
return ActivityType.TeamRestored;
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
else if (activityType === "message") {
|
|
2324
|
+
return ActivityType.CurrentBotMessaged;
|
|
2325
|
+
}
|
|
2326
|
+
return ActivityType.Unknown;
|
|
2327
|
+
}
|
|
2328
|
+
async tryAddMessagedReference(context) {
|
|
2329
|
+
var _a, _b, _c, _d;
|
|
2330
|
+
const reference = TurnContext.getConversationReference(context.activity);
|
|
2331
|
+
const conversationType = (_a = reference === null || reference === void 0 ? void 0 : reference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
|
|
2332
|
+
if (conversationType === "personal" || conversationType === "groupChat") {
|
|
2333
|
+
if (!(await this.conversationReferenceStore.check(reference))) {
|
|
2334
|
+
await this.conversationReferenceStore.set(reference);
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
else if (conversationType === "channel") {
|
|
2338
|
+
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;
|
|
2339
|
+
if (teamId !== undefined) {
|
|
2340
|
+
const teamReference = cloneConversation(reference);
|
|
2341
|
+
teamReference.conversation.id = teamId;
|
|
2342
|
+
if (!(await this.conversationReferenceStore.check(teamReference))) {
|
|
2343
|
+
await this.conversationReferenceStore.set(teamReference);
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2076
2350
|
// Copyright (c) Microsoft Corporation.
|
|
2077
2351
|
/**
|
|
2078
2352
|
* @internal
|
|
@@ -2576,7 +2850,7 @@ class ConversationBot {
|
|
|
2576
2850
|
* @param options - initialize options
|
|
2577
2851
|
*/
|
|
2578
2852
|
constructor(options) {
|
|
2579
|
-
var _a, _b;
|
|
2853
|
+
var _a, _b, _c;
|
|
2580
2854
|
if (options.adapter) {
|
|
2581
2855
|
this.adapter = options.adapter;
|
|
2582
2856
|
}
|
|
@@ -2589,6 +2863,9 @@ class ConversationBot {
|
|
|
2589
2863
|
if ((_b = options.notification) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
2590
2864
|
this.notification = new NotificationBot(this.adapter, options.notification);
|
|
2591
2865
|
}
|
|
2866
|
+
if ((_c = options.cardAction) === null || _c === void 0 ? void 0 : _c.enabled) {
|
|
2867
|
+
this.cardAction = new CardActionBot(this.adapter, options.cardAction);
|
|
2868
|
+
}
|
|
2592
2869
|
}
|
|
2593
2870
|
createDefaultAdapter(adapterConfig) {
|
|
2594
2871
|
const adapter = adapterConfig === undefined
|
|
@@ -2775,5 +3052,5 @@ class MessageBuilder {
|
|
|
2775
3052
|
}
|
|
2776
3053
|
}
|
|
2777
3054
|
|
|
2778
|
-
export { ApiKeyLocation, ApiKeyProvider, AppCredential, BasicAuthProvider, BearerTokenAuthProvider, CertificateAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, LogLevel, Member, MessageBuilder, MsGraphAuthProvider, NotificationBot, NotificationTargetType, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
|
|
3055
|
+
export { AdaptiveCardResponse, ApiKeyLocation, ApiKeyProvider, AppCredential, BasicAuthProvider, BearerTokenAuthProvider, CardActionBot, CertificateAuthProvider, Channel, CommandBot, ConversationBot, ErrorCode, ErrorWithCode, IdentityType, InvokeResponseErrorCode, InvokeResponseFactory, LogLevel, Member, MessageBuilder, MsGraphAuthProvider, NotificationBot, NotificationTargetType, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createApiClient, createMicrosoftGraphClient, createPemCertOption, createPfxCertOption, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
|
|
2779
3056
|
//# sourceMappingURL=index.esm2017.mjs.map
|