@botonic/core 1.0.0-dev.2 → 2.23.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/CHANGELOG.md +226 -0
- package/README.md +7 -9
- package/package.json +19 -57
- package/src/index.d.ts +4 -0
- package/src/index.js +5 -0
- package/src/index.js.map +1 -0
- package/src/lib/core-bot/index.d.ts +33 -0
- package/src/lib/core-bot/index.js +113 -0
- package/src/lib/core-bot/index.js.map +1 -0
- package/src/lib/hubtype-service/handoff.d.ts +4 -0
- package/src/lib/hubtype-service/handoff.js +32 -0
- package/src/lib/hubtype-service/handoff.js.map +1 -0
- package/src/lib/hubtype-service/index.d.ts +10 -0
- package/src/lib/hubtype-service/index.js +96 -0
- package/src/lib/hubtype-service/index.js.map +1 -0
- package/src/lib/messages/button.d.ts +8 -0
- package/src/lib/messages/button.js +10 -0
- package/src/lib/messages/button.js.map +1 -0
- package/src/lib/plugins/index.d.ts +2 -0
- package/src/lib/plugins/index.js +23 -0
- package/src/lib/plugins/index.js.map +1 -0
- package/src/lib/routes/index.d.ts +0 -0
- package/src/lib/routes/index.js +2 -0
- package/src/lib/routes/index.js.map +1 -0
- package/src/lib/routes/router.d.ts +14 -0
- package/src/lib/routes/router.js +68 -0
- package/src/lib/routes/router.js.map +1 -0
- package/src/lib/routes/types.d.ts +15 -0
- package/src/lib/routes/types.js +2 -0
- package/src/lib/routes/types.js.map +1 -0
- package/{lib/cjs/utils.d.ts → src/lib/utils/index.d.ts} +0 -4
- package/{lib/esm/utils.js → src/lib/utils/index.js} +1 -34
- package/src/lib/utils/index.js.map +1 -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 -36
- package/lib/cjs/core-bot.js +0 -96
- 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 -72
- package/lib/cjs/debug/inspector.js.map +0 -1
- package/lib/cjs/handoff.d.ts +0 -67
- package/lib/cjs/handoff.js +0 -186
- package/lib/cjs/handoff.js.map +0 -1
- package/lib/cjs/hubtype-service.d.ts +0 -69
- package/lib/cjs/hubtype-service.js +0 -190
- package/lib/cjs/hubtype-service.js.map +0 -1
- package/lib/cjs/i18n.d.ts +0 -2
- package/lib/cjs/i18n.js +0 -11
- package/lib/cjs/i18n.js.map +0 -1
- package/lib/cjs/index.d.ts +0 -11
- package/lib/cjs/index.js +0 -15
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/models/bot-state.d.ts +0 -11
- package/lib/cjs/models/bot-state.js +0 -3
- package/lib/cjs/models/bot-state.js.map +0 -1
- package/lib/cjs/models/channels.d.ts +0 -9
- package/lib/cjs/models/channels.js +0 -14
- package/lib/cjs/models/channels.js.map +0 -1
- package/lib/cjs/models/events/base-event.d.ts +0 -20
- package/lib/cjs/models/events/base-event.js +0 -17
- package/lib/cjs/models/events/base-event.js.map +0 -1
- package/lib/cjs/models/events/botonic-event.d.ts +0 -4
- package/lib/cjs/models/events/botonic-event.js +0 -3
- package/lib/cjs/models/events/botonic-event.js.map +0 -1
- package/lib/cjs/models/events/connection/connection-event.d.ts +0 -9
- package/lib/cjs/models/events/connection/connection-event.js +0 -9
- package/lib/cjs/models/events/connection/connection-event.js.map +0 -1
- package/lib/cjs/models/events/connection/index.d.ts +0 -1
- package/lib/cjs/models/events/connection/index.js +0 -5
- package/lib/cjs/models/events/connection/index.js.map +0 -1
- package/lib/cjs/models/events/index.d.ts +0 -4
- package/lib/cjs/models/events/index.js +0 -8
- package/lib/cjs/models/events/index.js.map +0 -1
- package/lib/cjs/models/events/integration/index.d.ts +0 -1
- package/lib/cjs/models/events/integration/index.js +0 -5
- package/lib/cjs/models/events/integration/index.js.map +0 -1
- package/lib/cjs/models/events/integration/integration-event.d.ts +0 -6
- package/lib/cjs/models/events/integration/integration-event.js +0 -3
- package/lib/cjs/models/events/integration/integration-event.js.map +0 -1
- package/lib/cjs/models/events/message/buttons.d.ts +0 -18
- package/lib/cjs/models/events/message/buttons.js +0 -3
- package/lib/cjs/models/events/message/buttons.js.map +0 -1
- package/lib/cjs/models/events/message/carousel.d.ts +0 -11
- package/lib/cjs/models/events/message/carousel.js +0 -3
- package/lib/cjs/models/events/message/carousel.js.map +0 -1
- package/lib/cjs/models/events/message/custom.d.ts +0 -6
- package/lib/cjs/models/events/message/custom.js +0 -3
- package/lib/cjs/models/events/message/custom.js.map +0 -1
- package/lib/cjs/models/events/message/index.d.ts +0 -9
- package/lib/cjs/models/events/message/index.js +0 -13
- package/lib/cjs/models/events/message/index.js.map +0 -1
- package/lib/cjs/models/events/message/location.d.ts +0 -6
- package/lib/cjs/models/events/message/location.js +0 -3
- package/lib/cjs/models/events/message/location.js.map +0 -1
- package/lib/cjs/models/events/message/media.d.ts +0 -18
- package/lib/cjs/models/events/message/media.js +0 -11
- package/lib/cjs/models/events/message/media.js.map +0 -1
- package/lib/cjs/models/events/message/message-event.d.ts +0 -30
- package/lib/cjs/models/events/message/message-event.js +0 -32
- package/lib/cjs/models/events/message/message-event.js.map +0 -1
- package/lib/cjs/models/events/message/postback.d.ts +0 -4
- package/lib/cjs/models/events/message/postback.js +0 -3
- package/lib/cjs/models/events/message/postback.js.map +0 -1
- package/lib/cjs/models/events/message/replies.d.ts +0 -7
- package/lib/cjs/models/events/message/replies.js +0 -3
- package/lib/cjs/models/events/message/replies.js.map +0 -1
- package/lib/cjs/models/events/message/text.d.ts +0 -8
- package/lib/cjs/models/events/message/text.js +0 -3
- package/lib/cjs/models/events/message/text.js.map +0 -1
- package/lib/cjs/models/index.d.ts +0 -6
- package/lib/cjs/models/index.js +0 -10
- package/lib/cjs/models/index.js.map +0 -1
- package/lib/cjs/models/legacy-types.d.ts +0 -184
- package/lib/cjs/models/legacy-types.js +0 -59
- package/lib/cjs/models/legacy-types.js.map +0 -1
- package/lib/cjs/models/session.d.ts +0 -3
- package/lib/cjs/models/session.js +0 -3
- package/lib/cjs/models/session.js.map +0 -1
- package/lib/cjs/models/user.d.ts +0 -14
- package/lib/cjs/models/user.js +0 -3
- package/lib/cjs/models/user.js.map +0 -1
- package/lib/cjs/output-parser/botonic-output-parser.d.ts +0 -16
- package/lib/cjs/output-parser/botonic-output-parser.js +0 -37
- package/lib/cjs/output-parser/botonic-output-parser.js.map +0 -1
- package/lib/cjs/output-parser/factory.d.ts +0 -4
- package/lib/cjs/output-parser/factory.js +0 -32
- package/lib/cjs/output-parser/factory.js.map +0 -1
- package/lib/cjs/output-parser/index.d.ts +0 -3
- package/lib/cjs/output-parser/index.js +0 -7
- package/lib/cjs/output-parser/index.js.map +0 -1
- package/lib/cjs/output-parser/parsers.d.ts +0 -22
- package/lib/cjs/output-parser/parsers.js +0 -147
- package/lib/cjs/output-parser/parsers.js.map +0 -1
- package/lib/cjs/plugins.d.ts +0 -6
- package/lib/cjs/plugins.js +0 -48
- package/lib/cjs/plugins.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 -89
- 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 -319
- package/lib/cjs/routing/router.js.map +0 -1
- package/lib/cjs/utils.js +0 -90
- package/lib/cjs/utils.js.map +0 -1
- package/lib/esm/constants.d.ts +0 -4
- package/lib/esm/constants.js +0 -5
- package/lib/esm/constants.js.map +0 -1
- package/lib/esm/core-bot.d.ts +0 -36
- package/lib/esm/core-bot.js +0 -92
- package/lib/esm/core-bot.js.map +0 -1
- package/lib/esm/debug/index.d.ts +0 -1
- package/lib/esm/debug/index.js +0 -2
- package/lib/esm/debug/index.js.map +0 -1
- package/lib/esm/debug/inspector.d.ts +0 -24
- package/lib/esm/debug/inspector.js +0 -65
- package/lib/esm/debug/inspector.js.map +0 -1
- package/lib/esm/handoff.d.ts +0 -67
- package/lib/esm/handoff.js +0 -173
- package/lib/esm/handoff.js.map +0 -1
- package/lib/esm/hubtype-service.d.ts +0 -69
- package/lib/esm/hubtype-service.js +0 -185
- package/lib/esm/hubtype-service.js.map +0 -1
- package/lib/esm/i18n.d.ts +0 -2
- package/lib/esm/i18n.js +0 -7
- package/lib/esm/i18n.js.map +0 -1
- package/lib/esm/index.d.ts +0 -11
- package/lib/esm/index.js +0 -12
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/models/bot-state.d.ts +0 -11
- package/lib/esm/models/bot-state.js +0 -2
- package/lib/esm/models/bot-state.js.map +0 -1
- package/lib/esm/models/channels.d.ts +0 -9
- package/lib/esm/models/channels.js +0 -11
- package/lib/esm/models/channels.js.map +0 -1
- package/lib/esm/models/events/base-event.d.ts +0 -20
- package/lib/esm/models/events/base-event.js +0 -14
- package/lib/esm/models/events/base-event.js.map +0 -1
- package/lib/esm/models/events/botonic-event.d.ts +0 -4
- package/lib/esm/models/events/botonic-event.js +0 -2
- package/lib/esm/models/events/botonic-event.js.map +0 -1
- package/lib/esm/models/events/connection/connection-event.d.ts +0 -9
- package/lib/esm/models/events/connection/connection-event.js +0 -6
- package/lib/esm/models/events/connection/connection-event.js.map +0 -1
- package/lib/esm/models/events/connection/index.d.ts +0 -1
- package/lib/esm/models/events/connection/index.js +0 -2
- package/lib/esm/models/events/connection/index.js.map +0 -1
- package/lib/esm/models/events/index.d.ts +0 -4
- package/lib/esm/models/events/index.js +0 -5
- package/lib/esm/models/events/index.js.map +0 -1
- package/lib/esm/models/events/integration/index.d.ts +0 -1
- package/lib/esm/models/events/integration/index.js +0 -2
- package/lib/esm/models/events/integration/index.js.map +0 -1
- package/lib/esm/models/events/integration/integration-event.d.ts +0 -6
- package/lib/esm/models/events/integration/integration-event.js +0 -2
- package/lib/esm/models/events/integration/integration-event.js.map +0 -1
- package/lib/esm/models/events/message/buttons.d.ts +0 -18
- package/lib/esm/models/events/message/buttons.js +0 -2
- package/lib/esm/models/events/message/buttons.js.map +0 -1
- package/lib/esm/models/events/message/carousel.d.ts +0 -11
- package/lib/esm/models/events/message/carousel.js +0 -2
- package/lib/esm/models/events/message/carousel.js.map +0 -1
- package/lib/esm/models/events/message/custom.d.ts +0 -6
- package/lib/esm/models/events/message/custom.js +0 -2
- package/lib/esm/models/events/message/custom.js.map +0 -1
- package/lib/esm/models/events/message/index.d.ts +0 -9
- package/lib/esm/models/events/message/index.js +0 -10
- package/lib/esm/models/events/message/index.js.map +0 -1
- package/lib/esm/models/events/message/location.d.ts +0 -6
- package/lib/esm/models/events/message/location.js +0 -2
- package/lib/esm/models/events/message/location.js.map +0 -1
- package/lib/esm/models/events/message/media.d.ts +0 -18
- package/lib/esm/models/events/message/media.js +0 -8
- package/lib/esm/models/events/message/media.js.map +0 -1
- package/lib/esm/models/events/message/message-event.d.ts +0 -30
- package/lib/esm/models/events/message/message-event.js +0 -29
- package/lib/esm/models/events/message/message-event.js.map +0 -1
- package/lib/esm/models/events/message/postback.d.ts +0 -4
- package/lib/esm/models/events/message/postback.js +0 -2
- package/lib/esm/models/events/message/postback.js.map +0 -1
- package/lib/esm/models/events/message/replies.d.ts +0 -7
- package/lib/esm/models/events/message/replies.js +0 -2
- package/lib/esm/models/events/message/replies.js.map +0 -1
- package/lib/esm/models/events/message/text.d.ts +0 -8
- package/lib/esm/models/events/message/text.js +0 -2
- package/lib/esm/models/events/message/text.js.map +0 -1
- package/lib/esm/models/index.d.ts +0 -6
- package/lib/esm/models/index.js +0 -7
- package/lib/esm/models/index.js.map +0 -1
- package/lib/esm/models/legacy-types.d.ts +0 -184
- package/lib/esm/models/legacy-types.js +0 -56
- package/lib/esm/models/legacy-types.js.map +0 -1
- package/lib/esm/models/session.d.ts +0 -3
- package/lib/esm/models/session.js +0 -2
- package/lib/esm/models/session.js.map +0 -1
- package/lib/esm/models/user.d.ts +0 -14
- package/lib/esm/models/user.js +0 -2
- package/lib/esm/models/user.js.map +0 -1
- package/lib/esm/output-parser/botonic-output-parser.d.ts +0 -16
- package/lib/esm/output-parser/botonic-output-parser.js +0 -33
- package/lib/esm/output-parser/botonic-output-parser.js.map +0 -1
- package/lib/esm/output-parser/factory.d.ts +0 -4
- package/lib/esm/output-parser/factory.js +0 -28
- package/lib/esm/output-parser/factory.js.map +0 -1
- package/lib/esm/output-parser/index.d.ts +0 -3
- package/lib/esm/output-parser/index.js +0 -4
- package/lib/esm/output-parser/index.js.map +0 -1
- package/lib/esm/output-parser/parsers.d.ts +0 -22
- package/lib/esm/output-parser/parsers.js +0 -130
- package/lib/esm/output-parser/parsers.js.map +0 -1
- package/lib/esm/plugins.d.ts +0 -6
- package/lib/esm/plugins.js +0 -43
- package/lib/esm/plugins.js.map +0 -1
- package/lib/esm/routing/index.d.ts +0 -2
- package/lib/esm/routing/index.js +0 -3
- package/lib/esm/routing/index.js.map +0 -1
- package/lib/esm/routing/router-utils.d.ts +0 -11
- package/lib/esm/routing/router-utils.js +0 -79
- package/lib/esm/routing/router-utils.js.map +0 -1
- package/lib/esm/routing/router.d.ts +0 -54
- package/lib/esm/routing/router.js +0 -315
- package/lib/esm/routing/router.js.map +0 -1
- package/lib/esm/utils.d.ts +0 -11
- package/lib/esm/utils.js.map +0 -1
- package/src/constants.ts +0 -6
- package/src/core-bot.ts +0 -181
- package/src/debug/index.ts +0 -1
- package/src/debug/inspector.ts +0 -102
- package/src/handoff.ts +0 -271
- package/src/hubtype-service.ts +0 -266
- package/src/i18n.ts +0 -12
- package/src/index.ts +0 -11
- package/src/models/bot-state.ts +0 -12
- package/src/models/channels.ts +0 -9
- package/src/models/events/base-event.ts +0 -22
- package/src/models/events/botonic-event.ts +0 -26
- package/src/models/events/connection/connection-event.ts +0 -11
- package/src/models/events/connection/index.ts +0 -1
- package/src/models/events/index.ts +0 -4
- package/src/models/events/integration/index.ts +0 -1
- package/src/models/events/integration/integration-event.ts +0 -13
- package/src/models/events/message/buttons.ts +0 -23
- package/src/models/events/message/carousel.ts +0 -13
- package/src/models/events/message/custom.ts +0 -7
- package/src/models/events/message/index.ts +0 -9
- package/src/models/events/message/location.ts +0 -7
- package/src/models/events/message/media.ts +0 -28
- package/src/models/events/message/message-event.ts +0 -37
- package/src/models/events/message/postback.ts +0 -5
- package/src/models/events/message/replies.ts +0 -8
- package/src/models/events/message/text.ts +0 -12
- package/src/models/index.ts +0 -6
- package/src/models/legacy-types.ts +0 -262
- package/src/models/session.ts +0 -3
- package/src/models/user.ts +0 -16
- package/src/output-parser/botonic-output-parser.ts +0 -38
- package/src/output-parser/factory.ts +0 -38
- package/src/output-parser/index.ts +0 -3
- package/src/output-parser/parsers.ts +0 -202
- package/src/plugins.ts +0 -59
- package/src/routing/index.ts +0 -2
- package/src/routing/router-utils.ts +0 -100
- package/src/routing/router.ts +0 -415
- package/src/utils.ts +0 -90
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
import { NOT_FOUND_PATH } from '../constants';
|
|
2
|
-
import { RouteInspector } from '../debug/inspector';
|
|
3
|
-
import { cloneObject } from '../utils';
|
|
4
|
-
import { getEmptyAction, getNotFoundAction, getPathParamsFromPathPayload, isPathPayload, } from './router-utils';
|
|
5
|
-
export class Router {
|
|
6
|
-
constructor(routes, routeInspector = undefined) {
|
|
7
|
-
this.routes = routes;
|
|
8
|
-
this.routeInspector = routeInspector || new RouteInspector();
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Processes an input and return a representation of the new bot state.
|
|
12
|
-
* The algorithm is splitted in two main parts:
|
|
13
|
-
* 1. Getting the current routing state.
|
|
14
|
-
* 2. Given a routing state, resolve the different possible scenarios and return the new bot state.
|
|
15
|
-
* The new bot state can return three type of actions:
|
|
16
|
-
* - action: an action directly resolved from a matching route
|
|
17
|
-
* - emptyAction: optional action that can exists or not only within childRoutes
|
|
18
|
-
* - fallbackAction: any other action that acts as a fallback (404, )
|
|
19
|
-
*/
|
|
20
|
-
// eslint-disable-next-line complexity
|
|
21
|
-
processInput(input, session, botState) {
|
|
22
|
-
var _a, _b, _c, _d, _e;
|
|
23
|
-
botState.retries = (_a = botState.retries) !== null && _a !== void 0 ? _a : 0;
|
|
24
|
-
// 1. Getting the current routing state.
|
|
25
|
-
const { currentRoute, matchedRoute, params, isFlowBroken, } = this.getRoutingState(input, session, botState);
|
|
26
|
-
const currentRoutePath = (_b = currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path) !== null && _b !== void 0 ? _b : null;
|
|
27
|
-
const matchedRoutePath = (_c = matchedRoute === null || matchedRoute === void 0 ? void 0 : matchedRoute.path) !== null && _c !== void 0 ? _c : null;
|
|
28
|
-
// 2. Given a routing state, resolve the different possible scenarios and return the new bot state.
|
|
29
|
-
/**
|
|
30
|
-
* Redirect Scenario:
|
|
31
|
-
* We have matched a redirect route with a given redirection path, so we try to obtain the redirectionRoute with getRouteByPath.
|
|
32
|
-
* 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.
|
|
33
|
-
* It has preference over ignoring retries.
|
|
34
|
-
*/
|
|
35
|
-
if (matchedRoute && matchedRoute.redirect) {
|
|
36
|
-
botState.retries = 0;
|
|
37
|
-
const redirectionRoute = this.getRouteByPath(matchedRoute.redirect);
|
|
38
|
-
if (redirectionRoute) {
|
|
39
|
-
botState.lastRoutePath = matchedRoute.redirect;
|
|
40
|
-
return {
|
|
41
|
-
action: redirectionRoute.action,
|
|
42
|
-
emptyAction: getEmptyAction(redirectionRoute.childRoutes),
|
|
43
|
-
fallbackAction: null,
|
|
44
|
-
botState,
|
|
45
|
-
params,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
botState.lastRoutePath = null;
|
|
49
|
-
return {
|
|
50
|
-
action: null,
|
|
51
|
-
emptyAction: null,
|
|
52
|
-
fallbackAction: getNotFoundAction(input, this.routes),
|
|
53
|
-
botState,
|
|
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 && matchedRoute.ignoreRetry) {
|
|
62
|
-
botState.retries = 0;
|
|
63
|
-
botState.lastRoutePath = matchedRoutePath;
|
|
64
|
-
return {
|
|
65
|
-
action: matchedRoute.action,
|
|
66
|
-
emptyAction: getEmptyAction(matchedRoute.childRoutes),
|
|
67
|
-
fallbackAction: null,
|
|
68
|
-
botState,
|
|
69
|
-
params,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Retry Scenario:
|
|
74
|
-
* We were in a route which had retries enabled, so we check if the number of retries is exceeded.
|
|
75
|
-
* 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.
|
|
76
|
-
*/
|
|
77
|
-
if (isFlowBroken &&
|
|
78
|
-
currentRoute &&
|
|
79
|
-
currentRoute.retry &&
|
|
80
|
-
botState.retries < currentRoute.retry) {
|
|
81
|
-
botState.retries = botState.retries !== 0 ? botState.retries + 1 : 1;
|
|
82
|
-
botState.lastRoutePath = currentRoutePath;
|
|
83
|
-
if (matchedRoute && matchedRoutePath !== NOT_FOUND_PATH) {
|
|
84
|
-
return {
|
|
85
|
-
action: currentRoute.action,
|
|
86
|
-
emptyAction: getEmptyAction(matchedRoute.childRoutes),
|
|
87
|
-
fallbackAction: matchedRoute.action,
|
|
88
|
-
botState,
|
|
89
|
-
params,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
action: (_d = currentRoute.action) !== null && _d !== void 0 ? _d : null,
|
|
94
|
-
emptyAction: getEmptyAction(currentRoute.childRoutes),
|
|
95
|
-
fallbackAction: getNotFoundAction(input, this.routes),
|
|
96
|
-
botState,
|
|
97
|
-
params,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Default Scenario:
|
|
102
|
-
* We have matched a route or not, but we don't need to execute retries logic, so retries stay to 0.
|
|
103
|
-
*/
|
|
104
|
-
botState.retries = 0;
|
|
105
|
-
/**
|
|
106
|
-
* Matching Route Scenario:
|
|
107
|
-
* We have matched a route, so we return the new bot state.
|
|
108
|
-
*/
|
|
109
|
-
if (matchedRoute && matchedRoutePath !== NOT_FOUND_PATH) {
|
|
110
|
-
botState.lastRoutePath = matchedRoutePath;
|
|
111
|
-
return {
|
|
112
|
-
action: (_e = matchedRoute.action) !== null && _e !== void 0 ? _e : null,
|
|
113
|
-
emptyAction: getEmptyAction(matchedRoute.childRoutes),
|
|
114
|
-
fallbackAction: null,
|
|
115
|
-
botState,
|
|
116
|
-
params,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* 404 Scenario (No Route Found):
|
|
121
|
-
* We have not matched any route, so we return the new bot state.
|
|
122
|
-
*/
|
|
123
|
-
botState.lastRoutePath = currentRoutePath;
|
|
124
|
-
return {
|
|
125
|
-
action: null,
|
|
126
|
-
emptyAction: null,
|
|
127
|
-
fallbackAction: getNotFoundAction(input, this.routes),
|
|
128
|
-
params,
|
|
129
|
-
botState,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* 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.
|
|
134
|
-
* IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects
|
|
135
|
-
* */
|
|
136
|
-
getRoute(input, routes, session, lastRoutePath) {
|
|
137
|
-
let params = {};
|
|
138
|
-
const route = routes.find(r => Object.entries(r)
|
|
139
|
-
.filter(([key, _]) => key !== 'action' && key !== 'childRoutes' && key !== 'path')
|
|
140
|
-
.some(([key, value]) => {
|
|
141
|
-
const match = this.matchRoute(r, key, value, input, session, lastRoutePath);
|
|
142
|
-
try {
|
|
143
|
-
if (match !== null && typeof match !== 'boolean' && match.groups) {
|
|
144
|
-
// Strip '[Object: null prototype]' from groups result: https://stackoverflow.com/a/62945609/6237608
|
|
145
|
-
params = Object.assign({}, match.groups);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
catch (e) { }
|
|
149
|
-
return Boolean(match);
|
|
150
|
-
}));
|
|
151
|
-
if (route)
|
|
152
|
-
return { route: cloneObject(route), params };
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Find the route that matches the given path. Path can include concatenations, e.g: 'Flow1/Subflow1.1'.
|
|
157
|
-
* IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects
|
|
158
|
-
* */
|
|
159
|
-
getRouteByPath(path, routeList = this.routes) {
|
|
160
|
-
if (!path)
|
|
161
|
-
return null;
|
|
162
|
-
const [currentPath, ...childPath] = path.split('/');
|
|
163
|
-
for (const route of routeList) {
|
|
164
|
-
// iterate over all routeList
|
|
165
|
-
if (route.path === currentPath) {
|
|
166
|
-
if (route.childRoutes &&
|
|
167
|
-
route.childRoutes.length &&
|
|
168
|
-
childPath.length > 0) {
|
|
169
|
-
// evaluate childroute over next actions
|
|
170
|
-
const computedRoute = this.getRouteByPath(childPath.join('/'), route.childRoutes);
|
|
171
|
-
// IMPORTANT: Returning a new object to avoid modifying dev routes and introduce side effects
|
|
172
|
-
if (computedRoute)
|
|
173
|
-
return cloneObject(computedRoute);
|
|
174
|
-
}
|
|
175
|
-
else if (childPath.length === 0) {
|
|
176
|
-
return cloneObject(route); // last action and found route
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Returns the matched value for a specific route.
|
|
184
|
-
* Matching Props: ('text' | 'payload' | 'intent' | 'type' | 'input' | 'session' | 'request' ...)
|
|
185
|
-
* Matchers: (string: exact match | regex: regular expression match | function: return true)
|
|
186
|
-
* input: user input object, e.g.: {type: 'text', data: 'Hi'}
|
|
187
|
-
* */
|
|
188
|
-
matchRoute(route, prop, matcher, input, session, lastRoutePath) {
|
|
189
|
-
let value = null;
|
|
190
|
-
if (Object.keys(input).indexOf(prop) > -1)
|
|
191
|
-
value = input[prop];
|
|
192
|
-
else if (prop === 'input')
|
|
193
|
-
value = input;
|
|
194
|
-
else if (prop === 'session')
|
|
195
|
-
value = session;
|
|
196
|
-
else if (prop === 'request')
|
|
197
|
-
value = { input, session, lastRoutePath };
|
|
198
|
-
const matched = this.matchValue(matcher, value);
|
|
199
|
-
if (matched) {
|
|
200
|
-
this.routeInspector.routeMatched(route, prop, matcher, value);
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
this.routeInspector.routeNotMatched(route, prop, matcher, value);
|
|
204
|
-
}
|
|
205
|
-
return matched;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Runs the matcher against the given value.
|
|
209
|
-
* If there is a match, it will return a truthy value (true, RegExp result), o.w., it will return a falsy value.
|
|
210
|
-
* */
|
|
211
|
-
matchValue(matcher, value) {
|
|
212
|
-
if (typeof matcher === 'string')
|
|
213
|
-
return value === matcher;
|
|
214
|
-
if (matcher instanceof RegExp) {
|
|
215
|
-
if (value === undefined || value === null)
|
|
216
|
-
return false;
|
|
217
|
-
return matcher.exec(value);
|
|
218
|
-
}
|
|
219
|
-
if (typeof matcher === 'function')
|
|
220
|
-
return matcher(value);
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* It resolves the current state of navigation. Two scenarios:
|
|
225
|
-
* 1. Given a path payload input (__PATH_PAYLOAD__somePath?someParam=someValue), we can resolve the routing state directly from it (using getRouteByPath).
|
|
226
|
-
* 2. Given any other type of input, we resolve the routing state with normal resolution (using getRoute).
|
|
227
|
-
* */
|
|
228
|
-
getRoutingState(input, session, botState) {
|
|
229
|
-
const currentRoute = this.getRouteByPath(botState.lastRoutePath);
|
|
230
|
-
if (currentRoute && botState.lastRoutePath)
|
|
231
|
-
currentRoute.path = botState.lastRoutePath;
|
|
232
|
-
if (typeof input.payload === 'string' && isPathPayload(input.payload)) {
|
|
233
|
-
return this.getRoutingStateFromPathPayload(currentRoute, input.payload);
|
|
234
|
-
}
|
|
235
|
-
return this.getRoutingStateFromInput(currentRoute, input, session);
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* 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.
|
|
239
|
-
* */
|
|
240
|
-
getRoutingStateFromInput(currentRoute, input, session) {
|
|
241
|
-
var _a, _b, _c;
|
|
242
|
-
// get route depending of current ChildRoutes
|
|
243
|
-
if (currentRoute && currentRoute.childRoutes) {
|
|
244
|
-
const routeParams = this.getRoute(input, currentRoute.childRoutes, session, currentRoute.path);
|
|
245
|
-
if (routeParams) {
|
|
246
|
-
return {
|
|
247
|
-
currentRoute,
|
|
248
|
-
matchedRoute: Object.assign(Object.assign({}, routeParams.route), { path: routeParams.route && currentRoute.path
|
|
249
|
-
? `${currentRoute.path}/${routeParams.route.path}`
|
|
250
|
-
: currentRoute.path }),
|
|
251
|
-
params: routeParams.params,
|
|
252
|
-
isFlowBroken: false,
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* we couldn't find a route in the state of the currentRoute childRoutes,
|
|
258
|
-
* so let's find in the general routes
|
|
259
|
-
*/
|
|
260
|
-
const routeParams = this.getRoute(input, this.routes, session, (_a = currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path) !== null && _a !== void 0 ? _a : null);
|
|
261
|
-
const isFlowBroken = Boolean(currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path);
|
|
262
|
-
if (routeParams === null || routeParams === void 0 ? void 0 : routeParams.route) {
|
|
263
|
-
return {
|
|
264
|
-
currentRoute,
|
|
265
|
-
matchedRoute: Object.assign(Object.assign({}, routeParams.route), { path: (_c = (_b = routeParams.route) === null || _b === void 0 ? void 0 : _b.path) !== null && _c !== void 0 ? _c : null }),
|
|
266
|
-
params: routeParams.params,
|
|
267
|
-
isFlowBroken,
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
return {
|
|
271
|
-
currentRoute,
|
|
272
|
-
matchedRoute: null,
|
|
273
|
-
params: {},
|
|
274
|
-
isFlowBroken,
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* 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.
|
|
279
|
-
* */
|
|
280
|
-
getRoutingStateFromPathPayload(currentRoute, pathPayload) {
|
|
281
|
-
const { path, params } = getPathParamsFromPathPayload(pathPayload);
|
|
282
|
-
/**
|
|
283
|
-
* shorthand function to update the matching information given a path
|
|
284
|
-
*/
|
|
285
|
-
const getRoutingStateFromPath = (seekPath) => {
|
|
286
|
-
const matchedRoute = this.getRouteByPath(seekPath);
|
|
287
|
-
if (!matchedRoute) {
|
|
288
|
-
return {
|
|
289
|
-
currentRoute,
|
|
290
|
-
matchedRoute: null,
|
|
291
|
-
params: {},
|
|
292
|
-
isFlowBroken: true,
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
return {
|
|
296
|
-
currentRoute,
|
|
297
|
-
matchedRoute: Object.assign(Object.assign({}, matchedRoute), { path: seekPath }),
|
|
298
|
-
params,
|
|
299
|
-
isFlowBroken: false,
|
|
300
|
-
};
|
|
301
|
-
};
|
|
302
|
-
/**
|
|
303
|
-
* Given a valid path: 'Flow1/Subflow1' we are in one of the two scenarios below.
|
|
304
|
-
*/
|
|
305
|
-
// 1. Received __PATH_PAYLOAD__Subflow2, so we need to first try to concatenate it with Flow1 (lastRoutePath)
|
|
306
|
-
if (currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path) {
|
|
307
|
-
const routingState = getRoutingStateFromPath(`${currentRoute.path}/${path}`);
|
|
308
|
-
if (routingState.matchedRoute)
|
|
309
|
-
return routingState;
|
|
310
|
-
}
|
|
311
|
-
// 2. Received __PATH_PAYLOAD__Flow1/Subflow1, so we can resolve it directly
|
|
312
|
-
return getRoutingStateFromPath(path);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
//# sourceMappingURL=router.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/routing/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAenD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,4BAA4B,EAC5B,aAAa,GACd,MAAM,gBAAgB,CAAA;AAEvB,MAAM,OAAO,MAAM;IAIjB,YACE,MAAe,EACf,iBAA6C,SAAS;QAEtD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,cAAc,GAAG,cAAc,IAAI,IAAI,cAAc,EAAE,CAAA;IAC9D,CAAC;IAED;;;;;;;;;OASG;IAEH,sCAAsC;IACtC,YAAY,CACV,KAAY,EACZ,OAAgB,EAChB,QAAkB;;QAElB,QAAQ,CAAC,OAAO,GAAG,MAAA,QAAQ,CAAC,OAAO,mCAAI,CAAC,CAAA;QAExC,wCAAwC;QACxC,MAAM,EACJ,YAAY,EACZ,YAAY,EACZ,MAAM,EACN,YAAY,GACb,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;QAElD,MAAM,gBAAgB,GAAG,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,IAAI,mCAAI,IAAI,CAAA;QACnD,MAAM,gBAAgB,GAAG,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,IAAI,mCAAI,IAAI,CAAA;QAEnD,mGAAm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M,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;YAClD,IAAI,CAAC,YAAY,EAAE;gBACjB,OAAO;oBACL,YAAY;oBACZ,YAAY,EAAE,IAAI;oBAClB,MAAM,EAAE,EAAE;oBACV,YAAY,EAAE,IAAI;iBACnB,CAAA;aACF;YACD,OAAO;gBACL,YAAY;gBACZ,YAAY,kCAAO,YAAY,KAAE,IAAI,EAAE,QAAQ,GAAE;gBACjD,MAAM;gBACN,YAAY,EAAE,KAAK;aACpB,CAAA;QACH,CAAC,CAAA;QACD;;WAEG;QACH,8GAA8G;QAC9G,IAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,IAAI,EAAE;YACtB,MAAM,YAAY,GAAG,uBAAuB,CAC1C,GAAG,YAAY,CAAC,IAAI,IAAI,IAAI,EAAE,CAC/B,CAAA;YACD,IAAI,YAAY,CAAC,YAAY;gBAAE,OAAO,YAAY,CAAA;SACnD;QACD,4EAA4E;QAC5E,OAAO,uBAAuB,CAAC,IAAc,CAAC,CAAA;IAChD,CAAC;CACF"}
|
package/lib/esm/utils.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const isNode: () => boolean;
|
|
2
|
-
export declare const isBrowser: () => boolean;
|
|
3
|
-
export declare function getWebpackEnvVar(webpackEnvVar: string | false, name: string, defaultValue: string): string;
|
|
4
|
-
export declare const isMobile: (mobileBreakpoint?: number) => boolean;
|
|
5
|
-
export declare function isFunction(o: any): boolean;
|
|
6
|
-
export declare function cloneObject(object: any): any;
|
|
7
|
-
export declare const params2queryString: (params: {
|
|
8
|
-
[key: string]: string;
|
|
9
|
-
}) => string;
|
|
10
|
-
export declare const join: (...segments: string[]) => string;
|
|
11
|
-
export declare const dirname: (path: string) => string;
|
package/lib/esm/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA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AAA;KACzB;IACD,+CAA+C;IAC/C,aAAa;IACb,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IACzC,uCAAuC;IACvC,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAC5D,CAAC,CAAA;AAED,iDAAiD;AACjD,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA"}
|
package/src/constants.ts
DELETED
package/src/core-bot.ts
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { Inspector } from './debug'
|
|
2
|
-
import { getString } from './i18n'
|
|
3
|
-
import {
|
|
4
|
-
BotonicEvent,
|
|
5
|
-
BotRequest,
|
|
6
|
-
BotResponse,
|
|
7
|
-
BotState,
|
|
8
|
-
Locales,
|
|
9
|
-
Route,
|
|
10
|
-
Routes,
|
|
11
|
-
Session,
|
|
12
|
-
} from './models'
|
|
13
|
-
import { BotonicOutputParser } from './output-parser'
|
|
14
|
-
import { loadPlugins, runPlugins } from './plugins'
|
|
15
|
-
import { getComputedRoutes, Router } from './routing'
|
|
16
|
-
|
|
17
|
-
interface CoreBotConfig {
|
|
18
|
-
appId?: string
|
|
19
|
-
defaultDelay?: number
|
|
20
|
-
defaultRoutes?: Route[]
|
|
21
|
-
defaultTyping?: number
|
|
22
|
-
inspector?: Inspector
|
|
23
|
-
locales: Locales
|
|
24
|
-
plugins?: any
|
|
25
|
-
renderer: any
|
|
26
|
-
routes: Routes
|
|
27
|
-
theme?: any
|
|
28
|
-
}
|
|
29
|
-
export class CoreBot {
|
|
30
|
-
appId?: string
|
|
31
|
-
defaultDelay?: number
|
|
32
|
-
defaultRoutes: Route[]
|
|
33
|
-
defaultTyping?: number
|
|
34
|
-
inspector: Inspector
|
|
35
|
-
locales: Locales
|
|
36
|
-
plugins?: Record<string, Plugin>
|
|
37
|
-
renderer: any
|
|
38
|
-
rootElement: any
|
|
39
|
-
router: Router | null
|
|
40
|
-
routes: Routes
|
|
41
|
-
theme?: any
|
|
42
|
-
botonicOutputParser = new BotonicOutputParser()
|
|
43
|
-
|
|
44
|
-
constructor({
|
|
45
|
-
// TODO: Receives dataProvider
|
|
46
|
-
renderer,
|
|
47
|
-
routes,
|
|
48
|
-
locales,
|
|
49
|
-
theme,
|
|
50
|
-
plugins,
|
|
51
|
-
appId,
|
|
52
|
-
defaultTyping,
|
|
53
|
-
defaultDelay,
|
|
54
|
-
defaultRoutes,
|
|
55
|
-
inspector,
|
|
56
|
-
}: CoreBotConfig) {
|
|
57
|
-
this.renderer = renderer
|
|
58
|
-
this.plugins = loadPlugins(plugins)
|
|
59
|
-
this.theme = theme || {}
|
|
60
|
-
this.defaultTyping =
|
|
61
|
-
typeof defaultTyping !== 'undefined' ? defaultTyping : 0.6
|
|
62
|
-
this.defaultDelay = typeof defaultDelay !== 'undefined' ? defaultDelay : 0.4
|
|
63
|
-
this.locales = locales
|
|
64
|
-
if (appId) {
|
|
65
|
-
this.appId = appId
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
this.rootElement = null
|
|
69
|
-
this.inspector = inspector || new Inspector()
|
|
70
|
-
this.routes = routes
|
|
71
|
-
this.defaultRoutes = defaultRoutes || []
|
|
72
|
-
this.router =
|
|
73
|
-
this.routes instanceof Function
|
|
74
|
-
? null
|
|
75
|
-
: new Router(
|
|
76
|
-
[...this.routes, ...this.defaultRoutes],
|
|
77
|
-
this.inspector.routeInspector
|
|
78
|
-
)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
getString(id: string, botState: BotState): string {
|
|
82
|
-
if (!botState.locale) {
|
|
83
|
-
console.error('Locale is not defined')
|
|
84
|
-
return ''
|
|
85
|
-
}
|
|
86
|
-
return getString(this.locales, botState.locale, id)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
setLocale(locale: string, botState: BotState): void {
|
|
90
|
-
botState.locale = locale
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async input({
|
|
94
|
-
input,
|
|
95
|
-
session,
|
|
96
|
-
botState,
|
|
97
|
-
dataProvider,
|
|
98
|
-
}: BotRequest): Promise<BotResponse> {
|
|
99
|
-
if (!botState?.locale) botState.locale = 'en'
|
|
100
|
-
if (this.plugins) {
|
|
101
|
-
await runPlugins(
|
|
102
|
-
this.plugins,
|
|
103
|
-
'pre',
|
|
104
|
-
input,
|
|
105
|
-
session,
|
|
106
|
-
botState,
|
|
107
|
-
undefined,
|
|
108
|
-
undefined,
|
|
109
|
-
dataProvider
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (this.routes instanceof Function) {
|
|
114
|
-
this.router = new Router(
|
|
115
|
-
[
|
|
116
|
-
...(await getComputedRoutes(this.routes, {
|
|
117
|
-
input,
|
|
118
|
-
session,
|
|
119
|
-
botState,
|
|
120
|
-
})),
|
|
121
|
-
...this.defaultRoutes,
|
|
122
|
-
],
|
|
123
|
-
this.inspector.routeInspector
|
|
124
|
-
)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const output = (this.router as Router).processInput(
|
|
128
|
-
input,
|
|
129
|
-
session,
|
|
130
|
-
botState
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
const request = {
|
|
134
|
-
getString: stringId => this.getString(stringId, botState),
|
|
135
|
-
setLocale: locale => this.setLocale(locale, botState),
|
|
136
|
-
session: session || {},
|
|
137
|
-
params: output.params || {},
|
|
138
|
-
input: input,
|
|
139
|
-
plugins: this.plugins,
|
|
140
|
-
defaultTyping: this.defaultTyping,
|
|
141
|
-
defaultDelay: this.defaultDelay,
|
|
142
|
-
botState,
|
|
143
|
-
dataProvider,
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const response = await this.renderer({
|
|
147
|
-
request,
|
|
148
|
-
actions: [output.fallbackAction, output.action, output.emptyAction],
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
const messageEvents: Partial<BotonicEvent>[] = this.botonicOutputParser.xmlToMessageEvents(
|
|
152
|
-
response
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
botState.lastRoutePath = output.botState.lastRoutePath // not needed if updated below
|
|
156
|
-
|
|
157
|
-
if (this.plugins) {
|
|
158
|
-
await runPlugins(
|
|
159
|
-
this.plugins,
|
|
160
|
-
'post',
|
|
161
|
-
input,
|
|
162
|
-
session, // passing output.session instead
|
|
163
|
-
botState, // passing output.botState instead
|
|
164
|
-
response,
|
|
165
|
-
messageEvents,
|
|
166
|
-
dataProvider
|
|
167
|
-
)
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
botState.isFirstInteraction = false
|
|
171
|
-
|
|
172
|
-
return {
|
|
173
|
-
input, // Delete
|
|
174
|
-
response, // xml/rendered react for actions (not needed)
|
|
175
|
-
messageEvents, // xml to Botonic Events
|
|
176
|
-
session, // to be output.session
|
|
177
|
-
botState, // to be output.botState
|
|
178
|
-
dataProvider, // no need to return it
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
package/src/debug/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './inspector'
|
package/src/debug/inspector.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { Route, RouteMatcher } from '../models'
|
|
2
|
-
export class RouteInspector {
|
|
3
|
-
routeMatched(
|
|
4
|
-
_route: Route,
|
|
5
|
-
_routeKey: string,
|
|
6
|
-
_routeValue: RouteMatcher,
|
|
7
|
-
_input: any
|
|
8
|
-
): void {}
|
|
9
|
-
routeNotMatched(
|
|
10
|
-
_route: Route,
|
|
11
|
-
_routeKey: string,
|
|
12
|
-
_routeValue: RouteMatcher,
|
|
13
|
-
_input: any
|
|
14
|
-
): void {}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class FocusRouteInspector extends RouteInspector {
|
|
18
|
-
focusRoutePaths: string[] | null
|
|
19
|
-
focusOnMatches: boolean
|
|
20
|
-
constructor() {
|
|
21
|
-
super()
|
|
22
|
-
this.focusRoutePaths = null
|
|
23
|
-
this.focusOnMatches = false
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
focusOnlyOnRoutes(focusRoutePaths: string[]): this {
|
|
27
|
-
this.focusRoutePaths = focusRoutePaths
|
|
28
|
-
return this
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
focusOnlyOnMatches(): this {
|
|
32
|
-
this.focusOnMatches = true
|
|
33
|
-
return this
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
_isOnFocus(route: Route): boolean {
|
|
37
|
-
if (this.focusRoutePaths === null) {
|
|
38
|
-
return true
|
|
39
|
-
}
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
return this.focusRoutePaths.includes(route.path)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export class LogRouteInspector extends FocusRouteInspector {
|
|
46
|
-
routeMatched(
|
|
47
|
-
route: Route,
|
|
48
|
-
routeKey: string,
|
|
49
|
-
routeValue: RouteMatcher,
|
|
50
|
-
inputValue: string
|
|
51
|
-
): void {
|
|
52
|
-
if (!this._isOnFocus(route)) {
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
this._log(
|
|
56
|
-
`Route ${this._routeName(route)} selected ` +
|
|
57
|
-
`because Input.${routeKey} (${inputValue}) matched '${routeValue}'`
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
routeNotMatched(
|
|
63
|
-
route: Route,
|
|
64
|
-
routeKey: string,
|
|
65
|
-
routeValue: RouteMatcher,
|
|
66
|
-
inputValue: string
|
|
67
|
-
): void {
|
|
68
|
-
if (!this._isOnFocus(route) || this.focusOnMatches) {
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
this._log(
|
|
72
|
-
`Route ${this._routeName(route)} not selected ` +
|
|
73
|
-
`because Input.${routeKey} (${inputValue}) did not match '${routeValue}'`
|
|
74
|
-
)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
_routeName(obj: Route): string {
|
|
78
|
-
let name = obj.path || '<<no path defined>>'
|
|
79
|
-
if (obj.action) {
|
|
80
|
-
name = `'${name}' (to action '${obj.action.name}')`
|
|
81
|
-
}
|
|
82
|
-
if (obj.redirect) {
|
|
83
|
-
name = `'${name}' (with redirect to '${obj.redirect}')`
|
|
84
|
-
}
|
|
85
|
-
return name as string
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
_log(message: string, ...optionalParams: string[]): void {
|
|
89
|
-
console.log(message, ...optionalParams)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export class Inspector {
|
|
94
|
-
routeInspector: RouteInspector
|
|
95
|
-
constructor(routeInspector: RouteInspector | undefined = undefined) {
|
|
96
|
-
this.routeInspector = routeInspector || new RouteInspector()
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
getRouteInspector(): RouteInspector {
|
|
100
|
-
return this.routeInspector
|
|
101
|
-
}
|
|
102
|
-
}
|