@botonic/core 1.0.0-dev.0 → 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/src/lib/utils/index.d.ts +7 -0
- package/{lib/esm/utils.js → src/lib/utils/index.js} +6 -34
- package/src/lib/utils/index.js.map +1 -0
- package/lib/cjs/constants.d.ts +0 -15
- package/lib/cjs/constants.js +0 -19
- package/lib/cjs/constants.js.map +0 -1
- package/lib/cjs/core-bot.d.ts +0 -33
- package/lib/cjs/core-bot.js +0 -85
- 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 -9
- 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/errors.d.ts +0 -5
- package/lib/cjs/errors.js +0 -11
- package/lib/cjs/errors.js.map +0 -1
- package/lib/cjs/handoff.d.ts +0 -67
- package/lib/cjs/handoff.js +0 -183
- 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 -166
- package/lib/cjs/index.js +0 -58
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/models/events/connections/index.d.ts +0 -9
- package/lib/cjs/models/events/connections/index.js +0 -9
- package/lib/cjs/models/events/connections/index.js.map +0 -1
- package/lib/cjs/models/events/index.d.ts +0 -21
- package/lib/cjs/models/events/index.js +0 -11
- package/lib/cjs/models/events/index.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 -30
- package/lib/cjs/models/events/message/index.js +0 -32
- 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/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/user.d.ts +0 -10
- package/lib/cjs/models/user.js +0 -3
- package/lib/cjs/models/user.js.map +0 -1
- package/lib/cjs/output-parser/factory.d.ts +0 -4
- package/lib/cjs/output-parser/factory.js +0 -33
- package/lib/cjs/output-parser/factory.js.map +0 -1
- package/lib/cjs/output-parser/index.d.ts +0 -16
- package/lib/cjs/output-parser/index.js +0 -37
- package/lib/cjs/output-parser/index.js.map +0 -1
- package/lib/cjs/output-parser/parsers.d.ts +0 -28
- package/lib/cjs/output-parser/parsers.js +0 -138
- package/lib/cjs/output-parser/parsers.js.map +0 -1
- package/lib/cjs/output-parser/util.d.ts +0 -2
- package/lib/cjs/output-parser/util.js +0 -14
- package/lib/cjs/output-parser/util.js.map +0 -1
- package/lib/cjs/plugins.d.ts +0 -7
- package/lib/cjs/plugins.js +0 -45
- package/lib/cjs/plugins.js.map +0 -1
- package/lib/cjs/router.d.ts +0 -35
- package/lib/cjs/router.js +0 -262
- package/lib/cjs/router.js.map +0 -1
- package/lib/cjs/utils.d.ts +0 -10
- package/lib/cjs/utils.js +0 -84
- package/lib/cjs/utils.js.map +0 -1
- package/lib/esm/constants.d.ts +0 -15
- package/lib/esm/constants.js +0 -16
- package/lib/esm/constants.js.map +0 -1
- package/lib/esm/core-bot.d.ts +0 -33
- package/lib/esm/core-bot.js +0 -81
- 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/errors.d.ts +0 -5
- package/lib/esm/errors.js +0 -7
- package/lib/esm/errors.js.map +0 -1
- package/lib/esm/handoff.d.ts +0 -67
- package/lib/esm/handoff.js +0 -170
- 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 -166
- package/lib/esm/index.js +0 -49
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/models/events/connections/index.d.ts +0 -9
- package/lib/esm/models/events/connections/index.js +0 -6
- package/lib/esm/models/events/connections/index.js.map +0 -1
- package/lib/esm/models/events/index.d.ts +0 -21
- package/lib/esm/models/events/index.js +0 -8
- package/lib/esm/models/events/index.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 -30
- package/lib/esm/models/events/message/index.js +0 -29
- 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/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/user.d.ts +0 -10
- package/lib/esm/models/user.js +0 -2
- package/lib/esm/models/user.js.map +0 -1
- package/lib/esm/output-parser/factory.d.ts +0 -4
- package/lib/esm/output-parser/factory.js +0 -29
- package/lib/esm/output-parser/factory.js.map +0 -1
- package/lib/esm/output-parser/index.d.ts +0 -16
- package/lib/esm/output-parser/index.js +0 -33
- package/lib/esm/output-parser/index.js.map +0 -1
- package/lib/esm/output-parser/parsers.d.ts +0 -28
- package/lib/esm/output-parser/parsers.js +0 -123
- package/lib/esm/output-parser/parsers.js.map +0 -1
- package/lib/esm/output-parser/util.d.ts +0 -2
- package/lib/esm/output-parser/util.js +0 -9
- package/lib/esm/output-parser/util.js.map +0 -1
- package/lib/esm/plugins.d.ts +0 -7
- package/lib/esm/plugins.js +0 -40
- package/lib/esm/plugins.js.map +0 -1
- package/lib/esm/router.d.ts +0 -35
- package/lib/esm/router.js +0 -258
- package/lib/esm/router.js.map +0 -1
- package/lib/esm/utils.d.ts +0 -10
- package/lib/esm/utils.js.map +0 -1
- package/src/constants.ts +0 -15
- package/src/core-bot.ts +0 -144
- package/src/debug/index.ts +0 -6
- package/src/debug/inspector.ts +0 -102
- package/src/errors.ts +0 -11
- package/src/handoff.ts +0 -268
- package/src/hubtype-service.ts +0 -266
- package/src/i18n.ts +0 -12
- package/src/index.ts +0 -233
- package/src/models/events/connections/index.ts +0 -11
- package/src/models/events/index.ts +0 -39
- 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 -37
- package/src/models/events/message/location.ts +0 -7
- package/src/models/events/message/media.ts +0 -28
- 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/user.ts +0 -10
- package/src/output-parser/factory.ts +0 -40
- package/src/output-parser/index.ts +0 -38
- package/src/output-parser/parsers.ts +0 -190
- package/src/output-parser/util.ts +0 -8
- package/src/plugins.ts +0 -49
- package/src/router.ts +0 -316
- package/src/utils.ts +0 -84
package/lib/esm/router.js
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
import { RouteInspector } from './debug/inspector';
|
|
2
|
-
import { NoMatchingRouteError } from './errors';
|
|
3
|
-
import { isFunction } from './utils';
|
|
4
|
-
export class Router {
|
|
5
|
-
/**
|
|
6
|
-
* @param {Route[]} routes
|
|
7
|
-
* @param routeInspector
|
|
8
|
-
*/
|
|
9
|
-
constructor(routes, routeInspector = undefined) {
|
|
10
|
-
this.routes = routes;
|
|
11
|
-
this.routeInspector = routeInspector || new RouteInspector();
|
|
12
|
-
}
|
|
13
|
-
// eslint-disable-next-line complexity
|
|
14
|
-
processInput(input, session = {}, lastRoutePath = null) {
|
|
15
|
-
let routeParams = {};
|
|
16
|
-
if (input.payload && input.payload.includes('__PATH_PAYLOAD__')) {
|
|
17
|
-
const pathParam = input.payload.split('__PATH_PAYLOAD__');
|
|
18
|
-
routeParams.route = this.getRouteByPath(pathParam[1], this.routes);
|
|
19
|
-
}
|
|
20
|
-
const pathParams = this.getOnFinishParams(input);
|
|
21
|
-
let brokenFlow = false;
|
|
22
|
-
const lastRoute = this.getRouteByPath(lastRoutePath, this.routes);
|
|
23
|
-
if (!lastRoute && input.path)
|
|
24
|
-
routeParams.route = this.getRouteByPath(input.path, this.routes);
|
|
25
|
-
if (lastRoute && lastRoute.childRoutes && !routeParams.route)
|
|
26
|
-
//get route depending of current ChildRoute
|
|
27
|
-
routeParams = this.getRoute(input, lastRoute.childRoutes, session, lastRoutePath);
|
|
28
|
-
if (!routeParams || !Object.keys(routeParams).length) {
|
|
29
|
-
/*
|
|
30
|
-
we couldn't find a route in the state of the lastRoute, so let's find in
|
|
31
|
-
the general conf.route
|
|
32
|
-
*/
|
|
33
|
-
brokenFlow = Boolean(lastRoutePath);
|
|
34
|
-
routeParams = this.getRoute(input, this.routes, session, lastRoutePath);
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
if (pathParams) {
|
|
38
|
-
const searchParams = new URLSearchParams(pathParams);
|
|
39
|
-
for (const [key, value] of searchParams) {
|
|
40
|
-
routeParams.params
|
|
41
|
-
? (routeParams.params[key] = value)
|
|
42
|
-
: (routeParams.params = { [key]: value });
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
catch (e) { }
|
|
47
|
-
if (routeParams && Object.keys(routeParams).length) {
|
|
48
|
-
//get in childRoute if one has path ''
|
|
49
|
-
let defaultAction;
|
|
50
|
-
if (routeParams.route) {
|
|
51
|
-
if (!routeParams.route.path &&
|
|
52
|
-
routeParams.route.childRoutes &&
|
|
53
|
-
routeParams.route.childRoutes.length) {
|
|
54
|
-
defaultAction = this.getRoute({ path: '' }, routeParams.route.childRoutes, session, lastRoutePath);
|
|
55
|
-
}
|
|
56
|
-
if ('action' in routeParams.route) {
|
|
57
|
-
if (brokenFlow &&
|
|
58
|
-
routeParams.route.ignoreRetry != true &&
|
|
59
|
-
lastRoute &&
|
|
60
|
-
(session.__retries || 0) < (lastRoute.retry || 0) &&
|
|
61
|
-
routeParams.route.path != lastRoute.action) {
|
|
62
|
-
session.__retries = session.__retries ? session.__retries + 1 : 1;
|
|
63
|
-
// The flow was broken, but we want to recover it
|
|
64
|
-
return {
|
|
65
|
-
action: routeParams.route.action,
|
|
66
|
-
params: routeParams.params,
|
|
67
|
-
retryAction: lastRoute ? lastRoute.action : null,
|
|
68
|
-
defaultAction: defaultAction ? defaultAction.route.action : null,
|
|
69
|
-
lastRoutePath: lastRoutePath,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
session.__retries = 0;
|
|
74
|
-
if (lastRoutePath && !brokenFlow)
|
|
75
|
-
lastRoutePath = `${lastRoutePath}/${routeParams.route.path}`;
|
|
76
|
-
else
|
|
77
|
-
lastRoutePath = routeParams.route.path;
|
|
78
|
-
return {
|
|
79
|
-
action: routeParams.route.action,
|
|
80
|
-
params: routeParams.params,
|
|
81
|
-
retryAction: null,
|
|
82
|
-
defaultAction: defaultAction ? defaultAction.route.action : null,
|
|
83
|
-
lastRoutePath: lastRoutePath,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
else if (defaultAction) {
|
|
88
|
-
return {
|
|
89
|
-
action: defaultAction.route.action,
|
|
90
|
-
params: defaultAction.params,
|
|
91
|
-
lastRoutePath: lastRoutePath,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
else if ('redirect' in routeParams.route) {
|
|
95
|
-
lastRoutePath = routeParams.route.redirect;
|
|
96
|
-
const redirectRoute = this.getRouteByPath(lastRoutePath, this.routes);
|
|
97
|
-
if (redirectRoute) {
|
|
98
|
-
return {
|
|
99
|
-
action: redirectRoute.action,
|
|
100
|
-
params: redirectRoute.params,
|
|
101
|
-
lastRoutePath: lastRoutePath,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const notFound = this.getRouteByPath('404', this.routes);
|
|
108
|
-
if (!notFound)
|
|
109
|
-
throw new NoMatchingRouteError(input);
|
|
110
|
-
if (lastRoute && (session.__retries || 0) < (lastRoute.retry || 0)) {
|
|
111
|
-
session.__retries = session.__retries ? session.__retries + 1 : 1;
|
|
112
|
-
return {
|
|
113
|
-
action: notFound.action,
|
|
114
|
-
params: {},
|
|
115
|
-
retryAction: lastRoute.action,
|
|
116
|
-
lastRoutePath: lastRoutePath,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
this.lastRoutePath = null;
|
|
121
|
-
session.__retries = 0;
|
|
122
|
-
return {
|
|
123
|
-
action: notFound.action,
|
|
124
|
-
params: {},
|
|
125
|
-
retryAction: null,
|
|
126
|
-
lastRoutePath: lastRoutePath,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
getOnFinishParams(input) {
|
|
131
|
-
try {
|
|
132
|
-
if (!input.payload) {
|
|
133
|
-
return undefined;
|
|
134
|
-
}
|
|
135
|
-
const params = input.payload.split('__PATH_PAYLOAD__');
|
|
136
|
-
if (params.length < 2) {
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
139
|
-
const pathParams = params[1].split('?');
|
|
140
|
-
if (pathParams.length > 0) {
|
|
141
|
-
input.path = pathParams[0];
|
|
142
|
-
delete input.payload;
|
|
143
|
-
}
|
|
144
|
-
if (pathParams.length > 1) {
|
|
145
|
-
return pathParams[1];
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
catch (e) {
|
|
149
|
-
console.error('ERROR getOnFinishParams', e);
|
|
150
|
-
}
|
|
151
|
-
return undefined;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* @return {null|RouteParams}
|
|
155
|
-
*/
|
|
156
|
-
getRoute(input, routes, session, lastRoutePath) {
|
|
157
|
-
const computedRoutes = isFunction(routes)
|
|
158
|
-
? // @ts-ignore
|
|
159
|
-
routes({ input, session, lastRoutePath })
|
|
160
|
-
: routes;
|
|
161
|
-
/* Find the route that matches the given input, if it match with some of the entries,
|
|
162
|
-
return the whole Route of the entry with optional params captured if matcher was a regex */
|
|
163
|
-
/** @type {{ [key: string]: string }}*/
|
|
164
|
-
let params = {};
|
|
165
|
-
const route = computedRoutes.find(r => Object.entries(r)
|
|
166
|
-
.filter(([key, _]) => key != 'action' && key != 'childRoutes')
|
|
167
|
-
.some(([key, value]) => {
|
|
168
|
-
const match = this.matchRoute(r, key, value, input, session, lastRoutePath);
|
|
169
|
-
try {
|
|
170
|
-
params = match.groups;
|
|
171
|
-
}
|
|
172
|
-
catch (e) { }
|
|
173
|
-
return Boolean(match);
|
|
174
|
-
}));
|
|
175
|
-
if (route) {
|
|
176
|
-
return { route, params };
|
|
177
|
-
}
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
getRouteByPath(path, routeList = null) {
|
|
181
|
-
if (!path)
|
|
182
|
-
return null;
|
|
183
|
-
let route = null;
|
|
184
|
-
routeList = routeList || this.routes;
|
|
185
|
-
const [currentPath, ...childPath] = path.split('/');
|
|
186
|
-
if (Array.isArray(routeList)) {
|
|
187
|
-
for (const r of routeList) {
|
|
188
|
-
//iterate over all routeList
|
|
189
|
-
if (r.path == currentPath) {
|
|
190
|
-
route = r;
|
|
191
|
-
if (r.childRoutes && r.childRoutes.length && childPath.length > 0) {
|
|
192
|
-
//evaluate childroute over next actions
|
|
193
|
-
route = this.getRouteByPath(childPath.join('/'), r.childRoutes);
|
|
194
|
-
if (route)
|
|
195
|
-
return route;
|
|
196
|
-
}
|
|
197
|
-
else if (childPath.length === 0)
|
|
198
|
-
return route; //last action and found route
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* @return {Params|boolean}
|
|
206
|
-
*/
|
|
207
|
-
matchRoute(route, prop, matcher, input, session, lastRoutePath) {
|
|
208
|
-
/*
|
|
209
|
-
prop: ('text' | 'payload' | 'intent' | 'type' | 'input' | 'session' | 'request' ...)
|
|
210
|
-
matcher: (string: exact match | regex: regular expression match | function: return true)
|
|
211
|
-
input: user input object, ex: {type: 'text', data: 'Hi'}
|
|
212
|
-
*/
|
|
213
|
-
/** @type {any} */
|
|
214
|
-
let value = '';
|
|
215
|
-
if (Object.keys(input).indexOf(prop) > -1)
|
|
216
|
-
value = input[prop];
|
|
217
|
-
if (prop === 'text') {
|
|
218
|
-
if (input.type === 'text')
|
|
219
|
-
value = input.data;
|
|
220
|
-
}
|
|
221
|
-
else if (prop === 'input')
|
|
222
|
-
value = input;
|
|
223
|
-
else if (prop === 'session')
|
|
224
|
-
value = session;
|
|
225
|
-
else if (prop === 'request')
|
|
226
|
-
value = { input, session, lastRoutePath };
|
|
227
|
-
const matched = this.matchValue(matcher, value);
|
|
228
|
-
if (matched) {
|
|
229
|
-
this.routeInspector.routeMatched(route, prop, matcher, value);
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
this.routeInspector.routeNotMatched(route, prop, matcher, value);
|
|
233
|
-
}
|
|
234
|
-
return matched;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
*
|
|
238
|
-
* @return {*|boolean|Params}
|
|
239
|
-
*/
|
|
240
|
-
matchValue(matcher, value) {
|
|
241
|
-
if (typeof matcher === 'string') {
|
|
242
|
-
// TODO should this be === to avoid matching '' with undefined?
|
|
243
|
-
return value == matcher;
|
|
244
|
-
}
|
|
245
|
-
if (matcher instanceof RegExp) {
|
|
246
|
-
// check if undefined to avoid conversion to 'undefined'
|
|
247
|
-
if (value === undefined) {
|
|
248
|
-
return false;
|
|
249
|
-
}
|
|
250
|
-
return Boolean(matcher.exec(value));
|
|
251
|
-
}
|
|
252
|
-
if (typeof matcher === 'function') {
|
|
253
|
-
return matcher(value);
|
|
254
|
-
}
|
|
255
|
-
return false;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
//# sourceMappingURL=router.js.map
|
package/lib/esm/router.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAE/C,OAAO,EAAE,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KAAU;QAEV,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,+DAA+D;YAC/D,OAAO,KAAK,IAAI,OAAO,CAAA;SACxB;QACD,IAAI,OAAO,YAAY,MAAM,EAAE;YAC7B,wDAAwD;YACxD,IAAI,KAAK,KAAK,SAAS,EAAE;gBACvB,OAAO,KAAK,CAAA;aACb;YACD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;SACpC;QACD,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;YACjC,OAAO,OAAO,CAAC,KAAK,CAAC,CAAA;SACtB;QACD,OAAO,KAAK,CAAA;IACd,CAAC;CACF"}
|
package/lib/esm/utils.d.ts
DELETED
|
@@ -1,10 +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 const params2queryString: (params: {
|
|
7
|
-
[key: string]: string;
|
|
8
|
-
}) => string;
|
|
9
|
-
export declare const join: (...segments: string[]) => string;
|
|
10
|
-
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,MAAM,CAAC,MAAM,MAAM,GAAG,GAAY,EAAE;IAClC,aAAa;IACb,OAAO,OAAO,OAAO,KAAK,WAAW;QACnC,CAAC,CAAC,aAAa;YACb,OAAO;QACT,CAAC,CAAC,OAAO,OAAO,KAAK,WAAW;YAC5B,OAAO,CAAC,QAAQ,KAAK,IAAI;YACzB,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,IAAI,CAAA;AACtC,CAAC,CAAA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CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA"}
|
package/src/constants.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export const Providers = Object.freeze({
|
|
2
|
-
Messaging: {
|
|
3
|
-
FACEBOOK: 'facebook',
|
|
4
|
-
GENERIC: 'generic',
|
|
5
|
-
IMBEE: 'imbee',
|
|
6
|
-
INTERCOM: 'intercom',
|
|
7
|
-
SMOOCH_WEB: 'smooch_web',
|
|
8
|
-
SMOOCH: 'smooch',
|
|
9
|
-
TELEGRAM: 'telegram',
|
|
10
|
-
TWITTER: 'twitter',
|
|
11
|
-
WEBCHAT: 'webchat',
|
|
12
|
-
WECHAT: 'wechat',
|
|
13
|
-
WHATSAPP: 'whatsapp',
|
|
14
|
-
},
|
|
15
|
-
})
|
package/src/core-bot.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { Inspector } from './debug/inspector'
|
|
2
|
-
import { getString } from './i18n'
|
|
3
|
-
import { BotRequest, BotResponse, Locales, Routes, Session } from './index'
|
|
4
|
-
import { BotonicEvent } from './models/events'
|
|
5
|
-
import { BotonicOutputParser } from './output-parser'
|
|
6
|
-
import { loadPlugins, runPlugins } from './plugins'
|
|
7
|
-
import { Router } from './router'
|
|
8
|
-
import { isFunction } from './utils'
|
|
9
|
-
|
|
10
|
-
interface CoreBotConfig {
|
|
11
|
-
appId?: string
|
|
12
|
-
defaultDelay?: number
|
|
13
|
-
defaultRoutes?: Routes
|
|
14
|
-
defaultTyping?: number
|
|
15
|
-
inspector?: Inspector
|
|
16
|
-
locales: Locales
|
|
17
|
-
plugins?: any
|
|
18
|
-
renderer: any
|
|
19
|
-
routes: Routes
|
|
20
|
-
theme?: any
|
|
21
|
-
}
|
|
22
|
-
export class CoreBot {
|
|
23
|
-
appId?: string
|
|
24
|
-
defaultDelay?: number
|
|
25
|
-
defaultRoutes?: Routes
|
|
26
|
-
defaultTyping?: number
|
|
27
|
-
inspector?: Inspector
|
|
28
|
-
locales: Locales
|
|
29
|
-
plugins?: Record<string, Plugin>
|
|
30
|
-
renderer: any
|
|
31
|
-
rootElement: any
|
|
32
|
-
router: any
|
|
33
|
-
routes: Routes
|
|
34
|
-
theme?: any
|
|
35
|
-
|
|
36
|
-
constructor({
|
|
37
|
-
renderer,
|
|
38
|
-
routes,
|
|
39
|
-
locales,
|
|
40
|
-
theme,
|
|
41
|
-
plugins,
|
|
42
|
-
appId,
|
|
43
|
-
defaultTyping,
|
|
44
|
-
defaultDelay,
|
|
45
|
-
defaultRoutes,
|
|
46
|
-
inspector,
|
|
47
|
-
}: CoreBotConfig) {
|
|
48
|
-
this.renderer = renderer
|
|
49
|
-
this.plugins = loadPlugins(plugins)
|
|
50
|
-
this.theme = theme || {}
|
|
51
|
-
this.defaultTyping =
|
|
52
|
-
typeof defaultTyping !== 'undefined' ? defaultTyping : 0.6
|
|
53
|
-
this.defaultDelay = typeof defaultDelay !== 'undefined' ? defaultDelay : 0.4
|
|
54
|
-
this.locales = locales
|
|
55
|
-
if (appId) {
|
|
56
|
-
this.appId = appId
|
|
57
|
-
return
|
|
58
|
-
}
|
|
59
|
-
this.rootElement = null
|
|
60
|
-
this.inspector = inspector || new Inspector()
|
|
61
|
-
this.routes = routes
|
|
62
|
-
this.defaultRoutes = defaultRoutes || []
|
|
63
|
-
this.router = isFunction(this.routes)
|
|
64
|
-
? null
|
|
65
|
-
: new Router(
|
|
66
|
-
// @ts-ignore
|
|
67
|
-
[...this.routes, ...this.defaultRoutes],
|
|
68
|
-
this.inspector.routeInspector
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
getString(id: string, session: Session): string {
|
|
73
|
-
// @ts-ignore
|
|
74
|
-
return getString(this.locales, session.__locale, id)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
setLocale(locale: string, session: Session): void {
|
|
78
|
-
session.__locale = locale
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async input({
|
|
82
|
-
input,
|
|
83
|
-
session,
|
|
84
|
-
lastRoutePath,
|
|
85
|
-
}: BotRequest): Promise<BotResponse> {
|
|
86
|
-
session = session || {}
|
|
87
|
-
if (!session.__locale) session.__locale = 'en'
|
|
88
|
-
|
|
89
|
-
if (this.plugins) {
|
|
90
|
-
await runPlugins(this.plugins, 'pre', input, session, lastRoutePath)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (isFunction(this.routes)) {
|
|
94
|
-
this.router = new Router(
|
|
95
|
-
[
|
|
96
|
-
// @ts-ignore
|
|
97
|
-
...(await this.routes({ input, session, lastRoutePath })),
|
|
98
|
-
// @ts-ignore
|
|
99
|
-
...this.defaultRoutes,
|
|
100
|
-
],
|
|
101
|
-
// @ts-ignore
|
|
102
|
-
this.inspector.routeInspector
|
|
103
|
-
)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const output = this.router.processInput(input, session, lastRoutePath)
|
|
107
|
-
|
|
108
|
-
const request = {
|
|
109
|
-
getString: stringId => this.getString(stringId, session),
|
|
110
|
-
setLocale: locale => this.setLocale(locale, session),
|
|
111
|
-
session: session || {},
|
|
112
|
-
params: output.params || {},
|
|
113
|
-
input: input,
|
|
114
|
-
plugins: this.plugins,
|
|
115
|
-
defaultTyping: this.defaultTyping,
|
|
116
|
-
defaultDelay: this.defaultDelay,
|
|
117
|
-
lastRoutePath,
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const actions = [output.action, output.retryAction, output.defaultAction]
|
|
121
|
-
|
|
122
|
-
const response = await this.renderer({ request, actions })
|
|
123
|
-
let parsedResponse: Partial<BotonicEvent>[] | null = null
|
|
124
|
-
try {
|
|
125
|
-
parsedResponse = new BotonicOutputParser().xmlToMessageEvents(response)
|
|
126
|
-
} catch (e) {}
|
|
127
|
-
|
|
128
|
-
lastRoutePath = output.lastRoutePath
|
|
129
|
-
if (this.plugins) {
|
|
130
|
-
await runPlugins(
|
|
131
|
-
this.plugins,
|
|
132
|
-
'post',
|
|
133
|
-
input,
|
|
134
|
-
session,
|
|
135
|
-
lastRoutePath,
|
|
136
|
-
response,
|
|
137
|
-
parsedResponse
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
session.is_first_interaction = false
|
|
142
|
-
return { input, response, parsedResponse, session, lastRoutePath }
|
|
143
|
-
}
|
|
144
|
-
}
|
package/src/debug/index.ts
DELETED
package/src/debug/inspector.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { Input, Route, RouteMatcher } from '../index'
|
|
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
|
-
}
|
package/src/errors.ts
DELETED