@botonic/core 1.0.0-dev.0 → 1.0.0-dev.2
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/cjs/constants.d.ts +4 -15
- package/lib/cjs/constants.js +5 -16
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/core-bot.d.ts +12 -9
- package/lib/cjs/core-bot.js +54 -43
- package/lib/cjs/core-bot.js.map +1 -1
- package/lib/cjs/debug/index.d.ts +1 -1
- package/lib/cjs/debug/index.js +2 -6
- package/lib/cjs/debug/index.js.map +1 -1
- package/lib/cjs/debug/inspector.d.ts +1 -1
- package/lib/cjs/handoff.d.ts +5 -5
- package/lib/cjs/handoff.js +13 -10
- package/lib/cjs/handoff.js.map +1 -1
- package/lib/cjs/hubtype-service.d.ts +4 -4
- package/lib/cjs/hubtype-service.js +1 -1
- package/lib/cjs/hubtype-service.js.map +1 -1
- package/lib/cjs/i18n.d.ts +1 -1
- package/lib/cjs/index.d.ts +8 -163
- package/lib/cjs/index.js +8 -51
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/models/bot-state.d.ts +11 -0
- package/lib/cjs/models/bot-state.js +3 -0
- package/lib/cjs/models/bot-state.js.map +1 -0
- package/lib/cjs/models/channels.d.ts +9 -0
- package/lib/cjs/models/channels.js +14 -0
- package/lib/cjs/models/channels.js.map +1 -0
- package/lib/cjs/models/events/base-event.d.ts +20 -0
- package/lib/cjs/models/events/base-event.js +17 -0
- package/lib/cjs/models/events/base-event.js.map +1 -0
- package/lib/cjs/models/events/botonic-event.d.ts +4 -0
- package/lib/cjs/models/events/botonic-event.js +3 -0
- package/lib/cjs/models/events/botonic-event.js.map +1 -0
- package/lib/{esm/models/events/connections/index.d.ts → cjs/models/events/connection/connection-event.d.ts} +1 -1
- package/lib/cjs/models/events/{connections/index.js → connection/connection-event.js} +1 -1
- package/lib/cjs/models/events/connection/connection-event.js.map +1 -0
- package/lib/cjs/models/events/connection/index.d.ts +1 -0
- package/lib/cjs/models/events/connection/index.js +5 -0
- package/lib/cjs/models/events/connection/index.js.map +1 -0
- package/lib/cjs/models/events/index.d.ts +4 -21
- package/lib/cjs/models/events/index.js +5 -8
- package/lib/cjs/models/events/index.js.map +1 -1
- package/lib/cjs/models/events/integration/index.d.ts +1 -0
- package/lib/cjs/models/events/integration/index.js +5 -0
- package/lib/cjs/models/events/integration/index.js.map +1 -0
- package/lib/cjs/models/events/integration/integration-event.d.ts +6 -0
- package/lib/cjs/models/events/integration/integration-event.js +3 -0
- package/lib/cjs/models/events/integration/integration-event.js.map +1 -0
- package/lib/cjs/models/events/message/carousel.d.ts +1 -1
- package/lib/cjs/models/events/message/custom.d.ts +2 -2
- package/lib/cjs/models/events/message/index.d.ts +9 -30
- package/lib/cjs/models/events/message/index.js +10 -29
- package/lib/cjs/models/events/message/index.js.map +1 -1
- package/lib/cjs/models/events/message/location.d.ts +1 -1
- package/lib/cjs/models/events/message/media.d.ts +1 -1
- package/lib/cjs/models/events/message/media.js +5 -5
- package/lib/cjs/models/events/message/media.js.map +1 -1
- package/lib/cjs/models/events/message/message-event.d.ts +30 -0
- package/lib/cjs/models/events/message/message-event.js +32 -0
- package/lib/cjs/models/events/message/message-event.js.map +1 -0
- package/lib/cjs/models/events/message/postback.d.ts +1 -1
- package/lib/cjs/models/events/message/text.d.ts +1 -1
- package/lib/cjs/models/index.d.ts +6 -0
- package/lib/cjs/models/index.js +10 -0
- package/lib/cjs/models/index.js.map +1 -0
- package/lib/cjs/models/legacy-types.d.ts +184 -0
- package/lib/cjs/models/legacy-types.js +59 -0
- package/lib/cjs/models/legacy-types.js.map +1 -0
- package/lib/cjs/models/session.d.ts +3 -0
- package/lib/cjs/models/session.js +3 -0
- package/lib/cjs/models/session.js.map +1 -0
- package/lib/cjs/models/user.d.ts +8 -4
- package/lib/cjs/output-parser/botonic-output-parser.d.ts +16 -0
- package/lib/cjs/output-parser/botonic-output-parser.js +37 -0
- package/lib/cjs/output-parser/botonic-output-parser.js.map +1 -0
- package/lib/cjs/output-parser/factory.d.ts +1 -1
- package/lib/cjs/output-parser/factory.js +7 -8
- package/lib/cjs/output-parser/factory.js.map +1 -1
- package/lib/cjs/output-parser/index.d.ts +3 -16
- package/lib/cjs/output-parser/index.js +4 -34
- package/lib/cjs/output-parser/index.js.map +1 -1
- package/lib/cjs/output-parser/parsers.d.ts +3 -9
- package/lib/cjs/output-parser/parsers.js +21 -12
- package/lib/cjs/output-parser/parsers.js.map +1 -1
- package/lib/cjs/plugins.d.ts +2 -3
- package/lib/cjs/plugins.js +9 -6
- package/lib/cjs/plugins.js.map +1 -1
- package/lib/cjs/routing/index.d.ts +2 -0
- package/lib/cjs/routing/index.js +6 -0
- package/lib/cjs/routing/index.js.map +1 -0
- package/lib/cjs/routing/router-utils.d.ts +11 -0
- package/lib/cjs/routing/router-utils.js +89 -0
- package/lib/cjs/routing/router-utils.js.map +1 -0
- package/lib/cjs/routing/router.d.ts +54 -0
- package/lib/cjs/routing/router.js +319 -0
- package/lib/cjs/routing/router.js.map +1 -0
- package/lib/cjs/utils.d.ts +1 -0
- package/lib/cjs/utils.js +7 -1
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/constants.d.ts +4 -15
- package/lib/esm/constants.js +4 -15
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/core-bot.d.ts +12 -9
- package/lib/esm/core-bot.js +52 -41
- package/lib/esm/core-bot.js.map +1 -1
- package/lib/esm/debug/index.d.ts +1 -1
- package/lib/esm/debug/index.js +1 -1
- package/lib/esm/debug/index.js.map +1 -1
- package/lib/esm/debug/inspector.d.ts +1 -1
- package/lib/esm/handoff.d.ts +5 -5
- package/lib/esm/handoff.js +13 -10
- package/lib/esm/handoff.js.map +1 -1
- package/lib/esm/hubtype-service.d.ts +4 -4
- package/lib/esm/hubtype-service.js +1 -1
- package/lib/esm/hubtype-service.js.map +1 -1
- package/lib/esm/i18n.d.ts +1 -1
- package/lib/esm/index.d.ts +8 -163
- package/lib/esm/index.js +8 -45
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/models/bot-state.d.ts +11 -0
- package/lib/esm/models/bot-state.js +2 -0
- package/lib/esm/models/bot-state.js.map +1 -0
- package/lib/esm/models/channels.d.ts +9 -0
- package/lib/esm/models/channels.js +11 -0
- package/lib/esm/models/channels.js.map +1 -0
- package/lib/esm/models/events/base-event.d.ts +20 -0
- package/lib/esm/models/events/base-event.js +14 -0
- package/lib/esm/models/events/base-event.js.map +1 -0
- package/lib/esm/models/events/botonic-event.d.ts +4 -0
- package/lib/esm/models/events/botonic-event.js +2 -0
- package/lib/esm/models/events/botonic-event.js.map +1 -0
- package/lib/{cjs/models/events/connections/index.d.ts → esm/models/events/connection/connection-event.d.ts} +1 -1
- package/lib/esm/models/events/{connections/index.js → connection/connection-event.js} +1 -1
- package/lib/esm/models/events/connection/connection-event.js.map +1 -0
- package/lib/esm/models/events/connection/index.d.ts +1 -0
- package/lib/esm/models/events/connection/index.js +2 -0
- package/lib/esm/models/events/connection/index.js.map +1 -0
- package/lib/esm/models/events/index.d.ts +4 -21
- package/lib/esm/models/events/index.js +4 -7
- package/lib/esm/models/events/index.js.map +1 -1
- package/lib/esm/models/events/integration/index.d.ts +1 -0
- package/lib/esm/models/events/integration/index.js +2 -0
- package/lib/esm/models/events/integration/index.js.map +1 -0
- package/lib/esm/models/events/integration/integration-event.d.ts +6 -0
- package/lib/esm/models/events/integration/integration-event.js +2 -0
- package/lib/esm/models/events/integration/integration-event.js.map +1 -0
- package/lib/esm/models/events/message/carousel.d.ts +1 -1
- package/lib/esm/models/events/message/custom.d.ts +2 -2
- package/lib/esm/models/events/message/index.d.ts +9 -30
- package/lib/esm/models/events/message/index.js +9 -28
- package/lib/esm/models/events/message/index.js.map +1 -1
- package/lib/esm/models/events/message/location.d.ts +1 -1
- package/lib/esm/models/events/message/media.d.ts +1 -1
- package/lib/esm/models/events/message/media.js +1 -1
- package/lib/esm/models/events/message/media.js.map +1 -1
- package/lib/esm/models/events/message/message-event.d.ts +30 -0
- package/lib/esm/models/events/message/message-event.js +29 -0
- package/lib/esm/models/events/message/message-event.js.map +1 -0
- package/lib/esm/models/events/message/postback.d.ts +1 -1
- package/lib/esm/models/events/message/text.d.ts +1 -1
- package/lib/esm/models/index.d.ts +6 -0
- package/lib/esm/models/index.js +7 -0
- package/lib/esm/models/index.js.map +1 -0
- package/lib/esm/models/legacy-types.d.ts +184 -0
- package/lib/esm/models/legacy-types.js +56 -0
- package/lib/esm/models/legacy-types.js.map +1 -0
- package/lib/esm/models/session.d.ts +3 -0
- package/lib/esm/models/session.js +2 -0
- package/lib/esm/models/session.js.map +1 -0
- package/lib/esm/models/user.d.ts +8 -4
- package/lib/esm/output-parser/botonic-output-parser.d.ts +16 -0
- package/lib/esm/output-parser/botonic-output-parser.js +33 -0
- package/lib/esm/output-parser/botonic-output-parser.js.map +1 -0
- package/lib/esm/output-parser/factory.d.ts +1 -1
- package/lib/esm/output-parser/factory.js +1 -2
- package/lib/esm/output-parser/factory.js.map +1 -1
- package/lib/esm/output-parser/index.d.ts +3 -16
- package/lib/esm/output-parser/index.js +3 -32
- package/lib/esm/output-parser/index.js.map +1 -1
- package/lib/esm/output-parser/parsers.d.ts +3 -9
- package/lib/esm/output-parser/parsers.js +14 -7
- package/lib/esm/output-parser/parsers.js.map +1 -1
- package/lib/esm/plugins.d.ts +2 -3
- package/lib/esm/plugins.js +9 -6
- package/lib/esm/plugins.js.map +1 -1
- package/lib/esm/routing/index.d.ts +2 -0
- package/lib/esm/routing/index.js +3 -0
- package/lib/esm/routing/index.js.map +1 -0
- package/lib/esm/routing/router-utils.d.ts +11 -0
- package/lib/esm/routing/router-utils.js +79 -0
- package/lib/esm/routing/router-utils.js.map +1 -0
- package/lib/esm/routing/router.d.ts +54 -0
- package/lib/esm/routing/router.js +315 -0
- package/lib/esm/routing/router.js.map +1 -0
- package/lib/esm/utils.d.ts +1 -0
- package/lib/esm/utils.js +5 -0
- package/lib/esm/utils.js.map +1 -1
- package/package.json +6 -6
- package/src/constants.ts +6 -15
- package/src/core-bot.ts +84 -47
- package/src/debug/index.ts +1 -6
- package/src/debug/inspector.ts +1 -1
- package/src/handoff.ts +15 -12
- package/src/hubtype-service.ts +5 -5
- package/src/i18n.ts +1 -1
- package/src/index.ts +8 -230
- package/src/models/bot-state.ts +12 -0
- package/src/models/channels.ts +9 -0
- package/src/models/events/base-event.ts +22 -0
- package/src/models/events/botonic-event.ts +26 -0
- package/src/models/events/{connections/index.ts → connection/connection-event.ts} +1 -1
- package/src/models/events/connection/index.ts +1 -0
- package/src/models/events/index.ts +4 -39
- package/src/models/events/integration/index.ts +1 -0
- package/src/models/events/integration/integration-event.ts +13 -0
- package/src/models/events/message/carousel.ts +1 -1
- package/src/models/events/message/custom.ts +2 -2
- package/src/models/events/message/index.ts +9 -37
- package/src/models/events/message/location.ts +1 -1
- package/src/models/events/message/media.ts +1 -1
- package/src/models/events/message/message-event.ts +37 -0
- package/src/models/events/message/postback.ts +1 -1
- package/src/models/events/message/text.ts +1 -1
- package/src/models/index.ts +6 -0
- package/src/models/legacy-types.ts +262 -0
- package/src/models/session.ts +3 -0
- package/src/models/user.ts +10 -4
- package/src/output-parser/botonic-output-parser.ts +38 -0
- package/src/output-parser/factory.ts +1 -3
- package/src/output-parser/index.ts +3 -38
- package/src/output-parser/parsers.ts +29 -17
- package/src/plugins.ts +18 -8
- package/src/routing/index.ts +2 -0
- package/src/routing/router-utils.ts +100 -0
- package/src/routing/router.ts +415 -0
- package/src/utils.ts +6 -0
- 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/models/events/connections/index.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/router.d.ts +0 -35
- package/lib/cjs/router.js +0 -262
- package/lib/cjs/router.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/models/events/connections/index.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/router.d.ts +0 -35
- package/lib/esm/router.js +0 -258
- package/lib/esm/router.js.map +0 -1
- package/src/errors.ts +0 -11
- package/src/output-parser/util.ts +0 -8
- package/src/router.ts +0 -316
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseCustom = exports.parseCarousel = exports.parseElement = exports.parseLocation = exports.parseMedia = exports.parsePostback = exports.parseText = exports.parseReplies = exports.parseReply = exports.parseButtons = exports.parseButton = exports.parseMessage = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
3
|
+
exports.parseCustom = exports.parseCarousel = exports.parseElement = exports.parseLocation = exports.parseMedia = exports.parsePostback = exports.parseText = exports.parseReplies = exports.parseReply = exports.parseButtons = exports.parseButton = exports.parseMessage = exports.parseBoolean = exports.parseNumber = void 0;
|
|
4
|
+
const models_1 = require("../models");
|
|
5
|
+
const botonic_output_parser_1 = require("./botonic-output-parser");
|
|
6
|
+
function parseNumber(strNumber) {
|
|
7
|
+
return parseInt(strNumber);
|
|
8
|
+
}
|
|
9
|
+
exports.parseNumber = parseNumber;
|
|
10
|
+
function parseBoolean(strNumber) {
|
|
11
|
+
if (strNumber === '0')
|
|
12
|
+
return false;
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
exports.parseBoolean = parseBoolean;
|
|
7
16
|
// COMMON
|
|
8
17
|
const parseMessage = args => {
|
|
9
18
|
const typingAndDelay = {};
|
|
10
19
|
if (args.toParse.delay !== undefined) {
|
|
11
|
-
typingAndDelay['delay'] =
|
|
20
|
+
typingAndDelay['delay'] = parseNumber(args.toParse.delay);
|
|
12
21
|
}
|
|
13
22
|
if (args.toParse.typing !== undefined) {
|
|
14
|
-
typingAndDelay['typing'] =
|
|
23
|
+
typingAndDelay['typing'] = parseNumber(args.toParse.typing);
|
|
15
24
|
}
|
|
16
25
|
return {
|
|
17
26
|
toParse: args.toParse,
|
|
18
27
|
parsed: Object.assign({
|
|
19
28
|
// Following properties added later before saving event: eventId, userId, createdAt, from, ack
|
|
20
|
-
eventType:
|
|
29
|
+
eventType: models_1.EventTypes.MESSAGE, type: args.toParse.type, ack: args.toParse.ack, from: args.toParse.from, channel: args.toParse.channel, idFromChannel: args.toParse.idFromChannel }, typingAndDelay),
|
|
21
30
|
};
|
|
22
31
|
};
|
|
23
32
|
exports.parseMessage = parseMessage;
|
|
24
33
|
// BUTTONS
|
|
25
34
|
const parseButton = (button) => {
|
|
26
|
-
const title = button[
|
|
35
|
+
const title = button[botonic_output_parser_1.TEXT_NODE_NAME];
|
|
27
36
|
if ('payload' in button) {
|
|
28
37
|
return { title, payload: button.payload };
|
|
29
38
|
}
|
|
@@ -58,7 +67,7 @@ const parseButtons = args => {
|
|
|
58
67
|
exports.parseButtons = parseButtons;
|
|
59
68
|
// REPLIES
|
|
60
69
|
const parseReply = (reply) => ({
|
|
61
|
-
title: reply[
|
|
70
|
+
title: reply[botonic_output_parser_1.TEXT_NODE_NAME],
|
|
62
71
|
payload: reply.payload,
|
|
63
72
|
});
|
|
64
73
|
exports.parseReply = parseReply;
|
|
@@ -79,7 +88,7 @@ exports.parseReplies = parseReplies;
|
|
|
79
88
|
const parseText = args => {
|
|
80
89
|
return {
|
|
81
90
|
toParse: args.toParse,
|
|
82
|
-
parsed: Object.assign(Object.assign({}, args.parsed), { text: args.toParse[
|
|
91
|
+
parsed: Object.assign(Object.assign({}, args.parsed), { text: args.toParse[botonic_output_parser_1.TEXT_NODE_NAME], markdown: parseBoolean(args.toParse.markdown) }),
|
|
83
92
|
};
|
|
84
93
|
};
|
|
85
94
|
exports.parseText = parseText;
|
|
@@ -95,7 +104,7 @@ exports.parsePostback = parsePostback;
|
|
|
95
104
|
const parseMedia = args => {
|
|
96
105
|
return {
|
|
97
106
|
toParse: args.toParse,
|
|
98
|
-
parsed: Object.assign(Object.assign({}, args.parsed), { src: args.toParse.src
|
|
107
|
+
parsed: Object.assign(Object.assign({}, args.parsed), { src: args.toParse.src }),
|
|
99
108
|
};
|
|
100
109
|
};
|
|
101
110
|
exports.parseMedia = parseMedia;
|
|
@@ -131,7 +140,7 @@ exports.parseCarousel = parseCarousel;
|
|
|
131
140
|
const parseCustom = args => {
|
|
132
141
|
return {
|
|
133
142
|
toParse: args.toParse,
|
|
134
|
-
parsed: Object.assign(Object.assign({}, args.parsed), {
|
|
143
|
+
parsed: Object.assign(Object.assign({}, args.parsed), { json: JSON.parse(args.toParse.json) }),
|
|
135
144
|
};
|
|
136
145
|
};
|
|
137
146
|
exports.parseCustom = parseCustom;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsers.js","sourceRoot":"","sources":["../../../src/output-parser/parsers.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"parsers.js","sourceRoot":"","sources":["../../../src/output-parser/parsers.ts"],"names":[],"mappings":";;;AAAA,sCAiBkB;AAClB,mEAAwD;AAExD,SAAgB,WAAW,CAAC,SAAiB;IAC3C,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAA;AAC5B,CAAC;AAFD,kCAEC;AAED,SAAgB,YAAY,CAAC,SAAiB;IAC5C,IAAI,SAAS,KAAK,GAAG;QAAE,OAAO,KAAK,CAAA;IACnC,OAAO,IAAI,CAAA;AACb,CAAC;AAHD,oCAGC;AAUD,SAAS;AACF,MAAM,YAAY,GAAuC,IAAI,CAAC,EAAE;IACrE,MAAM,cAAc,GAAG,EAAE,CAAA;IACzB,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE;QACpC,cAAc,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,O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AAE;IAC5D,MAAM,CAAC,GAAoB;QACzB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,QAAQ,EAAE,OAAO,CAAC,IAAI;KACvB,CAAA;IACD,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,KAAK,SAAS,CAAA;IAC/C,IAAI,UAAU;QAAE,CAAC,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,mBAAW,CAAC,CAAC,CAAC,CAAC,CAAA;IACnE,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AATY,QAAA,YAAY,gBASxB;AAEM,MAAM,aAAa,GAAwC,IAAI,CAAC,EAAE;IACvE,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,MAAM,kCACD,IAAI,CAAC,MAAM,KACd,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,oBAAY,CAAC,OAAO,CAAC,CAAC,GACrE;KACF,CAAA;AACH,CAAC,CAAA;AARY,QAAA,aAAa,iBAQzB;AAED,SAAS;AACF,MAAM,WAAW,GAAsC,IAAI,CAAC,EAAE;IACnE,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,MAAM,kCACD,IAAI,CAAC,MAAM,KACd,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GACpC;KACF,CAAA;AACH,CAAC,CAAA;AARY,QAAA,WAAW,eAQvB"}
|
package/lib/cjs/plugins.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Input, PluginConfig, Session } from './
|
|
2
|
-
import { BotonicEvent } from './models/events';
|
|
1
|
+
import { BotonicEvent, BotState, Input, PluginConfig, Session } from './models';
|
|
3
2
|
declare type PluginMode = 'pre' | 'post';
|
|
4
3
|
export declare function loadPlugins(plugins: PluginConfig<any>[]): any;
|
|
5
4
|
export declare function runPlugins(plugins: any, // // TODO: Add type for resolvedPlugins, they differ from loaded plugins
|
|
6
|
-
mode: PluginMode, input: Input, session: Session,
|
|
5
|
+
mode: PluginMode, input: Input, session: Session, botState: BotState, response?: string | null, messageEvents?: Partial<BotonicEvent>[] | null, dataProvider?: any): Promise<void>;
|
|
7
6
|
export {};
|
package/lib/cjs/plugins.js
CHANGED
|
@@ -21,19 +21,22 @@ function loadPlugins(plugins) {
|
|
|
21
21
|
}
|
|
22
22
|
exports.loadPlugins = loadPlugins;
|
|
23
23
|
async function runPlugins(plugins, // // TODO: Add type for resolvedPlugins, they differ from loaded plugins
|
|
24
|
-
mode, input, session,
|
|
24
|
+
mode, input, session, botState, response = null, messageEvents = null, dataProvider // TODO: type as dataProvider
|
|
25
|
+
) {
|
|
25
26
|
for (const key in plugins) {
|
|
26
27
|
const p = await plugins[key];
|
|
27
28
|
try {
|
|
28
|
-
if (mode
|
|
29
|
-
await p.pre({ input, session,
|
|
30
|
-
if (mode
|
|
29
|
+
if (mode === 'pre')
|
|
30
|
+
await p.pre({ input, session, botState, dataProvider, plugins });
|
|
31
|
+
if (mode === 'post')
|
|
31
32
|
await p.post({
|
|
32
33
|
input,
|
|
33
34
|
session,
|
|
34
|
-
|
|
35
|
+
botState,
|
|
35
36
|
response,
|
|
36
|
-
|
|
37
|
+
messageEvents,
|
|
38
|
+
dataProvider,
|
|
39
|
+
plugins,
|
|
37
40
|
});
|
|
38
41
|
}
|
|
39
42
|
catch (e) {
|
package/lib/cjs/plugins.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../src/plugins.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../src/plugins.ts"],"names":[],"mappings":";;;AAWA,SAAgB,WAAW,CAAC,OAA4B;IACtD,IAAI,CAAC,OAAO;QAAE,OAA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AE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,CAAA;YAClE,IAAI,IAAI,KAAK,MAAM;gBACjB,MAAM,CAAC,CAAC,IAAI,CAAC;oBACX,KAAK;oBACL,OAAO;oBACP,QAAQ;oBACR,QAAQ;oBACR,aAAa;oBACb,YAAY;oBACZ,OAAO;iBACR,CAAC,CAAA;SACL;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;SACf;KACF;AACH,CAAC;AA7BD,gCA6BC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/routing/index.ts"],"names":[],"mappings":";;;AAAA,mDAAwB;AACxB,yDAA8B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Action, BotRequest, Input, Params, PathParams, Route, Routes } from '../models';
|
|
2
|
+
export declare class NoMatchingRouteError extends Error {
|
|
3
|
+
input: Input;
|
|
4
|
+
constructor(input: Input);
|
|
5
|
+
}
|
|
6
|
+
export declare function isPathPayload(payload?: string): boolean;
|
|
7
|
+
export declare function getPathParamsFromPathPayload(payload?: string): PathParams;
|
|
8
|
+
export declare function pathParamsToParams(pathParams?: string): Params;
|
|
9
|
+
export declare function getEmptyAction(childRoutes?: Route[]): Action;
|
|
10
|
+
export declare function getNotFoundAction(input: Input, routes: Route[]): Action;
|
|
11
|
+
export declare function getComputedRoutes(routes: Routes, request: BotRequest): Promise<Route[]>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getComputedRoutes = exports.getNotFoundAction = exports.getEmptyAction = exports.pathParamsToParams = exports.getPathParamsFromPathPayload = exports.isPathPayload = exports.NoMatchingRouteError = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
class NoMatchingRouteError extends Error {
|
|
6
|
+
constructor(input) {
|
|
7
|
+
super(`No route found for input '${JSON.stringify(input)}' and no ${constants_1.NOT_FOUND_PATH} route defined`);
|
|
8
|
+
this.input = input;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.NoMatchingRouteError = NoMatchingRouteError;
|
|
12
|
+
function isPathPayload(payload) {
|
|
13
|
+
if (!payload)
|
|
14
|
+
return false;
|
|
15
|
+
const isPathPayload = constants_1.PATH_PAYLOAD_REGEXP.exec(payload);
|
|
16
|
+
return Boolean(isPathPayload);
|
|
17
|
+
}
|
|
18
|
+
exports.isPathPayload = isPathPayload;
|
|
19
|
+
function getPathParamsFromPathPayload(payload) {
|
|
20
|
+
const defaultPathParams = {
|
|
21
|
+
path: null,
|
|
22
|
+
params: {},
|
|
23
|
+
};
|
|
24
|
+
if (!payload)
|
|
25
|
+
return defaultPathParams;
|
|
26
|
+
if (!isPathPayload(payload))
|
|
27
|
+
return defaultPathParams;
|
|
28
|
+
try {
|
|
29
|
+
const pathWithParams = payload.split(constants_1.PATH_PAYLOAD_IDENTIFIER)[1];
|
|
30
|
+
if (!pathWithParams) {
|
|
31
|
+
throw `${constants_1.PATH_PAYLOAD_IDENTIFIER} is empty`;
|
|
32
|
+
}
|
|
33
|
+
const [path, params] = pathWithParams.split('?');
|
|
34
|
+
return { path: path !== null && path !== void 0 ? path : null, params: pathParamsToParams(params) };
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
console.error('Error getting path and params from input.payload:', e);
|
|
38
|
+
return defaultPathParams;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.getPathParamsFromPathPayload = getPathParamsFromPathPayload;
|
|
42
|
+
function pathParamsToParams(pathParams) {
|
|
43
|
+
if (!pathParams)
|
|
44
|
+
return {};
|
|
45
|
+
try {
|
|
46
|
+
const params = {};
|
|
47
|
+
const searchParams = new URLSearchParams(pathParams);
|
|
48
|
+
for (const [key, value] of searchParams) {
|
|
49
|
+
params[key] = value;
|
|
50
|
+
}
|
|
51
|
+
return params;
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.pathParamsToParams = pathParamsToParams;
|
|
58
|
+
function getEmptyAction(childRoutes) {
|
|
59
|
+
if (!childRoutes)
|
|
60
|
+
return null;
|
|
61
|
+
const emptyActionRoute = childRoutes.find(r => r.path === constants_1.EMPTY_ACTION_PATH);
|
|
62
|
+
if (!emptyActionRoute)
|
|
63
|
+
return null;
|
|
64
|
+
return emptyActionRoute.action;
|
|
65
|
+
}
|
|
66
|
+
exports.getEmptyAction = getEmptyAction;
|
|
67
|
+
function getNotFoundAction(input, routes) {
|
|
68
|
+
const notFoundActionRoute = routes.find(r => r.path === constants_1.NOT_FOUND_PATH);
|
|
69
|
+
if (!notFoundActionRoute)
|
|
70
|
+
throw new NoMatchingRouteError(input);
|
|
71
|
+
return notFoundActionRoute.action;
|
|
72
|
+
}
|
|
73
|
+
exports.getNotFoundAction = getNotFoundAction;
|
|
74
|
+
async function getComputedRoutes(routes, request) {
|
|
75
|
+
if (routes instanceof Function) {
|
|
76
|
+
return await getComputedRoutes(await routes(request), request);
|
|
77
|
+
}
|
|
78
|
+
for (const [key, route] of Object.entries(routes)) {
|
|
79
|
+
if (route.childRoutes && route.childRoutes instanceof Function) {
|
|
80
|
+
routes[key].childRoutes = await getComputedRoutes(await route.childRoutes(request), request);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
routes[key] = route;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return routes;
|
|
87
|
+
}
|
|
88
|
+
exports.getComputedRoutes = getComputedRoutes;
|
|
89
|
+
//# sourceMappingURL=router-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-utils.js","sourceRoot":"","sources":["../../../src/routing/router-utils.ts"],"names":[],"mappings":";;;AAAA,4CAKqB;AAWrB,MAAa,oBAAqB,SAAQ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AAM,CAAC,OAAO,CAAC,MAAM,CAAQ,EAAE;QACxD,IAAI,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,YAAY,QAAQ,EAAE;YAC9D,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,GAAG,MAAM,iBAAiB,CAC/C,MAAM,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,EAChC,OAAO,CACR,CAAA;SACF;aAAM;YACL,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;SACpB;KACF;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAlBD,8CAkBC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { RouteInspector } from '../debug/inspector';
|
|
2
|
+
import { BotState, 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, botState: BotState): 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, botState: BotState): 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
|
+
}
|
|
@@ -0,0 +1,319 @@
|
|
|
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, botState) {
|
|
25
|
+
var _a, _b, _c, _d, _e;
|
|
26
|
+
botState.retries = (_a = botState.retries) !== null && _a !== void 0 ? _a : 0;
|
|
27
|
+
// 1. Getting the current routing state.
|
|
28
|
+
const { currentRoute, matchedRoute, params, isFlowBroken, } = this.getRoutingState(input, session, botState);
|
|
29
|
+
const currentRoutePath = (_b = currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path) !== null && _b !== void 0 ? _b : null;
|
|
30
|
+
const matchedRoutePath = (_c = matchedRoute === null || matchedRoute === void 0 ? void 0 : matchedRoute.path) !== null && _c !== void 0 ? _c : null;
|
|
31
|
+
// 2. Given a routing state, resolve the different possible scenarios and return the new bot state.
|
|
32
|
+
/**
|
|
33
|
+
* Redirect Scenario:
|
|
34
|
+
* We have matched a redirect route with a given redirection path, so we try to obtain the redirectionRoute with getRouteByPath.
|
|
35
|
+
* 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.
|
|
36
|
+
* It has preference over ignoring retries.
|
|
37
|
+
*/
|
|
38
|
+
if (matchedRoute && matchedRoute.redirect) {
|
|
39
|
+
botState.retries = 0;
|
|
40
|
+
const redirectionRoute = this.getRouteByPath(matchedRoute.redirect);
|
|
41
|
+
if (redirectionRoute) {
|
|
42
|
+
botState.lastRoutePath = matchedRoute.redirect;
|
|
43
|
+
return {
|
|
44
|
+
action: redirectionRoute.action,
|
|
45
|
+
emptyAction: router_utils_1.getEmptyAction(redirectionRoute.childRoutes),
|
|
46
|
+
fallbackAction: null,
|
|
47
|
+
botState,
|
|
48
|
+
params,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
botState.lastRoutePath = null;
|
|
52
|
+
return {
|
|
53
|
+
action: null,
|
|
54
|
+
emptyAction: null,
|
|
55
|
+
fallbackAction: router_utils_1.getNotFoundAction(input, this.routes),
|
|
56
|
+
botState,
|
|
57
|
+
params,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Ignore Retry Scenario:
|
|
62
|
+
* 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.
|
|
63
|
+
*/
|
|
64
|
+
if (matchedRoute && matchedRoute.ignoreRetry) {
|
|
65
|
+
botState.retries = 0;
|
|
66
|
+
botState.lastRoutePath = matchedRoutePath;
|
|
67
|
+
return {
|
|
68
|
+
action: matchedRoute.action,
|
|
69
|
+
emptyAction: router_utils_1.getEmptyAction(matchedRoute.childRoutes),
|
|
70
|
+
fallbackAction: null,
|
|
71
|
+
botState,
|
|
72
|
+
params,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Retry Scenario:
|
|
77
|
+
* We were in a route which had retries enabled, so we check if the number of retries is exceeded.
|
|
78
|
+
* 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.
|
|
79
|
+
*/
|
|
80
|
+
if (isFlowBroken &&
|
|
81
|
+
currentRoute &&
|
|
82
|
+
currentRoute.retry &&
|
|
83
|
+
botState.retries < currentRoute.retry) {
|
|
84
|
+
botState.retries = botState.retries !== 0 ? botState.retries + 1 : 1;
|
|
85
|
+
botState.lastRoutePath = currentRoutePath;
|
|
86
|
+
if (matchedRoute && matchedRoutePath !== constants_1.NOT_FOUND_PATH) {
|
|
87
|
+
return {
|
|
88
|
+
action: currentRoute.action,
|
|
89
|
+
emptyAction: router_utils_1.getEmptyAction(matchedRoute.childRoutes),
|
|
90
|
+
fallbackAction: matchedRoute.action,
|
|
91
|
+
botState,
|
|
92
|
+
params,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
action: (_d = currentRoute.action) !== null && _d !== void 0 ? _d : null,
|
|
97
|
+
emptyAction: router_utils_1.getEmptyAction(currentRoute.childRoutes),
|
|
98
|
+
fallbackAction: router_utils_1.getNotFoundAction(input, this.routes),
|
|
99
|
+
botState,
|
|
100
|
+
params,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Default Scenario:
|
|
105
|
+
* We have matched a route or not, but we don't need to execute retries logic, so retries stay to 0.
|
|
106
|
+
*/
|
|
107
|
+
botState.retries = 0;
|
|
108
|
+
/**
|
|
109
|
+
* Matching Route Scenario:
|
|
110
|
+
* We have matched a route, so we return the new bot state.
|
|
111
|
+
*/
|
|
112
|
+
if (matchedRoute && matchedRoutePath !== constants_1.NOT_FOUND_PATH) {
|
|
113
|
+
botState.lastRoutePath = matchedRoutePath;
|
|
114
|
+
return {
|
|
115
|
+
action: (_e = matchedRoute.action) !== null && _e !== void 0 ? _e : null,
|
|
116
|
+
emptyAction: router_utils_1.getEmptyAction(matchedRoute.childRoutes),
|
|
117
|
+
fallbackAction: null,
|
|
118
|
+
botState,
|
|
119
|
+
params,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 404 Scenario (No Route Found):
|
|
124
|
+
* We have not matched any route, so we return the new bot state.
|
|
125
|
+
*/
|
|
126
|
+
botState.lastRoutePath = currentRoutePath;
|
|
127
|
+
return {
|
|
128
|
+
action: null,
|
|
129
|
+
emptyAction: null,
|
|
130
|
+
fallbackAction: router_utils_1.getNotFoundAction(input, this.routes),
|
|
131
|
+
params,
|
|
132
|
+
botState,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 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.
|
|
137
|
+
* IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects
|
|
138
|
+
* */
|
|
139
|
+
getRoute(input, routes, session, lastRoutePath) {
|
|
140
|
+
let params = {};
|
|
141
|
+
const route = routes.find(r => Object.entries(r)
|
|
142
|
+
.filter(([key, _]) => key !== 'action' && key !== 'childRoutes' && key !== 'path')
|
|
143
|
+
.some(([key, value]) => {
|
|
144
|
+
const match = this.matchRoute(r, key, value, input, session, lastRoutePath);
|
|
145
|
+
try {
|
|
146
|
+
if (match !== null && typeof match !== 'boolean' && match.groups) {
|
|
147
|
+
// Strip '[Object: null prototype]' from groups result: https://stackoverflow.com/a/62945609/6237608
|
|
148
|
+
params = Object.assign({}, match.groups);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (e) { }
|
|
152
|
+
return Boolean(match);
|
|
153
|
+
}));
|
|
154
|
+
if (route)
|
|
155
|
+
return { route: utils_1.cloneObject(route), params };
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Find the route that matches the given path. Path can include concatenations, e.g: 'Flow1/Subflow1.1'.
|
|
160
|
+
* IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects
|
|
161
|
+
* */
|
|
162
|
+
getRouteByPath(path, routeList = this.routes) {
|
|
163
|
+
if (!path)
|
|
164
|
+
return null;
|
|
165
|
+
const [currentPath, ...childPath] = path.split('/');
|
|
166
|
+
for (const route of routeList) {
|
|
167
|
+
// iterate over all routeList
|
|
168
|
+
if (route.path === currentPath) {
|
|
169
|
+
if (route.childRoutes &&
|
|
170
|
+
route.childRoutes.length &&
|
|
171
|
+
childPath.length > 0) {
|
|
172
|
+
// evaluate childroute over next actions
|
|
173
|
+
const computedRoute = this.getRouteByPath(childPath.join('/'), route.childRoutes);
|
|
174
|
+
// IMPORTANT: Returning a new object to avoid modifying dev routes and introduce side effects
|
|
175
|
+
if (computedRoute)
|
|
176
|
+
return utils_1.cloneObject(computedRoute);
|
|
177
|
+
}
|
|
178
|
+
else if (childPath.length === 0) {
|
|
179
|
+
return utils_1.cloneObject(route); // last action and found route
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Returns the matched value for a specific route.
|
|
187
|
+
* Matching Props: ('text' | 'payload' | 'intent' | 'type' | 'input' | 'session' | 'request' ...)
|
|
188
|
+
* Matchers: (string: exact match | regex: regular expression match | function: return true)
|
|
189
|
+
* input: user input object, e.g.: {type: 'text', data: 'Hi'}
|
|
190
|
+
* */
|
|
191
|
+
matchRoute(route, prop, matcher, input, session, lastRoutePath) {
|
|
192
|
+
let value = null;
|
|
193
|
+
if (Object.keys(input).indexOf(prop) > -1)
|
|
194
|
+
value = input[prop];
|
|
195
|
+
else if (prop === 'input')
|
|
196
|
+
value = input;
|
|
197
|
+
else if (prop === 'session')
|
|
198
|
+
value = session;
|
|
199
|
+
else if (prop === 'request')
|
|
200
|
+
value = { input, session, lastRoutePath };
|
|
201
|
+
const matched = this.matchValue(matcher, value);
|
|
202
|
+
if (matched) {
|
|
203
|
+
this.routeInspector.routeMatched(route, prop, matcher, value);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
this.routeInspector.routeNotMatched(route, prop, matcher, value);
|
|
207
|
+
}
|
|
208
|
+
return matched;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Runs the matcher against the given value.
|
|
212
|
+
* If there is a match, it will return a truthy value (true, RegExp result), o.w., it will return a falsy value.
|
|
213
|
+
* */
|
|
214
|
+
matchValue(matcher, value) {
|
|
215
|
+
if (typeof matcher === 'string')
|
|
216
|
+
return value === matcher;
|
|
217
|
+
if (matcher instanceof RegExp) {
|
|
218
|
+
if (value === undefined || value === null)
|
|
219
|
+
return false;
|
|
220
|
+
return matcher.exec(value);
|
|
221
|
+
}
|
|
222
|
+
if (typeof matcher === 'function')
|
|
223
|
+
return matcher(value);
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* It resolves the current state of navigation. Two scenarios:
|
|
228
|
+
* 1. Given a path payload input (__PATH_PAYLOAD__somePath?someParam=someValue), we can resolve the routing state directly from it (using getRouteByPath).
|
|
229
|
+
* 2. Given any other type of input, we resolve the routing state with normal resolution (using getRoute).
|
|
230
|
+
* */
|
|
231
|
+
getRoutingState(input, session, botState) {
|
|
232
|
+
const currentRoute = this.getRouteByPath(botState.lastRoutePath);
|
|
233
|
+
if (currentRoute && botState.lastRoutePath)
|
|
234
|
+
currentRoute.path = botState.lastRoutePath;
|
|
235
|
+
if (typeof input.payload === 'string' && router_utils_1.isPathPayload(input.payload)) {
|
|
236
|
+
return this.getRoutingStateFromPathPayload(currentRoute, input.payload);
|
|
237
|
+
}
|
|
238
|
+
return this.getRoutingStateFromInput(currentRoute, input, session);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* 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.
|
|
242
|
+
* */
|
|
243
|
+
getRoutingStateFromInput(currentRoute, input, session) {
|
|
244
|
+
var _a, _b, _c;
|
|
245
|
+
// get route depending of current ChildRoutes
|
|
246
|
+
if (currentRoute && currentRoute.childRoutes) {
|
|
247
|
+
const routeParams = this.getRoute(input, currentRoute.childRoutes, session, currentRoute.path);
|
|
248
|
+
if (routeParams) {
|
|
249
|
+
return {
|
|
250
|
+
currentRoute,
|
|
251
|
+
matchedRoute: Object.assign(Object.assign({}, routeParams.route), { path: routeParams.route && currentRoute.path
|
|
252
|
+
? `${currentRoute.path}/${routeParams.route.path}`
|
|
253
|
+
: currentRoute.path }),
|
|
254
|
+
params: routeParams.params,
|
|
255
|
+
isFlowBroken: false,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* we couldn't find a route in the state of the currentRoute childRoutes,
|
|
261
|
+
* so let's find in the general routes
|
|
262
|
+
*/
|
|
263
|
+
const routeParams = this.getRoute(input, this.routes, session, (_a = currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path) !== null && _a !== void 0 ? _a : null);
|
|
264
|
+
const isFlowBroken = Boolean(currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path);
|
|
265
|
+
if (routeParams === null || routeParams === void 0 ? void 0 : routeParams.route) {
|
|
266
|
+
return {
|
|
267
|
+
currentRoute,
|
|
268
|
+
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 }),
|
|
269
|
+
params: routeParams.params,
|
|
270
|
+
isFlowBroken,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
currentRoute,
|
|
275
|
+
matchedRoute: null,
|
|
276
|
+
params: {},
|
|
277
|
+
isFlowBroken,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* 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.
|
|
282
|
+
* */
|
|
283
|
+
getRoutingStateFromPathPayload(currentRoute, pathPayload) {
|
|
284
|
+
const { path, params } = router_utils_1.getPathParamsFromPathPayload(pathPayload);
|
|
285
|
+
/**
|
|
286
|
+
* shorthand function to update the matching information given a path
|
|
287
|
+
*/
|
|
288
|
+
const getRoutingStateFromPath = (seekPath) => {
|
|
289
|
+
const matchedRoute = this.getRouteByPath(seekPath);
|
|
290
|
+
if (!matchedRoute) {
|
|
291
|
+
return {
|
|
292
|
+
currentRoute,
|
|
293
|
+
matchedRoute: null,
|
|
294
|
+
params: {},
|
|
295
|
+
isFlowBroken: true,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
currentRoute,
|
|
300
|
+
matchedRoute: Object.assign(Object.assign({}, matchedRoute), { path: seekPath }),
|
|
301
|
+
params,
|
|
302
|
+
isFlowBroken: false,
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* Given a valid path: 'Flow1/Subflow1' we are in one of the two scenarios below.
|
|
307
|
+
*/
|
|
308
|
+
// 1. Received __PATH_PAYLOAD__Subflow2, so we need to first try to concatenate it with Flow1 (lastRoutePath)
|
|
309
|
+
if (currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path) {
|
|
310
|
+
const routingState = getRoutingStateFromPath(`${currentRoute.path}/${path}`);
|
|
311
|
+
if (routingState.matchedRoute)
|
|
312
|
+
return routingState;
|
|
313
|
+
}
|
|
314
|
+
// 2. Received __PATH_PAYLOAD__Flow1/Subflow1, so we can resolve it directly
|
|
315
|
+
return getRoutingStateFromPath(path);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
exports.Router = Router;
|
|
319
|
+
//# sourceMappingURL=router.js.map
|