@botonic/core 0.19.0 → 0.20.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/constants.d.ts +4 -0
- package/lib/cjs/constants.js +8 -0
- package/lib/cjs/constants.js.map +1 -0
- package/lib/cjs/core-bot.d.ts +36 -0
- package/lib/cjs/core-bot.js +115 -0
- package/lib/cjs/core-bot.js.map +1 -0
- package/lib/cjs/data-provider/dynamodb-data-provider.d.ts +26 -0
- package/lib/cjs/data-provider/dynamodb-data-provider.js +81 -0
- package/lib/cjs/data-provider/dynamodb-data-provider.js.map +1 -0
- package/lib/cjs/data-provider/dynamodb-utils.d.ts +11 -0
- package/lib/cjs/data-provider/dynamodb-utils.js +120 -0
- package/lib/cjs/data-provider/dynamodb-utils.js.map +1 -0
- package/lib/cjs/data-provider/factory.d.ts +25 -0
- package/lib/cjs/data-provider/factory.js +31 -0
- package/lib/cjs/data-provider/factory.js.map +1 -0
- package/lib/cjs/data-provider/index.d.ts +4 -0
- package/lib/cjs/data-provider/index.js +8 -0
- package/lib/cjs/data-provider/index.js.map +1 -0
- package/lib/cjs/data-provider/local-data-provider.d.ts +26 -0
- package/lib/cjs/data-provider/local-data-provider.js +137 -0
- package/lib/cjs/data-provider/local-data-provider.js.map +1 -0
- package/lib/cjs/debug/index.d.ts +1 -0
- package/lib/cjs/debug/index.js +5 -0
- package/lib/cjs/debug/index.js.map +1 -0
- package/lib/cjs/debug/inspector.d.ts +24 -0
- package/lib/{debug → cjs/debug}/inspector.js +5 -3
- package/lib/cjs/debug/inspector.js.map +1 -0
- package/lib/cjs/handoff.d.ts +67 -0
- package/lib/{handoff.js → cjs/handoff.js} +2 -1
- package/lib/cjs/handoff.js.map +1 -0
- package/lib/cjs/hubtype-service.d.ts +69 -0
- package/lib/{hubtype-service.js → cjs/hubtype-service.js} +25 -12
- package/lib/cjs/hubtype-service.js.map +1 -0
- package/lib/cjs/i18n.d.ts +2 -0
- package/lib/{i18n.js → cjs/i18n.js} +0 -1
- package/lib/cjs/i18n.js.map +1 -0
- package/lib/cjs/index.d.ts +11 -0
- package/lib/cjs/index.js +17 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/models/events/base-event.d.ts +13 -0
- package/lib/{models/events/index.js → cjs/models/events/base-event.js} +1 -1
- package/lib/cjs/models/events/base-event.js.map +1 -0
- package/lib/cjs/models/events/botonic-event.d.ts +3 -0
- package/lib/cjs/models/events/botonic-event.js +3 -0
- package/lib/cjs/models/events/botonic-event.js.map +1 -0
- package/lib/{models/events/connections/index.d.ts → cjs/models/events/connections/connection-event.d.ts} +1 -1
- package/lib/{models/events/connections/index.js → cjs/models/events/connections/connection-event.js} +1 -1
- package/lib/cjs/models/events/connections/connection-event.js.map +1 -0
- package/lib/cjs/models/events/connections/index.d.ts +1 -0
- package/lib/cjs/models/events/connections/index.js +5 -0
- package/lib/cjs/models/events/connections/index.js.map +1 -0
- package/lib/cjs/models/events/index.d.ts +4 -0
- package/lib/cjs/models/events/index.js +8 -0
- package/lib/cjs/models/events/index.js.map +1 -0
- package/lib/{models → cjs/models}/events/message/buttons.d.ts +0 -0
- package/lib/{models → cjs/models}/events/message/buttons.js +0 -0
- package/lib/cjs/models/events/message/buttons.js.map +1 -0
- package/lib/{models → cjs/models}/events/message/carousel.d.ts +1 -1
- package/lib/{models → cjs/models}/events/message/carousel.js +0 -0
- package/lib/cjs/models/events/message/carousel.js.map +1 -0
- package/lib/{models → cjs/models}/events/message/custom.d.ts +2 -2
- package/lib/{models → cjs/models}/events/message/custom.js +0 -0
- package/lib/cjs/models/events/message/custom.js.map +1 -0
- package/lib/cjs/models/events/message/index.d.ts +9 -0
- package/lib/cjs/models/events/message/index.js +13 -0
- package/lib/cjs/models/events/message/index.js.map +1 -0
- package/lib/{models → cjs/models}/events/message/location.d.ts +1 -1
- package/lib/{models → cjs/models}/events/message/location.js +0 -0
- package/lib/cjs/models/events/message/location.js.map +1 -0
- package/lib/{models → cjs/models}/events/message/media.d.ts +1 -1
- package/lib/cjs/models/events/message/media.js +11 -0
- package/lib/cjs/models/events/message/media.js.map +1 -0
- package/lib/{models/events/message/index.d.ts → cjs/models/events/message/message-event.d.ts} +1 -1
- package/lib/{models/events/message/index.js → cjs/models/events/message/message-event.js} +1 -1
- package/lib/cjs/models/events/message/message-event.js.map +1 -0
- package/lib/{models → cjs/models}/events/message/postback.d.ts +1 -1
- package/lib/{models → cjs/models}/events/message/postback.js +0 -0
- package/lib/cjs/models/events/message/postback.js.map +1 -0
- package/lib/{models → cjs/models}/events/message/replies.d.ts +0 -0
- package/lib/{models → cjs/models}/events/message/replies.js +0 -0
- package/lib/cjs/models/events/message/replies.js.map +1 -0
- package/lib/{models → cjs/models}/events/message/text.d.ts +1 -1
- package/lib/{models → cjs/models}/events/message/text.js +0 -0
- package/lib/cjs/models/events/message/text.js.map +1 -0
- package/lib/cjs/models/index.d.ts +3 -0
- package/lib/cjs/models/index.js +7 -0
- package/lib/cjs/models/index.js.map +1 -0
- package/lib/cjs/models/legacy-types.d.ts +207 -0
- package/lib/cjs/models/legacy-types.js +60 -0
- package/lib/cjs/models/legacy-types.js.map +1 -0
- package/lib/{models → cjs/models}/user.d.ts +1 -1
- package/lib/{models → cjs/models}/user.js +0 -0
- package/lib/{models → cjs/models}/user.js.map +1 -1
- package/lib/{output-parser/index.d.ts → cjs/output-parser/botonic-output-parser.d.ts} +1 -1
- package/lib/{output-parser/index.js → cjs/output-parser/botonic-output-parser.js} +2 -1
- package/lib/cjs/output-parser/botonic-output-parser.js.map +1 -0
- package/lib/{output-parser → cjs/output-parser}/factory.d.ts +1 -1
- package/lib/{output-parser → cjs/output-parser}/factory.js +7 -8
- package/lib/cjs/output-parser/factory.js.map +1 -0
- package/lib/cjs/output-parser/index.d.ts +3 -0
- package/lib/cjs/output-parser/index.js +7 -0
- package/lib/cjs/output-parser/index.js.map +1 -0
- package/lib/{output-parser → cjs/output-parser}/parsers.d.ts +3 -9
- package/lib/{output-parser → cjs/output-parser}/parsers.js +21 -12
- package/lib/cjs/output-parser/parsers.js.map +1 -0
- package/lib/cjs/plugins.d.ts +7 -0
- package/lib/{plugins.js → cjs/plugins.js} +8 -5
- package/lib/cjs/plugins.js.map +1 -0
- package/lib/cjs/pusher-utils.d.ts +7 -0
- package/lib/cjs/pusher-utils.js +20 -0
- package/lib/cjs/pusher-utils.js.map +1 -0
- 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 +315 -0
- package/lib/cjs/routing/router.js.map +1 -0
- package/lib/cjs/utils.d.ts +11 -0
- package/lib/{utils.js → cjs/utils.js} +14 -5
- package/lib/cjs/utils.js.map +1 -0
- package/lib/esm/constants.d.ts +4 -0
- package/lib/esm/constants.js +5 -0
- package/lib/esm/constants.js.map +1 -0
- package/lib/esm/core-bot.d.ts +36 -0
- package/lib/esm/core-bot.js +111 -0
- package/lib/esm/core-bot.js.map +1 -0
- package/lib/esm/data-provider/dynamodb-data-provider.d.ts +26 -0
- package/lib/esm/data-provider/dynamodb-data-provider.js +77 -0
- package/lib/esm/data-provider/dynamodb-data-provider.js.map +1 -0
- package/lib/esm/data-provider/dynamodb-utils.d.ts +11 -0
- package/lib/esm/data-provider/dynamodb-utils.js +113 -0
- package/lib/esm/data-provider/dynamodb-utils.js.map +1 -0
- package/lib/esm/data-provider/factory.d.ts +25 -0
- package/lib/esm/data-provider/factory.js +27 -0
- package/lib/esm/data-provider/factory.js.map +1 -0
- package/lib/esm/data-provider/index.d.ts +4 -0
- package/lib/esm/data-provider/index.js +5 -0
- package/lib/esm/data-provider/index.js.map +1 -0
- package/lib/esm/data-provider/local-data-provider.d.ts +26 -0
- package/lib/esm/data-provider/local-data-provider.js +133 -0
- package/lib/esm/data-provider/local-data-provider.js.map +1 -0
- package/lib/esm/debug/index.d.ts +1 -0
- package/lib/esm/debug/index.js +2 -0
- package/lib/esm/debug/index.js.map +1 -0
- package/lib/esm/debug/inspector.d.ts +24 -0
- package/lib/esm/debug/inspector.js +65 -0
- package/lib/esm/debug/inspector.js.map +1 -0
- package/lib/esm/handoff.d.ts +67 -0
- package/lib/esm/handoff.js +171 -0
- package/lib/esm/handoff.js.map +1 -0
- package/lib/esm/hubtype-service.d.ts +69 -0
- package/lib/esm/hubtype-service.js +195 -0
- package/lib/esm/hubtype-service.js.map +1 -0
- package/lib/esm/i18n.d.ts +2 -0
- package/lib/esm/i18n.js +7 -0
- package/lib/esm/i18n.js.map +1 -0
- package/lib/esm/index.d.ts +11 -0
- package/lib/esm/index.js +14 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/models/events/base-event.d.ts +13 -0
- package/lib/esm/models/events/base-event.js +8 -0
- package/lib/esm/models/events/base-event.js.map +1 -0
- package/lib/esm/models/events/botonic-event.d.ts +3 -0
- package/lib/esm/models/events/botonic-event.js +2 -0
- package/lib/esm/models/events/botonic-event.js.map +1 -0
- package/lib/esm/models/events/connections/connection-event.d.ts +9 -0
- package/lib/esm/models/events/connections/connection-event.js +6 -0
- package/lib/esm/models/events/connections/connection-event.js.map +1 -0
- package/lib/esm/models/events/connections/index.d.ts +1 -0
- package/lib/esm/models/events/connections/index.js +2 -0
- package/lib/esm/models/events/connections/index.js.map +1 -0
- package/lib/esm/models/events/index.d.ts +4 -0
- package/lib/esm/models/events/index.js +5 -0
- package/lib/esm/models/events/index.js.map +1 -0
- package/lib/esm/models/events/message/buttons.d.ts +18 -0
- package/lib/esm/models/events/message/buttons.js +2 -0
- package/lib/esm/models/events/message/buttons.js.map +1 -0
- package/lib/esm/models/events/message/carousel.d.ts +11 -0
- package/lib/esm/models/events/message/carousel.js +2 -0
- package/lib/esm/models/events/message/carousel.js.map +1 -0
- package/lib/esm/models/events/message/custom.d.ts +6 -0
- package/lib/esm/models/events/message/custom.js +2 -0
- package/lib/esm/models/events/message/custom.js.map +1 -0
- package/lib/esm/models/events/message/index.d.ts +9 -0
- package/lib/esm/models/events/message/index.js +10 -0
- package/lib/esm/models/events/message/index.js.map +1 -0
- package/lib/esm/models/events/message/location.d.ts +6 -0
- package/lib/esm/models/events/message/location.js +2 -0
- package/lib/esm/models/events/message/location.js.map +1 -0
- package/lib/esm/models/events/message/media.d.ts +18 -0
- package/lib/esm/models/events/message/media.js +8 -0
- package/lib/esm/models/events/message/media.js.map +1 -0
- 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 +4 -0
- package/lib/esm/models/events/message/postback.js +2 -0
- package/lib/esm/models/events/message/postback.js.map +1 -0
- package/lib/esm/models/events/message/replies.d.ts +7 -0
- package/lib/esm/models/events/message/replies.js +2 -0
- package/lib/esm/models/events/message/replies.js.map +1 -0
- package/lib/esm/models/events/message/text.d.ts +8 -0
- package/lib/esm/models/events/message/text.js +2 -0
- package/lib/esm/models/events/message/text.js.map +1 -0
- package/lib/esm/models/index.d.ts +3 -0
- package/lib/esm/models/index.js +4 -0
- package/lib/esm/models/index.js.map +1 -0
- package/lib/esm/models/legacy-types.d.ts +207 -0
- package/lib/esm/models/legacy-types.js +57 -0
- package/lib/esm/models/legacy-types.js.map +1 -0
- package/lib/esm/models/user.d.ts +10 -0
- package/lib/esm/models/user.js +2 -0
- package/lib/esm/models/user.js.map +1 -0
- 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 +4 -0
- package/lib/esm/output-parser/factory.js +28 -0
- package/lib/esm/output-parser/factory.js.map +1 -0
- package/lib/esm/output-parser/index.d.ts +3 -0
- package/lib/esm/output-parser/index.js +4 -0
- package/lib/esm/output-parser/index.js.map +1 -0
- package/lib/esm/output-parser/parsers.d.ts +22 -0
- package/lib/esm/output-parser/parsers.js +130 -0
- package/lib/esm/output-parser/parsers.js.map +1 -0
- package/lib/esm/plugins.d.ts +7 -0
- package/lib/esm/plugins.js +42 -0
- package/lib/esm/plugins.js.map +1 -0
- package/lib/esm/pusher-utils.d.ts +7 -0
- package/lib/esm/pusher-utils.js +16 -0
- package/lib/esm/pusher-utils.js.map +1 -0
- 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 +311 -0
- package/lib/esm/routing/router.js.map +1 -0
- package/lib/esm/utils.d.ts +11 -0
- package/lib/esm/utils.js +78 -0
- package/lib/esm/utils.js.map +1 -0
- package/package.json +22 -9
- package/src/constants.ts +6 -0
- package/src/core-bot.ts +213 -0
- package/src/data-provider/dynamodb-data-provider.ts +103 -0
- package/src/data-provider/dynamodb-utils.ts +149 -0
- package/src/data-provider/factory.ts +60 -0
- package/src/data-provider/index.ts +4 -0
- package/src/data-provider/local-data-provider.ts +154 -0
- package/src/{types/debug/index.d.ts → debug/index.ts} +0 -0
- package/src/debug/{inspector.js → inspector.ts} +39 -14
- package/src/{handoff.js → handoff.ts} +88 -24
- package/src/{hubtype-service.js → hubtype-service.ts} +85 -34
- package/src/{i18n.js → i18n.ts} +7 -1
- package/src/index.ts +13 -0
- package/src/models/events/base-event.ts +14 -0
- package/src/models/events/botonic-event.ts +24 -0
- package/src/models/events/connections/connection-event.ts +11 -0
- package/src/models/events/connections/index.ts +1 -11
- package/src/models/events/index.ts +4 -39
- 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 +3 -0
- package/src/{types/index.d.ts → models/legacy-types.ts} +141 -80
- package/src/models/user.ts +2 -1
- 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 -37
- package/src/output-parser/parsers.ts +27 -17
- package/src/{plugins.js → plugins.ts} +21 -12
- package/src/pusher-utils.ts +16 -0
- package/src/routing/index.ts +2 -0
- package/src/routing/router-utils.ts +100 -0
- package/src/routing/router.ts +409 -0
- package/src/{utils.js → utils.ts} +26 -13
- package/index.d.ts +0 -1
- package/lib/constants.d.ts +0 -15
- package/lib/constants.js +0 -19
- package/lib/constants.js.map +0 -1
- package/lib/core-bot.d.ts +0 -40
- package/lib/core-bot.js +0 -78
- package/lib/core-bot.js.map +0 -1
- package/lib/debug/index.d.ts +0 -1
- package/lib/debug/index.js +0 -9
- package/lib/debug/index.js.map +0 -1
- package/lib/debug/inspector.d.ts +0 -20
- package/lib/debug/inspector.js.map +0 -1
- package/lib/debug/inspector.test.d.ts +0 -1
- package/lib/debug/inspector.test.js +0 -8
- package/lib/debug/inspector.test.js.map +0 -1
- package/lib/errors.d.ts +0 -4
- package/lib/errors.js +0 -11
- package/lib/errors.js.map +0 -1
- package/lib/handoff.d.ts +0 -34
- package/lib/handoff.js.map +0 -1
- package/lib/handoff.test.d.ts +0 -1
- package/lib/handoff.test.js +0 -62
- package/lib/handoff.test.js.map +0 -1
- package/lib/hubtype-service.d.ts +0 -58
- package/lib/hubtype-service.js.map +0 -1
- package/lib/hubtype-service.test.d.ts +0 -1
- package/lib/hubtype-service.test.js +0 -21
- package/lib/hubtype-service.test.js.map +0 -1
- package/lib/i18n.d.ts +0 -1
- package/lib/i18n.js.map +0 -1
- package/lib/index.d.ts +0 -48
- package/lib/index.js +0 -58
- package/lib/index.js.map +0 -1
- package/lib/models/events/connections/index.js.map +0 -1
- package/lib/models/events/index.d.ts +0 -21
- package/lib/models/events/index.js.map +0 -1
- package/lib/models/events/message/buttons.js.map +0 -1
- package/lib/models/events/message/carousel.js.map +0 -1
- package/lib/models/events/message/custom.js.map +0 -1
- package/lib/models/events/message/index.js.map +0 -1
- package/lib/models/events/message/location.js.map +0 -1
- package/lib/models/events/message/media.js +0 -11
- package/lib/models/events/message/media.js.map +0 -1
- package/lib/models/events/message/postback.js.map +0 -1
- package/lib/models/events/message/replies.js.map +0 -1
- package/lib/models/events/message/text.js.map +0 -1
- package/lib/output-parser/factory.js.map +0 -1
- package/lib/output-parser/index.js.map +0 -1
- package/lib/output-parser/parsers.js.map +0 -1
- package/lib/output-parser/util.d.ts +0 -2
- package/lib/output-parser/util.js +0 -14
- package/lib/output-parser/util.js.map +0 -1
- package/lib/plugins.d.ts +0 -2
- package/lib/plugins.js.map +0 -1
- package/lib/router.d.ts +0 -55
- package/lib/router.js +0 -268
- package/lib/router.js.map +0 -1
- package/lib/router.test.d.ts +0 -1
- package/lib/router.test.js +0 -271
- package/lib/router.test.js.map +0 -1
- package/lib/utils.d.ts +0 -8
- package/lib/utils.js.map +0 -1
- package/src/constants.js +0 -15
- package/src/core-bot.js +0 -108
- package/src/debug/index.js +0 -6
- package/src/debug/inspector.test.js +0 -6
- package/src/errors.js +0 -8
- package/src/handoff.test.js +0 -61
- package/src/hubtype-service.test.js +0 -23
- package/src/index.js +0 -52
- package/src/output-parser/util.ts +0 -8
- package/src/router.js +0 -273
- package/src/router.test.js +0 -345
- package/src/types/constants.d.ts +0 -14
- package/src/types/core-bot.d.ts +0 -46
- package/src/types/debug/inspector.d.ts +0 -33
- package/src/types/handoff.d.ts +0 -84
- package/src/types/hubtype-service.d.ts +0 -52
- package/src/types/i18n.d.ts +0 -8
- package/src/types/plugins.d.ts +0 -13
- package/src/types/router.d.ts +0 -57
- package/src/types/utils.d.ts +0 -12
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Router = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const inspector_1 = require("../debug/inspector");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const router_utils_1 = require("./router-utils");
|
|
8
|
+
class Router {
|
|
9
|
+
constructor(routes, routeInspector = undefined) {
|
|
10
|
+
this.routes = routes;
|
|
11
|
+
this.routeInspector = routeInspector || new inspector_1.RouteInspector();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Processes an input and return a representation of the new bot state.
|
|
15
|
+
* The algorithm is splitted in two main parts:
|
|
16
|
+
* 1. Getting the current routing state.
|
|
17
|
+
* 2. Given a routing state, resolve the different possible scenarios and return the new bot state.
|
|
18
|
+
* The new bot state can return three type of actions:
|
|
19
|
+
* - action: an action directly resolved from a matching route
|
|
20
|
+
* - emptyAction: optional action that can exists or not only within childRoutes
|
|
21
|
+
* - fallbackAction: any other action that acts as a fallback (404, )
|
|
22
|
+
*/
|
|
23
|
+
// eslint-disable-next-line complexity
|
|
24
|
+
processInput(input, session, lastRoutePath = null) {
|
|
25
|
+
var _a, _b, _c, _d, _e;
|
|
26
|
+
session.__retries = (_a = session === null || session === void 0 ? void 0 : session.__retries) !== null && _a !== void 0 ? _a : 0;
|
|
27
|
+
// 1. Getting the current routing state.
|
|
28
|
+
const { currentRoute, matchedRoute, params, isFlowBroken, } = this.getRoutingState(input, session, lastRoutePath);
|
|
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
|
+
session.__retries = 0;
|
|
40
|
+
const redirectionRoute = this.getRouteByPath(matchedRoute.redirect);
|
|
41
|
+
if (redirectionRoute) {
|
|
42
|
+
return {
|
|
43
|
+
action: redirectionRoute.action,
|
|
44
|
+
emptyAction: router_utils_1.getEmptyAction(redirectionRoute.childRoutes),
|
|
45
|
+
fallbackAction: null,
|
|
46
|
+
lastRoutePath: matchedRoute.redirect,
|
|
47
|
+
params,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
action: null,
|
|
52
|
+
emptyAction: null,
|
|
53
|
+
fallbackAction: router_utils_1.getNotFoundAction(input, this.routes),
|
|
54
|
+
lastRoutePath: null,
|
|
55
|
+
params,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Ignore Retry Scenario:
|
|
60
|
+
* 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.
|
|
61
|
+
*/
|
|
62
|
+
if (matchedRoute && matchedRoute.ignoreRetry) {
|
|
63
|
+
session.__retries = 0;
|
|
64
|
+
return {
|
|
65
|
+
action: matchedRoute.action,
|
|
66
|
+
emptyAction: router_utils_1.getEmptyAction(matchedRoute.childRoutes),
|
|
67
|
+
fallbackAction: null,
|
|
68
|
+
lastRoutePath: matchedRoutePath,
|
|
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
|
+
session.__retries < currentRoute.retry) {
|
|
81
|
+
session.__retries = session.__retries !== 0 ? session.__retries + 1 : 1;
|
|
82
|
+
if (matchedRoute && matchedRoutePath !== constants_1.NOT_FOUND_PATH) {
|
|
83
|
+
return {
|
|
84
|
+
action: currentRoute.action,
|
|
85
|
+
emptyAction: router_utils_1.getEmptyAction(matchedRoute.childRoutes),
|
|
86
|
+
fallbackAction: matchedRoute.action,
|
|
87
|
+
lastRoutePath: currentRoutePath,
|
|
88
|
+
params,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
action: (_d = currentRoute.action) !== null && _d !== void 0 ? _d : null,
|
|
93
|
+
emptyAction: router_utils_1.getEmptyAction(currentRoute.childRoutes),
|
|
94
|
+
fallbackAction: router_utils_1.getNotFoundAction(input, this.routes),
|
|
95
|
+
lastRoutePath: currentRoutePath,
|
|
96
|
+
params,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Default Scenario:
|
|
101
|
+
* We have matched a route or not, but we don't need to execute retries logic, so retries stay to 0.
|
|
102
|
+
*/
|
|
103
|
+
session.__retries = 0;
|
|
104
|
+
/**
|
|
105
|
+
* Matching Route Scenario:
|
|
106
|
+
* We have matched a route, so we return the new bot state.
|
|
107
|
+
*/
|
|
108
|
+
if (matchedRoute && matchedRoutePath !== constants_1.NOT_FOUND_PATH) {
|
|
109
|
+
return {
|
|
110
|
+
action: (_e = matchedRoute.action) !== null && _e !== void 0 ? _e : null,
|
|
111
|
+
emptyAction: router_utils_1.getEmptyAction(matchedRoute.childRoutes),
|
|
112
|
+
fallbackAction: null,
|
|
113
|
+
lastRoutePath: matchedRoutePath,
|
|
114
|
+
params,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 404 Scenario (No Route Found):
|
|
119
|
+
* We have not matched any route, so we return the new bot state.
|
|
120
|
+
*/
|
|
121
|
+
return {
|
|
122
|
+
action: null,
|
|
123
|
+
emptyAction: null,
|
|
124
|
+
fallbackAction: router_utils_1.getNotFoundAction(input, this.routes),
|
|
125
|
+
params,
|
|
126
|
+
lastRoutePath: currentRoutePath,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 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.
|
|
131
|
+
* IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects
|
|
132
|
+
* */
|
|
133
|
+
getRoute(input, routes, session, lastRoutePath) {
|
|
134
|
+
let params = {};
|
|
135
|
+
const route = routes.find(r => Object.entries(r)
|
|
136
|
+
.filter(([key, _]) => key !== 'action' && key !== 'childRoutes' && key !== 'path')
|
|
137
|
+
.some(([key, value]) => {
|
|
138
|
+
const match = this.matchRoute(r, key, value, input, session, lastRoutePath);
|
|
139
|
+
try {
|
|
140
|
+
if (match !== null && typeof match !== 'boolean' && match.groups) {
|
|
141
|
+
// Strip '[Object: null prototype]' from groups result: https://stackoverflow.com/a/62945609/6237608
|
|
142
|
+
params = Object.assign({}, match.groups);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (e) { }
|
|
146
|
+
return Boolean(match);
|
|
147
|
+
}));
|
|
148
|
+
if (route)
|
|
149
|
+
return { route: utils_1.cloneObject(route), params };
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Find the route that matches the given path. Path can include concatenations, e.g: 'Flow1/Subflow1.1'.
|
|
154
|
+
* IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects
|
|
155
|
+
* */
|
|
156
|
+
getRouteByPath(path, routeList = this.routes) {
|
|
157
|
+
if (!path)
|
|
158
|
+
return null;
|
|
159
|
+
const [currentPath, ...childPath] = path.split('/');
|
|
160
|
+
for (const route of routeList) {
|
|
161
|
+
// iterate over all routeList
|
|
162
|
+
if (route.path === currentPath) {
|
|
163
|
+
if (route.childRoutes &&
|
|
164
|
+
route.childRoutes.length &&
|
|
165
|
+
childPath.length > 0) {
|
|
166
|
+
// evaluate childroute over next actions
|
|
167
|
+
const computedRoute = this.getRouteByPath(childPath.join('/'), route.childRoutes);
|
|
168
|
+
// IMPORTANT: Returning a new object to avoid modifying dev routes and introduce side effects
|
|
169
|
+
if (computedRoute)
|
|
170
|
+
return utils_1.cloneObject(computedRoute);
|
|
171
|
+
}
|
|
172
|
+
else if (childPath.length === 0) {
|
|
173
|
+
return utils_1.cloneObject(route); // last action and found route
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Returns the matched value for a specific route.
|
|
181
|
+
* Matching Props: ('text' | 'payload' | 'intent' | 'type' | 'input' | 'session' | 'request' ...)
|
|
182
|
+
* Matchers: (string: exact match | regex: regular expression match | function: return true)
|
|
183
|
+
* input: user input object, e.g.: {type: 'text', data: 'Hi'}
|
|
184
|
+
* */
|
|
185
|
+
matchRoute(route, prop, matcher, input, session, lastRoutePath) {
|
|
186
|
+
let value = null;
|
|
187
|
+
if (Object.keys(input).indexOf(prop) > -1)
|
|
188
|
+
value = input[prop];
|
|
189
|
+
else if (prop === 'text')
|
|
190
|
+
value = input.data;
|
|
191
|
+
else if (prop === 'input')
|
|
192
|
+
value = input;
|
|
193
|
+
else if (prop === 'session')
|
|
194
|
+
value = session;
|
|
195
|
+
else if (prop === 'request')
|
|
196
|
+
value = { input, session, lastRoutePath };
|
|
197
|
+
const matched = this.matchValue(matcher, value);
|
|
198
|
+
if (matched) {
|
|
199
|
+
this.routeInspector.routeMatched(route, prop, matcher, value);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
this.routeInspector.routeNotMatched(route, prop, matcher, value);
|
|
203
|
+
}
|
|
204
|
+
return matched;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Runs the matcher against the given value.
|
|
208
|
+
* If there is a match, it will return a truthy value (true, RegExp result), o.w., it will return a falsy value.
|
|
209
|
+
* */
|
|
210
|
+
matchValue(matcher, value) {
|
|
211
|
+
if (typeof matcher === 'string')
|
|
212
|
+
return value === matcher;
|
|
213
|
+
if (matcher instanceof RegExp) {
|
|
214
|
+
if (value === undefined || value === null)
|
|
215
|
+
return false;
|
|
216
|
+
return matcher.exec(value);
|
|
217
|
+
}
|
|
218
|
+
if (typeof matcher === 'function')
|
|
219
|
+
return matcher(value);
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* It resolves the current state of navigation. Two scenarios:
|
|
224
|
+
* 1. Given a path payload input (__PATH_PAYLOAD__somePath?someParam=someValue), we can resolve the routing state directly from it (using getRouteByPath).
|
|
225
|
+
* 2. Given any other type of input, we resolve the routing state with normal resolution (using getRoute).
|
|
226
|
+
* */
|
|
227
|
+
getRoutingState(input, session, lastRoutePath) {
|
|
228
|
+
const currentRoute = this.getRouteByPath(lastRoutePath);
|
|
229
|
+
if (currentRoute && lastRoutePath)
|
|
230
|
+
currentRoute.path = lastRoutePath;
|
|
231
|
+
if (typeof input.payload === 'string' && router_utils_1.isPathPayload(input.payload)) {
|
|
232
|
+
return this.getRoutingStateFromPathPayload(currentRoute, input.payload);
|
|
233
|
+
}
|
|
234
|
+
return this.getRoutingStateFromInput(currentRoute, input, session);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* 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.
|
|
238
|
+
* */
|
|
239
|
+
getRoutingStateFromInput(currentRoute, input, session) {
|
|
240
|
+
var _a, _b, _c;
|
|
241
|
+
// get route depending of current ChildRoutes
|
|
242
|
+
if (currentRoute && currentRoute.childRoutes) {
|
|
243
|
+
const routeParams = this.getRoute(input, currentRoute.childRoutes, session, currentRoute.path);
|
|
244
|
+
if (routeParams) {
|
|
245
|
+
return {
|
|
246
|
+
currentRoute,
|
|
247
|
+
matchedRoute: Object.assign(Object.assign({}, routeParams.route), { path: routeParams.route && currentRoute.path
|
|
248
|
+
? `${currentRoute.path}/${routeParams.route.path}`
|
|
249
|
+
: currentRoute.path }),
|
|
250
|
+
params: routeParams.params,
|
|
251
|
+
isFlowBroken: false,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* we couldn't find a route in the state of the currentRoute childRoutes,
|
|
257
|
+
* so let's find in the general routes
|
|
258
|
+
*/
|
|
259
|
+
const routeParams = this.getRoute(input, this.routes, session, (_a = currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path) !== null && _a !== void 0 ? _a : null);
|
|
260
|
+
const isFlowBroken = Boolean(currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path);
|
|
261
|
+
if (routeParams === null || routeParams === void 0 ? void 0 : routeParams.route) {
|
|
262
|
+
return {
|
|
263
|
+
currentRoute,
|
|
264
|
+
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 }),
|
|
265
|
+
params: routeParams.params,
|
|
266
|
+
isFlowBroken,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
currentRoute,
|
|
271
|
+
matchedRoute: null,
|
|
272
|
+
params: {},
|
|
273
|
+
isFlowBroken,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* 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.
|
|
278
|
+
* */
|
|
279
|
+
getRoutingStateFromPathPayload(currentRoute, pathPayload) {
|
|
280
|
+
const { path, params } = router_utils_1.getPathParamsFromPathPayload(pathPayload);
|
|
281
|
+
/**
|
|
282
|
+
* shorthand function to update the matching information given a path
|
|
283
|
+
*/
|
|
284
|
+
const getRoutingStateFromPath = (seekPath) => {
|
|
285
|
+
const matchedRoute = this.getRouteByPath(seekPath);
|
|
286
|
+
if (!matchedRoute) {
|
|
287
|
+
return {
|
|
288
|
+
currentRoute,
|
|
289
|
+
matchedRoute: null,
|
|
290
|
+
params: {},
|
|
291
|
+
isFlowBroken: true,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
currentRoute,
|
|
296
|
+
matchedRoute: Object.assign(Object.assign({}, matchedRoute), { path: seekPath }),
|
|
297
|
+
params,
|
|
298
|
+
isFlowBroken: false,
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* Given a valid path: 'Flow1/Subflow1' we are in one of the two scenarios below.
|
|
303
|
+
*/
|
|
304
|
+
// 1. Received __PATH_PAYLOAD__Subflow2, so we need to first try to concatenate it with Flow1 (lastRoutePath)
|
|
305
|
+
if (currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path) {
|
|
306
|
+
const routingState = getRoutingStateFromPath(`${currentRoute.path}/${path}`);
|
|
307
|
+
if (routingState.matchedRoute)
|
|
308
|
+
return routingState;
|
|
309
|
+
}
|
|
310
|
+
// 2. Received __PATH_PAYLOAD__Flow1/Subflow1, so we can resolve it directly
|
|
311
|
+
return getRoutingStateFromPath(path);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
exports.Router = Router;
|
|
315
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/routing/router.ts"],"names":[],"mappings":";;;AAAA,4CAA6C;AAC7C,kDAAmD;AAcnD,oCAAsC;AACtC,iDAMuB;AAEvB,MAAa,MAAM;IAIjB,YACE,MAAe,EACf,iBAA6C,SAAS;QAEtD,IAAI,CAAC,MAAM,GAAG,MAAM,CAA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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;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dirname = exports.join = exports.params2queryString = exports.isFunction = exports.isMobile = exports.getWebpackEnvVar = exports.isBrowser = exports.isNode = void 0;
|
|
3
|
+
exports.dirname = exports.join = exports.params2queryString = exports.cloneObject = exports.isFunction = exports.isMobile = exports.getWebpackEnvVar = exports.isBrowser = exports.isNode = void 0;
|
|
4
4
|
const isNode = () => {
|
|
5
|
+
// @ts-ignore
|
|
5
6
|
return typeof IS_NODE !== 'undefined'
|
|
6
|
-
? //
|
|
7
|
+
? // @ts-ignore
|
|
7
8
|
IS_NODE
|
|
8
9
|
: typeof process !== 'undefined' &&
|
|
9
10
|
process.versions !== null &&
|
|
@@ -11,8 +12,9 @@ const isNode = () => {
|
|
|
11
12
|
};
|
|
12
13
|
exports.isNode = isNode;
|
|
13
14
|
const isBrowser = () => {
|
|
15
|
+
// @ts-ignore
|
|
14
16
|
return typeof IS_BROWSER !== 'undefined'
|
|
15
|
-
? //
|
|
17
|
+
? // @ts-ignore
|
|
16
18
|
IS_BROWSER
|
|
17
19
|
: typeof window !== 'undefined' &&
|
|
18
20
|
typeof window.document !== 'undefined' &&
|
|
@@ -39,7 +41,13 @@ function isFunction(o) {
|
|
|
39
41
|
return typeof o === 'function';
|
|
40
42
|
}
|
|
41
43
|
exports.isFunction = isFunction;
|
|
42
|
-
|
|
44
|
+
function cloneObject(object) {
|
|
45
|
+
if (!object)
|
|
46
|
+
return {};
|
|
47
|
+
return Object.assign({}, object);
|
|
48
|
+
}
|
|
49
|
+
exports.cloneObject = cloneObject;
|
|
50
|
+
const params2queryString = (params) => Object.entries(params)
|
|
43
51
|
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
|
|
44
52
|
.join('&');
|
|
45
53
|
exports.params2queryString = params2queryString;
|
|
@@ -68,6 +76,7 @@ const join = (...segments) => {
|
|
|
68
76
|
newParts.push(part);
|
|
69
77
|
}
|
|
70
78
|
// Preserve the initial slash if there was one.
|
|
79
|
+
// @ts-ignore
|
|
71
80
|
if (parts[0] === '')
|
|
72
81
|
newParts.unshift('');
|
|
73
82
|
// Turn back into a single string path.
|
|
@@ -76,6 +85,6 @@ const join = (...segments) => {
|
|
|
76
85
|
exports.join = join;
|
|
77
86
|
// A simple function to get the dirname of a path
|
|
78
87
|
// Trailing slashes are ignored. Leading slash is preserved.
|
|
79
|
-
const dirname = path => exports.join(path, '..');
|
|
88
|
+
const dirname = (path) => exports.join(path, '..');
|
|
80
89
|
exports.dirname = dirname;
|
|
81
90
|
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAO,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;AARY,QAAA,MAAM,UAQlB;AAEM,MAAM,SAAS,GAAG,GAAY,EAAE;IACrC,aAAa;IACb,OAA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AG,CAAC,CAAA;AAC5D,CAAC,CAAA;AAvBY,QAAA,IAAI,QAuBhB;AAED,iDAAiD;AACjD,4DAA4D;AACrD,MAAM,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,YAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AAApD,QAAA,OAAO,WAA6C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAA;AACnC,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAA;AACnC,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAA;AACzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,MAAM,CAC3C,OAAO,uBAAuB,SAAS,CACxC,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Inspector } from './debug';
|
|
2
|
+
import { BotRequest, BotResponse, Locales, Route, Routes, Session } from './models';
|
|
3
|
+
import { BotonicOutputParser } from './output-parser';
|
|
4
|
+
import { Router } from './routing';
|
|
5
|
+
interface CoreBotConfig {
|
|
6
|
+
appId?: string;
|
|
7
|
+
defaultDelay?: number;
|
|
8
|
+
defaultRoutes?: Route[];
|
|
9
|
+
defaultTyping?: number;
|
|
10
|
+
inspector?: Inspector;
|
|
11
|
+
locales: Locales;
|
|
12
|
+
plugins?: any;
|
|
13
|
+
renderer: any;
|
|
14
|
+
routes: Routes;
|
|
15
|
+
theme?: any;
|
|
16
|
+
}
|
|
17
|
+
export declare class CoreBot {
|
|
18
|
+
appId?: string;
|
|
19
|
+
defaultDelay?: number;
|
|
20
|
+
defaultRoutes: Route[];
|
|
21
|
+
defaultTyping?: number;
|
|
22
|
+
inspector: Inspector;
|
|
23
|
+
locales: Locales;
|
|
24
|
+
plugins?: Record<string, Plugin>;
|
|
25
|
+
renderer: any;
|
|
26
|
+
rootElement: any;
|
|
27
|
+
router: Router | null;
|
|
28
|
+
routes: Routes;
|
|
29
|
+
theme?: any;
|
|
30
|
+
botonicOutputParser: BotonicOutputParser;
|
|
31
|
+
constructor({ renderer, routes, locales, theme, plugins, appId, defaultTyping, defaultDelay, defaultRoutes, inspector, }: CoreBotConfig);
|
|
32
|
+
getString(id: string, session: Session): string;
|
|
33
|
+
setLocale(locale: string, session: Session): void;
|
|
34
|
+
input({ input, session, lastRoutePath, dataProvider, }: BotRequest): Promise<BotResponse>;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ulid } from 'ulid';
|
|
2
|
+
import { Inspector } from './debug';
|
|
3
|
+
import { getString } from './i18n';
|
|
4
|
+
import { MessageEventAck, MessageEventFrom, } from './models';
|
|
5
|
+
import { BotonicOutputParser } from './output-parser';
|
|
6
|
+
import { loadPlugins, runPlugins } from './plugins';
|
|
7
|
+
import { getComputedRoutes, Router } from './routing';
|
|
8
|
+
export class CoreBot {
|
|
9
|
+
constructor({
|
|
10
|
+
// TODO: Receives dataProvider
|
|
11
|
+
renderer, routes, locales, theme, plugins, appId, defaultTyping, defaultDelay, defaultRoutes, inspector, }) {
|
|
12
|
+
this.botonicOutputParser = new BotonicOutputParser();
|
|
13
|
+
this.renderer = renderer;
|
|
14
|
+
this.plugins = loadPlugins(plugins);
|
|
15
|
+
this.theme = theme || {};
|
|
16
|
+
this.defaultTyping =
|
|
17
|
+
typeof defaultTyping !== 'undefined' ? defaultTyping : 0.6;
|
|
18
|
+
this.defaultDelay = typeof defaultDelay !== 'undefined' ? defaultDelay : 0.4;
|
|
19
|
+
this.locales = locales;
|
|
20
|
+
if (appId) {
|
|
21
|
+
this.appId = appId;
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
this.rootElement = null;
|
|
25
|
+
this.inspector = inspector || new Inspector();
|
|
26
|
+
this.routes = routes;
|
|
27
|
+
this.defaultRoutes = defaultRoutes || [];
|
|
28
|
+
this.router =
|
|
29
|
+
this.routes instanceof Function
|
|
30
|
+
? null
|
|
31
|
+
: new Router([...this.routes, ...this.defaultRoutes], this.inspector.routeInspector);
|
|
32
|
+
}
|
|
33
|
+
getString(id, session) {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
return getString(this.locales, session.__locale, id);
|
|
36
|
+
}
|
|
37
|
+
setLocale(locale, session) {
|
|
38
|
+
session.__locale = locale;
|
|
39
|
+
}
|
|
40
|
+
async input({ input, session, lastRoutePath, dataProvider, }) {
|
|
41
|
+
session = session || {};
|
|
42
|
+
if (!session.__locale)
|
|
43
|
+
session.__locale = 'en';
|
|
44
|
+
const parsedUserEvent = this.botonicOutputParser.parseFromUserInput(input);
|
|
45
|
+
const userId = session.user.id;
|
|
46
|
+
if (dataProvider) {
|
|
47
|
+
// TODO: Next iterations. Review cycle of commited events to DB when messages change their ACK
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
const userEvent = await dataProvider.saveEvent(Object.assign(Object.assign({}, parsedUserEvent), { userId, eventId: ulid(), createdAt: new Date().toISOString(), from: MessageEventFrom.USER, ack: MessageEventAck.RECEIVED }));
|
|
50
|
+
}
|
|
51
|
+
if (this.plugins) {
|
|
52
|
+
await runPlugins(this.plugins, 'pre', input, session, lastRoutePath, undefined, undefined, dataProvider);
|
|
53
|
+
}
|
|
54
|
+
if (this.routes instanceof Function) {
|
|
55
|
+
this.router = new Router([
|
|
56
|
+
...(await getComputedRoutes(this.routes, {
|
|
57
|
+
input,
|
|
58
|
+
session,
|
|
59
|
+
lastRoutePath,
|
|
60
|
+
})),
|
|
61
|
+
...this.defaultRoutes,
|
|
62
|
+
], this.inspector.routeInspector);
|
|
63
|
+
}
|
|
64
|
+
const output = this.router.processInput(input, session, lastRoutePath);
|
|
65
|
+
const request = {
|
|
66
|
+
getString: stringId => this.getString(stringId, session),
|
|
67
|
+
setLocale: locale => this.setLocale(locale, session),
|
|
68
|
+
session: session || {},
|
|
69
|
+
params: output.params || {},
|
|
70
|
+
input: input,
|
|
71
|
+
plugins: this.plugins,
|
|
72
|
+
defaultTyping: this.defaultTyping,
|
|
73
|
+
defaultDelay: this.defaultDelay,
|
|
74
|
+
lastRoutePath,
|
|
75
|
+
dataProvider,
|
|
76
|
+
};
|
|
77
|
+
const response = await this.renderer({
|
|
78
|
+
request,
|
|
79
|
+
actions: [output.fallbackAction, output.action, output.emptyAction],
|
|
80
|
+
});
|
|
81
|
+
let messageEvents = [];
|
|
82
|
+
try {
|
|
83
|
+
messageEvents = this.botonicOutputParser.xmlToMessageEvents(response);
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
// Disabling Botonic 1.0 error log for LTS version:
|
|
87
|
+
// console.error(e)
|
|
88
|
+
}
|
|
89
|
+
lastRoutePath = output.lastRoutePath;
|
|
90
|
+
if (this.plugins) {
|
|
91
|
+
await runPlugins(this.plugins, 'post', input, session, lastRoutePath, response, messageEvents, dataProvider);
|
|
92
|
+
}
|
|
93
|
+
if (dataProvider) {
|
|
94
|
+
// TODO: save bot responses to db and update user with new session and new params
|
|
95
|
+
for (const messageEvent of messageEvents) {
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
const botEvent = await dataProvider.saveEvent(Object.assign(Object.assign({}, messageEvent), { userId, eventId: ulid(), createdAt: new Date().toISOString(), from: MessageEventFrom.BOT, ack: MessageEventAck.SENT }));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
session.is_first_interaction = false;
|
|
101
|
+
return {
|
|
102
|
+
input,
|
|
103
|
+
response,
|
|
104
|
+
messageEvents,
|
|
105
|
+
session,
|
|
106
|
+
lastRoutePath,
|
|
107
|
+
dataProvider,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=core-bot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-bot.js","sourceRoot":"","sources":["../../src/core-bot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IA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AG,IAAI,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAA;SACtE;QAAC,OAAO,CAAC,EAAE;YACV,mDAAmD;YACnD,mBAAmB;SACpB;QAED,aAAa,GAAG,MAAM,CAAC,aAAa,CAAA;QACpC,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,MAAM,UAAU,CACd,IAAI,CAAC,OAAO,EACZ,MAAM,EACN,KAAK,EACL,OAAO,EACP,aAAa,EACb,QAAQ,EACR,aAAa,EACb,YAAY,CACb,CAAA;SACF;QAED,IAAI,YAAY,EAAE;YAChB,iFAAiF;YACjF,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE;gBACxC,aAAa;gBACb,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,SAAS,iCACxC,YAAY,KACf,MAAM,EACN,OAAO,EAAE,IAAI,EAAE,EACf,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EACnC,IAAI,EAAE,gBAAgB,CAAC,GAAG,EAC1B,GAAG,EAAE,eAAe,CAAC,IAAI,IACzB,CAAA;aACH;SACF;QAED,OAAO,CAAC,oBAAoB,GAAG,KAAK,CAAA;QACpC,OAAO;YACL,KAAK;YACL,QAAQ;YACR,aAAa;YACb,OAAO;YACP,aAAa;YACb,YAAY;SACb,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Entity, Table } from 'dynamodb-toolbox';
|
|
2
|
+
import { BotonicEvent, User } from '../models';
|
|
3
|
+
import { DataProvider } from './factory';
|
|
4
|
+
export declare class DynamoDBDataProvider implements DataProvider {
|
|
5
|
+
region: string;
|
|
6
|
+
tableName: string;
|
|
7
|
+
userEventsTable: Table;
|
|
8
|
+
userEntity: Entity<any>;
|
|
9
|
+
eventEntity: Entity<any>;
|
|
10
|
+
messageEventEntities: Record<string, Entity<any>>;
|
|
11
|
+
textMessageEventEntity: Entity<any>;
|
|
12
|
+
connectionEventEntity: Entity<any>;
|
|
13
|
+
constructor(url: string);
|
|
14
|
+
getUsers(limit?: number, offset?: number): Promise<User[]>;
|
|
15
|
+
getUser(id: string): Promise<User | undefined>;
|
|
16
|
+
getUserByWebsocketId(websocketId: string): Promise<User | undefined>;
|
|
17
|
+
getUserByField(field: string, value: any): Promise<User | undefined>;
|
|
18
|
+
saveUser(user: User): Promise<User>;
|
|
19
|
+
updateUser(user: User): Promise<User>;
|
|
20
|
+
deleteUser(id: string): Promise<User | undefined>;
|
|
21
|
+
getEvents(limit?: number, offset?: number): Promise<BotonicEvent[]>;
|
|
22
|
+
getEvent(id: string): Promise<BotonicEvent | undefined>;
|
|
23
|
+
saveEvent(event: BotonicEvent): Promise<BotonicEvent>;
|
|
24
|
+
updateEvent(event: BotonicEvent): Promise<BotonicEvent>;
|
|
25
|
+
deleteEvent(id: string): Promise<BotonicEvent | undefined>;
|
|
26
|
+
}
|