@botonic/core 0.55.1 → 0.57.0-rslib-esm.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/lib/esm/constants.js +7 -7
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/core-bot.d.ts +3 -3
- package/lib/esm/core-bot.js +87 -50
- package/lib/esm/core-bot.js.map +1 -1
- package/lib/esm/debug/index.d.ts +1 -1
- package/lib/esm/debug/index.js +5 -4
- package/lib/esm/debug/index.js.map +1 -1
- package/lib/esm/debug/inspector.d.ts +1 -1
- package/lib/esm/debug/inspector.js +27 -21
- package/lib/esm/debug/inspector.js.map +1 -1
- package/lib/esm/handoff.d.ts +1 -1
- package/lib/esm/handoff.js +82 -53
- package/lib/esm/handoff.js.map +1 -1
- package/lib/esm/hubtype-service.d.ts +3 -3
- package/lib/esm/hubtype-service.js +100 -64
- package/lib/esm/hubtype-service.js.map +1 -1
- package/lib/esm/index.d.ts +9 -9
- package/lib/esm/index.js +21 -12
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/models/ai-agents.js +15 -15
- package/lib/esm/models/ai-agents.js.map +1 -1
- package/lib/esm/models/bot-config.js +6 -6
- package/lib/esm/models/bot-config.js.map +1 -1
- package/lib/esm/models/hubtype-analytics.d.ts +1 -1
- package/lib/esm/models/hubtype-analytics.js +10 -10
- package/lib/esm/models/hubtype-analytics.js.map +1 -1
- package/lib/esm/models/index.d.ts +4 -4
- package/lib/esm/models/index.js +11 -7
- package/lib/esm/models/index.js.map +1 -1
- package/lib/esm/models/legacy-types.d.ts +3 -1
- package/lib/esm/models/legacy-types.js +25 -24
- package/lib/esm/models/legacy-types.js.map +1 -1
- package/lib/esm/package.json +3 -0
- package/lib/esm/plugins.d.ts +1 -1
- package/lib/esm/plugins.js +7 -8
- package/lib/esm/plugins.js.map +1 -1
- package/lib/esm/pusher-utils.js +15 -10
- package/lib/esm/pusher-utils.js.map +1 -1
- package/lib/esm/routing/index.d.ts +2 -2
- package/lib/esm/routing/index.js +7 -5
- package/lib/esm/routing/index.js.map +1 -1
- package/lib/esm/routing/router-utils.d.ts +1 -1
- package/lib/esm/routing/router-utils.js +37 -30
- package/lib/esm/routing/router-utils.js.map +1 -1
- package/lib/esm/routing/router.d.ts +2 -2
- package/lib/esm/routing/router.js +152 -149
- package/lib/esm/routing/router.js.map +1 -1
- package/lib/esm/testing/index.d.ts +1 -1
- package/lib/esm/testing/index.js +60 -94
- package/lib/esm/testing/index.js.map +1 -1
- package/lib/esm/utils/bot-config.d.ts +1 -1
- package/lib/esm/utils/bot-config.js +57 -28
- package/lib/esm/utils/bot-config.js.map +1 -1
- package/lib/esm/utils/check-providers.d.ts +1 -1
- package/lib/esm/utils/check-providers.js +14 -17
- package/lib/esm/utils/check-providers.js.map +1 -1
- package/lib/esm/utils/functional.js +19 -38
- package/lib/esm/utils/functional.js.map +1 -1
- package/lib/esm/utils/index.d.ts +3 -3
- package/lib/esm/utils/index.js +9 -6
- package/lib/esm/utils/index.js.map +1 -1
- package/package.json +12 -11
- package/src/hubtype-service.ts +4 -2
- package/src/models/legacy-types.ts +3 -0
- package/lib/cjs/constants.d.ts +0 -4
- package/lib/cjs/constants.js +0 -8
- package/lib/cjs/constants.js.map +0 -1
- package/lib/cjs/core-bot.d.ts +0 -43
- package/lib/cjs/core-bot.js +0 -205
- package/lib/cjs/core-bot.js.map +0 -1
- package/lib/cjs/debug/index.d.ts +0 -1
- package/lib/cjs/debug/index.js +0 -5
- package/lib/cjs/debug/index.js.map +0 -1
- package/lib/cjs/debug/inspector.d.ts +0 -24
- package/lib/cjs/debug/inspector.js +0 -70
- package/lib/cjs/debug/inspector.js.map +0 -1
- package/lib/cjs/handoff.d.ts +0 -110
- package/lib/cjs/handoff.js +0 -238
- package/lib/cjs/handoff.js.map +0 -1
- package/lib/cjs/hubtype-service.d.ts +0 -58
- package/lib/cjs/hubtype-service.js +0 -205
- package/lib/cjs/hubtype-service.js.map +0 -1
- package/lib/cjs/index.d.ts +0 -9
- package/lib/cjs/index.js +0 -13
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/models/ai-agents.d.ts +0 -140
- package/lib/cjs/models/ai-agents.js +0 -30
- package/lib/cjs/models/ai-agents.js.map +0 -1
- package/lib/cjs/models/bot-config.d.ts +0 -24
- package/lib/cjs/models/bot-config.js +0 -10
- package/lib/cjs/models/bot-config.js.map +0 -1
- package/lib/cjs/models/hubtype-analytics.d.ts +0 -210
- package/lib/cjs/models/hubtype-analytics.js +0 -38
- package/lib/cjs/models/hubtype-analytics.js.map +0 -1
- package/lib/cjs/models/index.d.ts +0 -4
- package/lib/cjs/models/index.js +0 -8
- package/lib/cjs/models/index.js.map +0 -1
- package/lib/cjs/models/legacy-types.d.ts +0 -330
- package/lib/cjs/models/legacy-types.js +0 -83
- package/lib/cjs/models/legacy-types.js.map +0 -1
- package/lib/cjs/plugins.d.ts +0 -9
- package/lib/cjs/plugins.js +0 -24
- package/lib/cjs/plugins.js.map +0 -1
- package/lib/cjs/pusher-utils.d.ts +0 -7
- package/lib/cjs/pusher-utils.js +0 -18
- package/lib/cjs/pusher-utils.js.map +0 -1
- package/lib/cjs/routing/index.d.ts +0 -2
- package/lib/cjs/routing/index.js +0 -6
- package/lib/cjs/routing/index.js.map +0 -1
- package/lib/cjs/routing/router-utils.d.ts +0 -11
- package/lib/cjs/routing/router-utils.js +0 -96
- package/lib/cjs/routing/router-utils.js.map +0 -1
- package/lib/cjs/routing/router.d.ts +0 -54
- package/lib/cjs/routing/router.js +0 -330
- package/lib/cjs/routing/router.js.map +0 -1
- package/lib/cjs/testing/index.d.ts +0 -91
- package/lib/cjs/testing/index.js +0 -196
- package/lib/cjs/testing/index.js.map +0 -1
- package/lib/cjs/utils/bot-config.d.ts +0 -4
- package/lib/cjs/utils/bot-config.js +0 -94
- package/lib/cjs/utils/bot-config.js.map +0 -1
- package/lib/cjs/utils/check-providers.d.ts +0 -8
- package/lib/cjs/utils/check-providers.js +0 -34
- package/lib/cjs/utils/check-providers.js.map +0 -1
- package/lib/cjs/utils/functional.d.ts +0 -10
- package/lib/cjs/utils/functional.js +0 -88
- package/lib/cjs/utils/functional.js.map +0 -1
- package/lib/cjs/utils/index.d.ts +0 -3
- package/lib/cjs/utils/index.js +0 -7
- package/lib/cjs/utils/index.js.map +0 -1
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NoMatchingRouteError = void 0;
|
|
4
|
-
exports.isPathPayload = isPathPayload;
|
|
5
|
-
exports.getPathParamsFromPathPayload = getPathParamsFromPathPayload;
|
|
6
|
-
exports.pathParamsToParams = pathParamsToParams;
|
|
7
|
-
exports.getEmptyAction = getEmptyAction;
|
|
8
|
-
exports.getNotFoundAction = getNotFoundAction;
|
|
9
|
-
exports.getComputedRoutes = getComputedRoutes;
|
|
10
|
-
const constants_1 = require("../constants");
|
|
11
|
-
class NoMatchingRouteError extends Error {
|
|
12
|
-
constructor(input) {
|
|
13
|
-
super(`No route found for input '${JSON.stringify(input)}' and no ${constants_1.NOT_FOUND_PATH} route defined`);
|
|
14
|
-
this.input = input;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.NoMatchingRouteError = NoMatchingRouteError;
|
|
18
|
-
function isPathPayload(payload) {
|
|
19
|
-
if (!payload) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
const isPathPayload = constants_1.PATH_PAYLOAD_REGEXP.exec(payload);
|
|
23
|
-
return Boolean(isPathPayload);
|
|
24
|
-
}
|
|
25
|
-
function getPathParamsFromPathPayload(payload) {
|
|
26
|
-
const defaultPathParams = {
|
|
27
|
-
path: null,
|
|
28
|
-
params: {},
|
|
29
|
-
};
|
|
30
|
-
if (!payload) {
|
|
31
|
-
return defaultPathParams;
|
|
32
|
-
}
|
|
33
|
-
if (!isPathPayload(payload)) {
|
|
34
|
-
return defaultPathParams;
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
const pathWithParams = payload.split(constants_1.PATH_PAYLOAD_IDENTIFIER)[1];
|
|
38
|
-
if (!pathWithParams) {
|
|
39
|
-
throw `${constants_1.PATH_PAYLOAD_IDENTIFIER} is empty`;
|
|
40
|
-
}
|
|
41
|
-
const [path, params] = pathWithParams.split('?');
|
|
42
|
-
return { path: path ?? null, params: pathParamsToParams(params) };
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
console.error('Error getting path and params from input.payload:', e);
|
|
46
|
-
return defaultPathParams;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function pathParamsToParams(pathParams) {
|
|
50
|
-
if (!pathParams) {
|
|
51
|
-
return {};
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
const params = {};
|
|
55
|
-
const searchParams = new URLSearchParams(pathParams);
|
|
56
|
-
for (const [key, value] of searchParams) {
|
|
57
|
-
params[key] = value;
|
|
58
|
-
}
|
|
59
|
-
return params;
|
|
60
|
-
}
|
|
61
|
-
catch (_e) {
|
|
62
|
-
return {};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function getEmptyAction(childRoutes) {
|
|
66
|
-
if (!childRoutes) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
const emptyActionRoute = childRoutes.find(r => r.path === constants_1.EMPTY_ACTION_PATH);
|
|
70
|
-
if (!emptyActionRoute) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
return emptyActionRoute.action;
|
|
74
|
-
}
|
|
75
|
-
function getNotFoundAction(input, routes) {
|
|
76
|
-
const notFoundActionRoute = routes.find(r => r.path === constants_1.NOT_FOUND_PATH);
|
|
77
|
-
if (!notFoundActionRoute) {
|
|
78
|
-
throw new NoMatchingRouteError(input);
|
|
79
|
-
}
|
|
80
|
-
return notFoundActionRoute.action;
|
|
81
|
-
}
|
|
82
|
-
async function getComputedRoutes(routes, botContext) {
|
|
83
|
-
if (routes instanceof Function) {
|
|
84
|
-
return await getComputedRoutes(await routes(botContext), botContext);
|
|
85
|
-
}
|
|
86
|
-
for (const [key, route] of Object.entries(routes)) {
|
|
87
|
-
if (route.childRoutes && route.childRoutes instanceof Function) {
|
|
88
|
-
routes[key].childRoutes = await getComputedRoutes(await route.childRoutes(botContext), botContext);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
routes[key] = route;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return routes;
|
|
95
|
-
}
|
|
96
|
-
//# sourceMappingURL=router-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router-utils.js","sourceRoot":"","sources":["../../../src/routing/router-utils.ts"],"names":[],"mappings":";;;AA4BA,sCAMC;AAED,oEAsBC;AAED,gDAcC;AAED,wCASC;AAED,8CAMC;AAED,8CAkBC;AAjHD,4CAKqB;AAWrB,MAAa,oBAAqB,SAAQ,KAAK;IAE7C,YAAY,KAAY;QACtB,KAAK,CACH,6BAA6B,IAAI,CAAC,SAAS,CACzC,KAAK,CACN,YAAY,0BAAc,gBAAgB,CAC5C,CAAA;QACD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;CACF;AAVD,oDAUC;AAED,SAAgB,aAAa,CAAC,OAAgB;IAC5C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,KAAK,CAAA;IACd,CAAC;IACD,MAAM,aAAa,GAAG,+BAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACvD,OAAO,OAAO,CAAC,aAAa,CAAC,CAAA;AAC/B,CAAC;AAED,SAAgB,4BAA4B,CAAC,OAAgB;IAC3D,MAAM,iBAAiB,GAAG;QACxB,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,EAAE;KACX,CAAA;IACD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,iBAAiB,CAAA;IAC1B,CAAC;IACD,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;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AAK,6BAAiB,CAAC,CAAA;IAC5E,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,gBAAgB,CAAC,MAAM,CAAA;AAChC,CAAC;AAED,SAAgB,iBAAiB,CAAC,KAAY,EAAE,MAAe;IAC7D,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,0BAAc,CAAC,CAAA;IACvE,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,MAAM,IAAI,oBAAoB,CAAC,KAAK,CAAC,CAAA;IACvC,CAAC;IACD,OAAO,mBAAmB,CAAC,MAAM,CAAA;AACnC,CAAC;AAEM,KAAK,UAAU,iBAAiB,CACrC,MAAc,EACd,UAAsB;IAEtB,IAAI,MAAM,YAAY,QAAQ,EAAE,CAAC;QAC/B,OAAO,MAAM,iBAAiB,CAAC,MAAM,MAAM,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAA;IACtE,CAAC;IACD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAQ,EAAE,CAAC;QACzD,IAAI,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,YAAY,QAAQ,EAAE,CAAC;YAC/D,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,GAAG,MAAM,iBAAiB,CAC/C,MAAM,KAAK,CAAC,WAAW,CAAC,UAAU,CAAC,EACnC,UAAU,CACX,CAAA;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QACrB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { RouteInspector } from '../debug/inspector';
|
|
2
|
-
import type { Input, MatchedValue, Matcher, MatchingProp, Nullable, ProcessInputResult, Route, RouteParams, RoutePath, RoutingState, Session } from '../models';
|
|
3
|
-
export declare class Router {
|
|
4
|
-
routes: Route[];
|
|
5
|
-
routeInspector: RouteInspector;
|
|
6
|
-
constructor(routes: Route[], routeInspector?: RouteInspector | undefined);
|
|
7
|
-
/**
|
|
8
|
-
* Processes an input and return a representation of the new bot state.
|
|
9
|
-
* The algorithm is splitted in two main parts:
|
|
10
|
-
* 1. Getting the current routing state.
|
|
11
|
-
* 2. Given a routing state, resolve the different possible scenarios and return the new bot state.
|
|
12
|
-
* The new bot state can return three type of actions:
|
|
13
|
-
* - action: an action directly resolved from a matching route
|
|
14
|
-
* - emptyAction: optional action that can exists or not only within childRoutes
|
|
15
|
-
* - fallbackAction: any other action that acts as a fallback (404, )
|
|
16
|
-
*/
|
|
17
|
-
processInput(input: Input, session: Session, lastRoutePath?: RoutePath): ProcessInputResult;
|
|
18
|
-
/**
|
|
19
|
-
* Find the route that matches the given input, if it match with some of the entries, return the whole Route of the entry with optional params captured if matcher was a regex.
|
|
20
|
-
* IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects
|
|
21
|
-
* */
|
|
22
|
-
getRoute(input: Input | Partial<Input>, routes: Route[], session: Session, lastRoutePath: RoutePath): RouteParams | null;
|
|
23
|
-
/**
|
|
24
|
-
* Find the route that matches the given path. Path can include concatenations, e.g: 'Flow1/Subflow1.1'.
|
|
25
|
-
* IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects
|
|
26
|
-
* */
|
|
27
|
-
getRouteByPath(path: RoutePath, routeList?: Route[]): Nullable<Route>;
|
|
28
|
-
/**
|
|
29
|
-
* Returns the matched value for a specific route.
|
|
30
|
-
* Matching Props: ('text' | 'payload' | 'intent' | 'type' | 'input' | 'session' | 'request' ...)
|
|
31
|
-
* Matchers: (string: exact match | regex: regular expression match | function: return true)
|
|
32
|
-
* input: user input object, e.g.: {type: 'text', data: 'Hi'}
|
|
33
|
-
* */
|
|
34
|
-
matchRoute(route: Route, prop: MatchingProp, matcher: Matcher, input: Input, session: Session, lastRoutePath: RoutePath): MatchedValue;
|
|
35
|
-
/**
|
|
36
|
-
* Runs the matcher against the given value.
|
|
37
|
-
* If there is a match, it will return a truthy value (true, RegExp result), o.w., it will return a falsy value.
|
|
38
|
-
* */
|
|
39
|
-
matchValue(matcher: Matcher, value: any): MatchedValue;
|
|
40
|
-
/**
|
|
41
|
-
* It resolves the current state of navigation. Two scenarios:
|
|
42
|
-
* 1. Given a path payload input (__PATH_PAYLOAD__somePath?someParam=someValue), we can resolve the routing state directly from it (using getRouteByPath).
|
|
43
|
-
* 2. Given any other type of input, we resolve the routing state with normal resolution (using getRoute).
|
|
44
|
-
* */
|
|
45
|
-
getRoutingState(input: Input, session: Session, lastRoutePath: RoutePath): RoutingState;
|
|
46
|
-
/**
|
|
47
|
-
* Given a non path payload input, try to run it against the routes, update matching routes information in consequence and dictamine if the flow has been broken.
|
|
48
|
-
* */
|
|
49
|
-
getRoutingStateFromInput(currentRoute: Nullable<Route>, input: Input, session: Session): RoutingState;
|
|
50
|
-
/**
|
|
51
|
-
* Given a path payload input, try to run the path against the routes, update matching routes information in consequence and dictamine if the flow has been broken.
|
|
52
|
-
* */
|
|
53
|
-
getRoutingStateFromPathPayload(currentRoute: Nullable<Route>, pathPayload: string): RoutingState;
|
|
54
|
-
}
|
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Router = void 0;
|
|
4
|
-
const constants_1 = require("../constants");
|
|
5
|
-
const inspector_1 = require("../debug/inspector");
|
|
6
|
-
const utils_1 = require("../utils");
|
|
7
|
-
const router_utils_1 = require("./router-utils");
|
|
8
|
-
class Router {
|
|
9
|
-
constructor(routes, routeInspector = undefined) {
|
|
10
|
-
this.routes = routes;
|
|
11
|
-
this.routeInspector = routeInspector || new inspector_1.RouteInspector();
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Processes an input and return a representation of the new bot state.
|
|
15
|
-
* The algorithm is splitted in two main parts:
|
|
16
|
-
* 1. Getting the current routing state.
|
|
17
|
-
* 2. Given a routing state, resolve the different possible scenarios and return the new bot state.
|
|
18
|
-
* The new bot state can return three type of actions:
|
|
19
|
-
* - action: an action directly resolved from a matching route
|
|
20
|
-
* - emptyAction: optional action that can exists or not only within childRoutes
|
|
21
|
-
* - fallbackAction: any other action that acts as a fallback (404, )
|
|
22
|
-
*/
|
|
23
|
-
// eslint-disable-next-line complexity
|
|
24
|
-
processInput(input, session, lastRoutePath = null) {
|
|
25
|
-
session.__retries = session?.__retries ?? 0;
|
|
26
|
-
// 1. Getting the current routing state.
|
|
27
|
-
const { currentRoute, matchedRoute, params, isFlowBroken } = this.getRoutingState(input, session, lastRoutePath);
|
|
28
|
-
const currentRoutePath = currentRoute?.path ?? null;
|
|
29
|
-
const matchedRoutePath = matchedRoute?.path ?? null;
|
|
30
|
-
// 2. Given a routing state, resolve the different possible scenarios and return the new bot state.
|
|
31
|
-
/**
|
|
32
|
-
* Redirect Scenario:
|
|
33
|
-
* We have matched a redirect route with a given redirection path, so we try to obtain the redirectionRoute with getRouteByPath.
|
|
34
|
-
* Independently of whether the redirectionRoute is found or not, the intent is to trigger a redirection which by definition breaks the flow, so retries are set to 0.
|
|
35
|
-
* It has preference over ignoring retries.
|
|
36
|
-
*/
|
|
37
|
-
if (matchedRoute?.redirect) {
|
|
38
|
-
session.__retries = 0;
|
|
39
|
-
const redirectionRoute = this.getRouteByPath(matchedRoute.redirect);
|
|
40
|
-
if (redirectionRoute) {
|
|
41
|
-
return {
|
|
42
|
-
action: redirectionRoute.action,
|
|
43
|
-
emptyAction: (0, router_utils_1.getEmptyAction)(redirectionRoute.childRoutes),
|
|
44
|
-
fallbackAction: null,
|
|
45
|
-
lastRoutePath: matchedRoute.redirect,
|
|
46
|
-
params,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
action: null,
|
|
51
|
-
emptyAction: null,
|
|
52
|
-
fallbackAction: (0, router_utils_1.getNotFoundAction)(input, this.routes),
|
|
53
|
-
lastRoutePath: null,
|
|
54
|
-
params,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Ignore Retry Scenario:
|
|
59
|
-
* We have matched a route with an ignore retry, so we return directly the new bot state. The intent is to break the flow, so retries are set to 0.
|
|
60
|
-
*/
|
|
61
|
-
if (matchedRoute?.ignoreRetry) {
|
|
62
|
-
session.__retries = 0;
|
|
63
|
-
return {
|
|
64
|
-
action: matchedRoute.action,
|
|
65
|
-
emptyAction: (0, router_utils_1.getEmptyAction)(matchedRoute.childRoutes),
|
|
66
|
-
fallbackAction: null,
|
|
67
|
-
lastRoutePath: matchedRoutePath,
|
|
68
|
-
params,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Retry Scenario:
|
|
73
|
-
* We were in a route which had retries enabled, so we check if the number of retries is exceeded.
|
|
74
|
-
* If we have not surpassed the limit of retries and we haven't matched an ignoreRetry route, update them, and then return the new bot state.
|
|
75
|
-
*/
|
|
76
|
-
if (isFlowBroken &&
|
|
77
|
-
currentRoute &&
|
|
78
|
-
currentRoute.retry &&
|
|
79
|
-
session.__retries < currentRoute.retry) {
|
|
80
|
-
session.__retries = session.__retries !== 0 ? session.__retries + 1 : 1;
|
|
81
|
-
if (matchedRoute && matchedRoutePath !== constants_1.NOT_FOUND_PATH) {
|
|
82
|
-
return {
|
|
83
|
-
action: currentRoute.action,
|
|
84
|
-
emptyAction: (0, router_utils_1.getEmptyAction)(matchedRoute.childRoutes),
|
|
85
|
-
fallbackAction: matchedRoute.action,
|
|
86
|
-
lastRoutePath: currentRoutePath,
|
|
87
|
-
params,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
action: currentRoute.action ?? null,
|
|
92
|
-
emptyAction: (0, router_utils_1.getEmptyAction)(currentRoute.childRoutes),
|
|
93
|
-
fallbackAction: (0, router_utils_1.getNotFoundAction)(input, this.routes),
|
|
94
|
-
lastRoutePath: currentRoutePath,
|
|
95
|
-
params,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Default Scenario:
|
|
100
|
-
* We have matched a route or not, but we don't need to execute retries logic, so retries stay to 0.
|
|
101
|
-
*/
|
|
102
|
-
session.__retries = 0;
|
|
103
|
-
/**
|
|
104
|
-
* Matching Route Scenario:
|
|
105
|
-
* We have matched a route, so we return the new bot state.
|
|
106
|
-
*/
|
|
107
|
-
if (matchedRoute && matchedRoutePath !== constants_1.NOT_FOUND_PATH) {
|
|
108
|
-
return {
|
|
109
|
-
action: matchedRoute.action ?? null,
|
|
110
|
-
emptyAction: (0, router_utils_1.getEmptyAction)(matchedRoute.childRoutes),
|
|
111
|
-
fallbackAction: null,
|
|
112
|
-
lastRoutePath: matchedRoutePath,
|
|
113
|
-
params,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* 404 Scenario (No Route Found):
|
|
118
|
-
* We have not matched any route, so we return the new bot state.
|
|
119
|
-
*/
|
|
120
|
-
return {
|
|
121
|
-
action: null,
|
|
122
|
-
emptyAction: null,
|
|
123
|
-
fallbackAction: (0, router_utils_1.getNotFoundAction)(input, this.routes),
|
|
124
|
-
params,
|
|
125
|
-
lastRoutePath: currentRoutePath,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Find the route that matches the given input, if it match with some of the entries, return the whole Route of the entry with optional params captured if matcher was a regex.
|
|
130
|
-
* IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects
|
|
131
|
-
* */
|
|
132
|
-
getRoute(input, routes, session, lastRoutePath) {
|
|
133
|
-
let params = {};
|
|
134
|
-
const route = routes.find(r => Object.entries(r)
|
|
135
|
-
.filter(([key, _]) => key !== 'action' && key !== 'childRoutes' && key !== 'path')
|
|
136
|
-
.some(([key, value]) => {
|
|
137
|
-
const match = this.matchRoute(r, key, value, input, session, lastRoutePath);
|
|
138
|
-
try {
|
|
139
|
-
if (match !== null && typeof match !== 'boolean' && match.groups) {
|
|
140
|
-
// Strip '[Object: null prototype]' from groups result: https://stackoverflow.com/a/62945609/6237608
|
|
141
|
-
params = { ...match.groups };
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
catch (_e) { }
|
|
145
|
-
return Boolean(match);
|
|
146
|
-
}));
|
|
147
|
-
if (route) {
|
|
148
|
-
return { route: (0, utils_1.cloneObject)(route), params };
|
|
149
|
-
}
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Find the route that matches the given path. Path can include concatenations, e.g: 'Flow1/Subflow1.1'.
|
|
154
|
-
* IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects
|
|
155
|
-
* */
|
|
156
|
-
getRouteByPath(path, routeList = this.routes) {
|
|
157
|
-
if (!path) {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
const [currentPath, ...childPath] = path.split('/');
|
|
161
|
-
for (const route of routeList) {
|
|
162
|
-
// iterate over all routeList
|
|
163
|
-
if (route.path === currentPath) {
|
|
164
|
-
if (route.childRoutes?.length && childPath.length > 0) {
|
|
165
|
-
// evaluate childroute over next actions
|
|
166
|
-
const computedRoute = this.getRouteByPath(childPath.join('/'), route.childRoutes);
|
|
167
|
-
// IMPORTANT: Returning a new object to avoid modifying dev routes and introduce side effects
|
|
168
|
-
if (computedRoute) {
|
|
169
|
-
return (0, utils_1.cloneObject)(computedRoute);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
else if (childPath.length === 0) {
|
|
173
|
-
return (0, utils_1.cloneObject)(route); // last action and found route
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Returns the matched value for a specific route.
|
|
181
|
-
* Matching Props: ('text' | 'payload' | 'intent' | 'type' | 'input' | 'session' | 'request' ...)
|
|
182
|
-
* Matchers: (string: exact match | regex: regular expression match | function: return true)
|
|
183
|
-
* input: user input object, e.g.: {type: 'text', data: 'Hi'}
|
|
184
|
-
* */
|
|
185
|
-
matchRoute(route, prop, matcher, input, session, lastRoutePath) {
|
|
186
|
-
let value = null;
|
|
187
|
-
if (Object.keys(input).indexOf(prop) > -1) {
|
|
188
|
-
value = input[prop];
|
|
189
|
-
}
|
|
190
|
-
else if (prop === 'text') {
|
|
191
|
-
value = input.data;
|
|
192
|
-
}
|
|
193
|
-
else if (prop === 'input') {
|
|
194
|
-
value = input;
|
|
195
|
-
}
|
|
196
|
-
else if (prop === 'session') {
|
|
197
|
-
value = session;
|
|
198
|
-
}
|
|
199
|
-
else if (prop === 'request') {
|
|
200
|
-
value = { input, session, lastRoutePath };
|
|
201
|
-
}
|
|
202
|
-
const matched = this.matchValue(matcher, value);
|
|
203
|
-
if (matched) {
|
|
204
|
-
this.routeInspector.routeMatched(route, prop, matcher, value);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
this.routeInspector.routeNotMatched(route, prop, matcher, value);
|
|
208
|
-
}
|
|
209
|
-
return matched;
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Runs the matcher against the given value.
|
|
213
|
-
* If there is a match, it will return a truthy value (true, RegExp result), o.w., it will return a falsy value.
|
|
214
|
-
* */
|
|
215
|
-
matchValue(matcher, value) {
|
|
216
|
-
if (typeof matcher === 'string') {
|
|
217
|
-
return value === matcher;
|
|
218
|
-
}
|
|
219
|
-
if (matcher instanceof RegExp) {
|
|
220
|
-
if (value === undefined || value === null) {
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
return matcher.exec(value);
|
|
224
|
-
}
|
|
225
|
-
if (typeof matcher === 'function') {
|
|
226
|
-
return matcher(value);
|
|
227
|
-
}
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* It resolves the current state of navigation. Two scenarios:
|
|
232
|
-
* 1. Given a path payload input (__PATH_PAYLOAD__somePath?someParam=someValue), we can resolve the routing state directly from it (using getRouteByPath).
|
|
233
|
-
* 2. Given any other type of input, we resolve the routing state with normal resolution (using getRoute).
|
|
234
|
-
* */
|
|
235
|
-
getRoutingState(input, session, lastRoutePath) {
|
|
236
|
-
const currentRoute = this.getRouteByPath(lastRoutePath);
|
|
237
|
-
if (currentRoute && lastRoutePath) {
|
|
238
|
-
currentRoute.path = lastRoutePath;
|
|
239
|
-
}
|
|
240
|
-
if (typeof input.payload === 'string' && (0, router_utils_1.isPathPayload)(input.payload)) {
|
|
241
|
-
return this.getRoutingStateFromPathPayload(currentRoute, input.payload);
|
|
242
|
-
}
|
|
243
|
-
return this.getRoutingStateFromInput(currentRoute, input, session);
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Given a non path payload input, try to run it against the routes, update matching routes information in consequence and dictamine if the flow has been broken.
|
|
247
|
-
* */
|
|
248
|
-
getRoutingStateFromInput(currentRoute, input, session) {
|
|
249
|
-
// get route depending of current ChildRoutes
|
|
250
|
-
if (currentRoute?.childRoutes) {
|
|
251
|
-
const routeParams = this.getRoute(input, currentRoute.childRoutes, session, currentRoute.path);
|
|
252
|
-
if (routeParams) {
|
|
253
|
-
return {
|
|
254
|
-
currentRoute,
|
|
255
|
-
matchedRoute: {
|
|
256
|
-
...routeParams.route,
|
|
257
|
-
path: routeParams.route && currentRoute.path
|
|
258
|
-
? `${currentRoute.path}/${routeParams.route.path}`
|
|
259
|
-
: currentRoute.path,
|
|
260
|
-
},
|
|
261
|
-
params: routeParams.params,
|
|
262
|
-
isFlowBroken: false,
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* we couldn't find a route in the state of the currentRoute childRoutes,
|
|
268
|
-
* so let's find in the general routes
|
|
269
|
-
*/
|
|
270
|
-
const routeParams = this.getRoute(input, this.routes, session, currentRoute?.path ?? null);
|
|
271
|
-
const isFlowBroken = Boolean(currentRoute?.path);
|
|
272
|
-
if (routeParams?.route) {
|
|
273
|
-
return {
|
|
274
|
-
currentRoute,
|
|
275
|
-
matchedRoute: {
|
|
276
|
-
...routeParams.route,
|
|
277
|
-
path: routeParams.route?.path ?? null,
|
|
278
|
-
},
|
|
279
|
-
params: routeParams.params,
|
|
280
|
-
isFlowBroken,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
return {
|
|
284
|
-
currentRoute,
|
|
285
|
-
matchedRoute: null,
|
|
286
|
-
params: {},
|
|
287
|
-
isFlowBroken,
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Given a path payload input, try to run the path against the routes, update matching routes information in consequence and dictamine if the flow has been broken.
|
|
292
|
-
* */
|
|
293
|
-
getRoutingStateFromPathPayload(currentRoute, pathPayload) {
|
|
294
|
-
const { path, params } = (0, router_utils_1.getPathParamsFromPathPayload)(pathPayload);
|
|
295
|
-
/**
|
|
296
|
-
* shorthand function to update the matching information given a path
|
|
297
|
-
*/
|
|
298
|
-
const getRoutingStateFromPath = (seekPath) => {
|
|
299
|
-
const matchedRoute = this.getRouteByPath(seekPath);
|
|
300
|
-
if (!matchedRoute) {
|
|
301
|
-
return {
|
|
302
|
-
currentRoute,
|
|
303
|
-
matchedRoute: null,
|
|
304
|
-
params: {},
|
|
305
|
-
isFlowBroken: true,
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
return {
|
|
309
|
-
currentRoute,
|
|
310
|
-
matchedRoute: { ...matchedRoute, path: seekPath },
|
|
311
|
-
params,
|
|
312
|
-
isFlowBroken: false,
|
|
313
|
-
};
|
|
314
|
-
};
|
|
315
|
-
/**
|
|
316
|
-
* Given a valid path: 'Flow1/Subflow1' we are in one of the two scenarios below.
|
|
317
|
-
*/
|
|
318
|
-
// 1. Received __PATH_PAYLOAD__Subflow2, so we need to first try to concatenate it with Flow1 (lastRoutePath)
|
|
319
|
-
if (currentRoute?.path) {
|
|
320
|
-
const routingState = getRoutingStateFromPath(`${currentRoute.path}/${path}`);
|
|
321
|
-
if (routingState.matchedRoute) {
|
|
322
|
-
return routingState;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
// 2. Received __PATH_PAYLOAD__Flow1/Subflow1, so we can resolve it directly
|
|
326
|
-
return getRoutingStateFromPath(path);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
exports.Router = Router;
|
|
330
|
-
//# sourceMappingURL=router.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/routing/router.ts"],"names":[],"mappings":";;;AAAA,4CAA6C;AAC7C,kDAAmD;AAcnD,oCAAsC;AACtC,iDAKuB;AAEvB,MAAa,MAAM;IAIjB,YACE,MAAe,EACf,iBAA6C,SAAS;QAEtD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,cAAc,GAAG,cAAc,IAAI,IAAI,0BAAc,EAAE,CAAA;IAC9D,CAAC;IAED;;;;;;;;;OASG;IAEH,sCAAsC;IACtC,YAAY,CACV,KAAY,EACZ,OAAgB,EAChB,gBAA2B,IAAI;QAE/B,OAAO,CAAC,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,CAAC,CAAA;QAE3C,wCAAwC;QACxC,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,GACxD,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC,CAAA;QAErD,MAAM,gBAAgB,GAAG,YAAY,EAAE,IAAI,IAAI,IAAI,CAAA;QACnD,MAAM,gBAAgB,GAAG,YAAY,EAAE,IAAI,IAAI,IAAI,CAAA;QAEnD,mGAAmG;QAEnG;;;;;WAKG;QACH,IAAI,YAAY,EAAE,QAAQ,EAAE,CAAC;YAC3B,OAAO,CAAC,SAAS,GAAG,CAA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ACb,CAAA;IACH,CAAC;IAED;;SAEK;IACL,8BAA8B,CAC5B,YAA6B,EAC7B,WAAmB;QAEnB,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAA,2CAA4B,EAAC,WAAW,CAAC,CAAA;QAClE;;WAEG;QACH,MAAM,uBAAuB,GAAG,CAAC,QAAgB,EAAgB,EAAE;YACjE,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;YAClD,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO;oBACL,YAAY;oBACZ,YAAY,EAAE,IAAI;oBAClB,MAAM,EAAE,EAAE;oBACV,YAAY,EAAE,IAAI;iBACnB,CAAA;YACH,CAAC;YACD,OAAO;gBACL,YAAY;gBACZ,YAAY,EAAE,EAAE,GAAG,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACjD,MAAM;gBACN,YAAY,EAAE,KAAK;aACpB,CAAA;QACH,CAAC,CAAA;QACD;;WAEG;QACH,8GAA8G;QAC9G,IAAI,YAAY,EAAE,IAAI,EAAE,CAAC;YACvB,MAAM,YAAY,GAAG,uBAAuB,CAC1C,GAAG,YAAY,CAAC,IAAI,IAAI,IAAI,EAAE,CAC/B,CAAA;YACD,IAAI,YAAY,CAAC,YAAY,EAAE,CAAC;gBAC9B,OAAO,YAAY,CAAA;YACrB,CAAC;QACH,CAAC;QACD,4EAA4E;QAC5E,OAAO,uBAAuB,CAAC,IAAc,CAAC,CAAA;IAChD,CAAC;CACF;AA9YD,wBA8YC"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { type BotContext, type BotRequest, type BotSecrets, type BotSettings, type ContactInfo, type Input, type ProviderType, type ResolvedPlugins, type Session, type SessionUser } from '../models';
|
|
2
|
-
export declare const TEST_DEFAULTS: {
|
|
3
|
-
HUBTYPE_API_URL: string;
|
|
4
|
-
STATIC_URL: string;
|
|
5
|
-
LITELLM_API_URL: string;
|
|
6
|
-
AZURE_OPENAI_API_BASE: string;
|
|
7
|
-
AZURE_OPENAI_API_VERSION: string;
|
|
8
|
-
LANGUAGE_DETECTION_ENABLED: boolean;
|
|
9
|
-
HUBTYPE_ACCESS_TOKEN: string;
|
|
10
|
-
LITELLM_API_KEY: string;
|
|
11
|
-
AZURE_OPENAI_API_KEY: string;
|
|
12
|
-
ACCESS_TOKEN: string;
|
|
13
|
-
HUBTYPE_API_HOST: string;
|
|
14
|
-
FLOW_THREAD_ID: string;
|
|
15
|
-
BOT_ID: string;
|
|
16
|
-
USER_ID: string;
|
|
17
|
-
ORG_ID: string;
|
|
18
|
-
ORG_NAME: string;
|
|
19
|
-
PROVIDER: ProviderType;
|
|
20
|
-
LOCALE: string;
|
|
21
|
-
COUNTRY: string;
|
|
22
|
-
BOT_INTERACTION_ID: string;
|
|
23
|
-
MESSAGE_ID: string;
|
|
24
|
-
LAST_ROUTE_PATH: string;
|
|
25
|
-
};
|
|
26
|
-
export declare function createTestSettings(overrides?: Partial<BotSettings>): BotSettings;
|
|
27
|
-
export declare function createTestSecrets(overrides?: Partial<BotSecrets>): BotSecrets;
|
|
28
|
-
export interface TestUserOptions {
|
|
29
|
-
id?: string;
|
|
30
|
-
provider?: ProviderType;
|
|
31
|
-
locale?: string;
|
|
32
|
-
country?: string;
|
|
33
|
-
systemLocale?: string;
|
|
34
|
-
contactInfo?: ContactInfo[];
|
|
35
|
-
extraData?: Record<string, any>;
|
|
36
|
-
}
|
|
37
|
-
export declare function createTestSessionUser(options?: TestUserOptions): SessionUser<Record<string, any>>;
|
|
38
|
-
export interface TestSessionOptions {
|
|
39
|
-
user?: TestUserOptions;
|
|
40
|
-
botId?: string;
|
|
41
|
-
organization?: string;
|
|
42
|
-
organizationId?: string;
|
|
43
|
-
isFirstInteraction?: boolean;
|
|
44
|
-
isTestIntegration?: boolean;
|
|
45
|
-
accessToken?: string;
|
|
46
|
-
hubtypeApi?: string;
|
|
47
|
-
flowThreadId?: string;
|
|
48
|
-
retries?: number;
|
|
49
|
-
shadowing?: boolean;
|
|
50
|
-
hubtypeCaseId?: string;
|
|
51
|
-
captureUserInputNodeId?: string;
|
|
52
|
-
}
|
|
53
|
-
export declare function createTestSession(options?: TestSessionOptions): Session<Record<string, any>>;
|
|
54
|
-
export interface TestInputOptions {
|
|
55
|
-
type?: Input['type'];
|
|
56
|
-
data?: string;
|
|
57
|
-
text?: string;
|
|
58
|
-
payload?: string;
|
|
59
|
-
src?: string;
|
|
60
|
-
botInteractionId?: string;
|
|
61
|
-
messageId?: string;
|
|
62
|
-
context?: Input['context'];
|
|
63
|
-
transcript?: string;
|
|
64
|
-
}
|
|
65
|
-
export declare function createTestInput(options?: TestInputOptions): Input;
|
|
66
|
-
export interface TestBotRequestOptions {
|
|
67
|
-
input?: TestInputOptions | Input;
|
|
68
|
-
session?: TestSessionOptions | Session;
|
|
69
|
-
lastRoutePath?: string;
|
|
70
|
-
settings?: Partial<BotSettings> | BotSettings;
|
|
71
|
-
secrets?: Partial<BotSecrets> | BotSecrets;
|
|
72
|
-
}
|
|
73
|
-
export declare function createTestBotRequest(options?: TestBotRequestOptions): BotRequest;
|
|
74
|
-
export interface TestBotContextOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins> extends TestBotRequestOptions {
|
|
75
|
-
plugins?: TPlugins;
|
|
76
|
-
params?: Record<string, string>;
|
|
77
|
-
defaultDelay?: number;
|
|
78
|
-
defaultTyping?: number;
|
|
79
|
-
}
|
|
80
|
-
export declare function createTestBotContext<TPlugins extends ResolvedPlugins = ResolvedPlugins>(options?: TestBotContextOptions<TPlugins>): BotContext<TPlugins>;
|
|
81
|
-
/**
|
|
82
|
-
* Alias for `createTestBotContext` typed as `PluginPreRequest`.
|
|
83
|
-
* PluginPreRequest === BotContext in @botonic/core.
|
|
84
|
-
*/
|
|
85
|
-
export declare const createTestPluginPreRequest: typeof createTestBotContext;
|
|
86
|
-
export interface TestPluginPostRequestOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins> extends TestBotContextOptions<TPlugins> {
|
|
87
|
-
response?: string | null;
|
|
88
|
-
}
|
|
89
|
-
export declare function createTestPluginPostRequest<TPlugins extends ResolvedPlugins = ResolvedPlugins>(options?: TestPluginPostRequestOptions<TPlugins>): BotContext<TPlugins> & {
|
|
90
|
-
response: string | null;
|
|
91
|
-
};
|