@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
|
@@ -1,35 +1,54 @@
|
|
|
1
|
+
import { Route, RouteMatcher } from '../models'
|
|
1
2
|
export class RouteInspector {
|
|
2
|
-
routeMatched(
|
|
3
|
-
|
|
3
|
+
routeMatched(
|
|
4
|
+
_route: Route,
|
|
5
|
+
_routeKey: string,
|
|
6
|
+
_routeValue: RouteMatcher,
|
|
7
|
+
_input: any
|
|
8
|
+
): void {}
|
|
9
|
+
routeNotMatched(
|
|
10
|
+
_route: Route,
|
|
11
|
+
_routeKey: string,
|
|
12
|
+
_routeValue: RouteMatcher,
|
|
13
|
+
_input: any
|
|
14
|
+
): void {}
|
|
4
15
|
}
|
|
5
16
|
|
|
6
17
|
export class FocusRouteInspector extends RouteInspector {
|
|
18
|
+
focusRoutePaths: string[] | null
|
|
19
|
+
focusOnMatches: boolean
|
|
7
20
|
constructor() {
|
|
8
21
|
super()
|
|
9
22
|
this.focusRoutePaths = null
|
|
10
23
|
this.focusOnMatches = false
|
|
11
24
|
}
|
|
12
25
|
|
|
13
|
-
focusOnlyOnRoutes(focusRoutePaths) {
|
|
26
|
+
focusOnlyOnRoutes(focusRoutePaths: string[]): this {
|
|
14
27
|
this.focusRoutePaths = focusRoutePaths
|
|
15
28
|
return this
|
|
16
29
|
}
|
|
17
30
|
|
|
18
|
-
focusOnlyOnMatches() {
|
|
31
|
+
focusOnlyOnMatches(): this {
|
|
19
32
|
this.focusOnMatches = true
|
|
20
33
|
return this
|
|
21
34
|
}
|
|
22
35
|
|
|
23
|
-
_isOnFocus(route) {
|
|
24
|
-
if (this.focusRoutePaths
|
|
36
|
+
_isOnFocus(route: Route): boolean {
|
|
37
|
+
if (this.focusRoutePaths === null) {
|
|
25
38
|
return true
|
|
26
39
|
}
|
|
40
|
+
// @ts-ignore
|
|
27
41
|
return this.focusRoutePaths.includes(route.path)
|
|
28
42
|
}
|
|
29
43
|
}
|
|
30
44
|
|
|
31
45
|
export class LogRouteInspector extends FocusRouteInspector {
|
|
32
|
-
routeMatched(
|
|
46
|
+
routeMatched(
|
|
47
|
+
route: Route,
|
|
48
|
+
routeKey: string,
|
|
49
|
+
routeValue: RouteMatcher,
|
|
50
|
+
inputValue: string
|
|
51
|
+
): void {
|
|
33
52
|
if (!this._isOnFocus(route)) {
|
|
34
53
|
return
|
|
35
54
|
}
|
|
@@ -39,7 +58,13 @@ export class LogRouteInspector extends FocusRouteInspector {
|
|
|
39
58
|
)
|
|
40
59
|
}
|
|
41
60
|
|
|
42
|
-
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
routeNotMatched(
|
|
63
|
+
route: Route,
|
|
64
|
+
routeKey: string,
|
|
65
|
+
routeValue: RouteMatcher,
|
|
66
|
+
inputValue: string
|
|
67
|
+
): void {
|
|
43
68
|
if (!this._isOnFocus(route) || this.focusOnMatches) {
|
|
44
69
|
return
|
|
45
70
|
}
|
|
@@ -49,7 +74,7 @@ export class LogRouteInspector extends FocusRouteInspector {
|
|
|
49
74
|
)
|
|
50
75
|
}
|
|
51
76
|
|
|
52
|
-
_routeName(obj) {
|
|
77
|
+
_routeName(obj: Route): string {
|
|
53
78
|
let name = obj.path || '<<no path defined>>'
|
|
54
79
|
if (obj.action) {
|
|
55
80
|
name = `'${name}' (to action '${obj.action.name}')`
|
|
@@ -57,21 +82,21 @@ export class LogRouteInspector extends FocusRouteInspector {
|
|
|
57
82
|
if (obj.redirect) {
|
|
58
83
|
name = `'${name}' (with redirect to '${obj.redirect}')`
|
|
59
84
|
}
|
|
60
|
-
|
|
61
|
-
return name
|
|
85
|
+
return name as string
|
|
62
86
|
}
|
|
63
87
|
|
|
64
|
-
_log(message, ...optionalParams) {
|
|
88
|
+
_log(message: string, ...optionalParams: string[]): void {
|
|
65
89
|
console.log(message, ...optionalParams)
|
|
66
90
|
}
|
|
67
91
|
}
|
|
68
92
|
|
|
69
93
|
export class Inspector {
|
|
70
|
-
|
|
94
|
+
routeInspector: RouteInspector
|
|
95
|
+
constructor(routeInspector: RouteInspector | undefined = undefined) {
|
|
71
96
|
this.routeInspector = routeInspector || new RouteInspector()
|
|
72
97
|
}
|
|
73
98
|
|
|
74
|
-
getRouteInspector() {
|
|
99
|
+
getRouteInspector(): RouteInspector {
|
|
75
100
|
return this.routeInspector
|
|
76
101
|
}
|
|
77
102
|
}
|
|
@@ -1,14 +1,45 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
2
|
|
|
3
|
+
import { PATH_PAYLOAD_IDENTIFIER } from './constants'
|
|
4
|
+
import { Session } from './models'
|
|
5
|
+
|
|
3
6
|
const HUBTYPE_API_URL = 'https://api.hubtype.com'
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
export interface HubtypeAgentsInfo {
|
|
9
|
+
attending_count: number
|
|
10
|
+
email: string
|
|
11
|
+
idle_count: number
|
|
12
|
+
last_message_sent: string
|
|
13
|
+
status: string
|
|
14
|
+
}
|
|
15
|
+
export interface HubtypeSession extends Session {
|
|
16
|
+
_hubtype_api?: string
|
|
17
|
+
_access_token: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SessionWithBotonicAction extends Session {
|
|
21
|
+
_botonic_action: string
|
|
22
|
+
}
|
|
23
|
+
export interface BackendContext {
|
|
24
|
+
timeoutMs: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface VacationRange {
|
|
28
|
+
end_date: number // timestamp
|
|
29
|
+
id: number
|
|
30
|
+
start_date: number // timestamp
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function contextDefaults(context: any): BackendContext {
|
|
6
34
|
return {
|
|
7
35
|
timeoutMs: context.timeoutMs || 10000,
|
|
8
36
|
}
|
|
9
37
|
}
|
|
10
38
|
|
|
11
|
-
export async function getOpenQueues(
|
|
39
|
+
export async function getOpenQueues(
|
|
40
|
+
session: HubtypeSession,
|
|
41
|
+
context = {}
|
|
42
|
+
): Promise<{ queues: string[] }> {
|
|
12
43
|
//be aware of https://github.com/axios/axios/issues/1543
|
|
13
44
|
const baseUrl = session._hubtype_api || HUBTYPE_API_URL
|
|
14
45
|
const endpointUrl = `${baseUrl}/v1/queues/get_open_queues/`
|
|
@@ -20,57 +51,66 @@ export async function getOpenQueues(session, context = {}) {
|
|
|
20
51
|
method: 'post',
|
|
21
52
|
url: endpointUrl,
|
|
22
53
|
data: { bot_id: session.bot.id },
|
|
23
|
-
timeout: context.timeoutMs,
|
|
54
|
+
timeout: (context as BackendContext).timeoutMs,
|
|
24
55
|
})
|
|
25
56
|
return resp.data
|
|
26
57
|
}
|
|
27
58
|
|
|
28
59
|
export class HandOffBuilder {
|
|
29
|
-
|
|
60
|
+
_session: SessionWithBotonicAction
|
|
61
|
+
_queue: string
|
|
62
|
+
_onFinish: string
|
|
63
|
+
_email: string
|
|
64
|
+
_agentId: string
|
|
65
|
+
_note: string
|
|
66
|
+
_caseInfo: string
|
|
67
|
+
_shadowing: boolean
|
|
68
|
+
|
|
69
|
+
constructor(session: SessionWithBotonicAction) {
|
|
30
70
|
this._session = session
|
|
31
71
|
}
|
|
32
72
|
|
|
33
|
-
withQueue(queueNameOrId) {
|
|
73
|
+
withQueue(queueNameOrId: string): this {
|
|
34
74
|
this._queue = queueNameOrId
|
|
35
75
|
return this
|
|
36
76
|
}
|
|
37
77
|
|
|
38
|
-
withOnFinishPayload(payload) {
|
|
78
|
+
withOnFinishPayload(payload: string): this {
|
|
39
79
|
this._onFinish = payload
|
|
40
80
|
return this
|
|
41
81
|
}
|
|
42
82
|
|
|
43
|
-
withOnFinishPath(path) {
|
|
44
|
-
this._onFinish =
|
|
83
|
+
withOnFinishPath(path: string): this {
|
|
84
|
+
this._onFinish = `${PATH_PAYLOAD_IDENTIFIER}${path}`
|
|
45
85
|
return this
|
|
46
86
|
}
|
|
47
87
|
|
|
48
|
-
withAgentEmail(email) {
|
|
88
|
+
withAgentEmail(email: string): this {
|
|
49
89
|
this._email = email
|
|
50
90
|
return this
|
|
51
91
|
}
|
|
52
92
|
|
|
53
|
-
withAgentId(agentId) {
|
|
93
|
+
withAgentId(agentId: string): this {
|
|
54
94
|
this._agentId = agentId
|
|
55
95
|
return this
|
|
56
96
|
}
|
|
57
97
|
|
|
58
|
-
withNote(note) {
|
|
98
|
+
withNote(note: string): this {
|
|
59
99
|
this._note = note
|
|
60
100
|
return this
|
|
61
101
|
}
|
|
62
102
|
|
|
63
|
-
withCaseInfo(caseInfo) {
|
|
103
|
+
withCaseInfo(caseInfo: string): this {
|
|
64
104
|
this._caseInfo = caseInfo
|
|
65
105
|
return this
|
|
66
106
|
}
|
|
67
107
|
|
|
68
|
-
withShadowing(shadowing = true) {
|
|
108
|
+
withShadowing(shadowing = true): this {
|
|
69
109
|
this._shadowing = shadowing
|
|
70
110
|
return this
|
|
71
111
|
}
|
|
72
112
|
|
|
73
|
-
async handOff() {
|
|
113
|
+
async handOff(): Promise<void> {
|
|
74
114
|
return _humanHandOff(
|
|
75
115
|
this._session,
|
|
76
116
|
this._queue,
|
|
@@ -104,17 +144,26 @@ export async function humanHandOff(session, queueNameOrId = '', onFinish) {
|
|
|
104
144
|
return builder.handOff()
|
|
105
145
|
}
|
|
106
146
|
|
|
147
|
+
interface HubtypeHandoffParams {
|
|
148
|
+
queue?: string
|
|
149
|
+
agent_email?: string
|
|
150
|
+
agent_id?: string
|
|
151
|
+
case_info?: string
|
|
152
|
+
note?: string
|
|
153
|
+
shadowing?: boolean
|
|
154
|
+
on_finish?: string
|
|
155
|
+
}
|
|
107
156
|
async function _humanHandOff(
|
|
108
|
-
session,
|
|
157
|
+
session: SessionWithBotonicAction,
|
|
109
158
|
queueNameOrId = '',
|
|
110
|
-
onFinish,
|
|
159
|
+
onFinish: string,
|
|
111
160
|
agentEmail = '',
|
|
112
161
|
agentId = '',
|
|
113
162
|
caseInfo = '',
|
|
114
163
|
note = '',
|
|
115
164
|
shadowing = false
|
|
116
165
|
) {
|
|
117
|
-
const params = {}
|
|
166
|
+
const params: HubtypeHandoffParams = {}
|
|
118
167
|
if (queueNameOrId) {
|
|
119
168
|
params.queue = queueNameOrId
|
|
120
169
|
}
|
|
@@ -139,7 +188,11 @@ async function _humanHandOff(
|
|
|
139
188
|
session._botonic_action = `create_case:${JSON.stringify(params)}`
|
|
140
189
|
}
|
|
141
190
|
|
|
142
|
-
export async function storeCaseRating(
|
|
191
|
+
export async function storeCaseRating(
|
|
192
|
+
session: HubtypeSession,
|
|
193
|
+
rating: number,
|
|
194
|
+
context: any = {}
|
|
195
|
+
): Promise<{ status: string }> {
|
|
143
196
|
const baseUrl = session._hubtype_api || HUBTYPE_API_URL
|
|
144
197
|
const chatId = session.user.id
|
|
145
198
|
context = contextDefaults(context)
|
|
@@ -150,12 +203,15 @@ export async function storeCaseRating(session, rating, context = {}) {
|
|
|
150
203
|
method: 'post',
|
|
151
204
|
url: `${baseUrl}/v1/chats/${chatId}/store_case_rating/`,
|
|
152
205
|
data: { chat_id: chatId, rating },
|
|
153
|
-
timeout: context.timeoutMs,
|
|
206
|
+
timeout: (context as BackendContext).timeoutMs,
|
|
154
207
|
})
|
|
155
208
|
return resp.data
|
|
156
209
|
}
|
|
157
210
|
|
|
158
|
-
export async function getAvailableAgentsByQueue(
|
|
211
|
+
export async function getAvailableAgentsByQueue(
|
|
212
|
+
session: HubtypeSession,
|
|
213
|
+
queueId: string
|
|
214
|
+
): Promise<{ agents: string[] }> {
|
|
159
215
|
const baseUrl = session._hubtype_api || HUBTYPE_API_URL
|
|
160
216
|
const resp = await axios({
|
|
161
217
|
headers: {
|
|
@@ -167,7 +223,9 @@ export async function getAvailableAgentsByQueue(session, queueId) {
|
|
|
167
223
|
return resp.data
|
|
168
224
|
}
|
|
169
225
|
|
|
170
|
-
export async function getAvailableAgents(
|
|
226
|
+
export async function getAvailableAgents(
|
|
227
|
+
session: HubtypeSession
|
|
228
|
+
): Promise<{ agents: HubtypeAgentsInfo[] }> {
|
|
171
229
|
const baseUrl = session._hubtype_api || HUBTYPE_API_URL
|
|
172
230
|
const botId = session.bot.id
|
|
173
231
|
const resp = await axios({
|
|
@@ -180,7 +238,10 @@ export async function getAvailableAgents(session) {
|
|
|
180
238
|
return resp.data
|
|
181
239
|
}
|
|
182
240
|
|
|
183
|
-
export async function getAgentVacationRanges(
|
|
241
|
+
export async function getAgentVacationRanges(
|
|
242
|
+
session: HubtypeSession,
|
|
243
|
+
{ agentId, agentEmail }: { agentId?: string; agentEmail?: string }
|
|
244
|
+
): Promise<{ vacation_ranges: VacationRange[] }> {
|
|
184
245
|
const baseUrl = session._hubtype_api || HUBTYPE_API_URL
|
|
185
246
|
const botId = session.bot.id
|
|
186
247
|
const resp = await axios({
|
|
@@ -194,12 +255,15 @@ export async function getAgentVacationRanges(session, { agentId, agentEmail }) {
|
|
|
194
255
|
return resp.data
|
|
195
256
|
}
|
|
196
257
|
|
|
197
|
-
export function cancelHandoff(
|
|
258
|
+
export function cancelHandoff(
|
|
259
|
+
session: SessionWithBotonicAction,
|
|
260
|
+
typification: string | null = null
|
|
261
|
+
): void {
|
|
198
262
|
let action = 'discard_case'
|
|
199
263
|
if (typification) action = `${action}:${JSON.stringify({ typification })}`
|
|
200
264
|
session._botonic_action = action
|
|
201
265
|
}
|
|
202
266
|
|
|
203
|
-
export function deleteUser(session) {
|
|
267
|
+
export function deleteUser(session: SessionWithBotonicAction): void {
|
|
204
268
|
session._botonic_action = `delete_user`
|
|
205
269
|
}
|
|
@@ -1,16 +1,43 @@
|
|
|
1
|
-
import axios from 'axios'
|
|
2
|
-
import Pusher from 'pusher-js'
|
|
1
|
+
import axios, { AxiosResponse } from 'axios'
|
|
2
|
+
import Pusher, { AuthOptions, Channel } from 'pusher-js'
|
|
3
|
+
import Channels from 'pusher-js/types/src/core/channels/channels'
|
|
3
4
|
|
|
5
|
+
import { Input, SessionUser } from './models'
|
|
6
|
+
import { decompressData } from './pusher-utils'
|
|
4
7
|
import { getWebpackEnvVar } from './utils'
|
|
5
8
|
|
|
9
|
+
interface UnsentInput {
|
|
10
|
+
id: string
|
|
11
|
+
ack: number
|
|
12
|
+
unsentInput: Input
|
|
13
|
+
}
|
|
14
|
+
interface BotonicHeaders {
|
|
15
|
+
'X-BOTONIC-USER-ID': string
|
|
16
|
+
'X-BOTONIC-LAST-MESSAGE-ID': string
|
|
17
|
+
'X-BOTONIC-LAST-MESSAGE-UPDATE-DATE': string
|
|
18
|
+
}
|
|
19
|
+
interface ServerConfig {
|
|
20
|
+
activityTimeout?: number
|
|
21
|
+
pongTimeout?: number
|
|
22
|
+
}
|
|
23
|
+
interface HubtypeServiceArgs {
|
|
24
|
+
appId: string
|
|
25
|
+
user: SessionUser
|
|
26
|
+
lastMessageId: string
|
|
27
|
+
lastMessageUpdateDate: string
|
|
28
|
+
onEvent: any
|
|
29
|
+
unsentInputs: () => UnsentInput[]
|
|
30
|
+
server: ServerConfig
|
|
31
|
+
}
|
|
32
|
+
|
|
6
33
|
const _WEBCHAT_PUSHER_KEY_ = getWebpackEnvVar(
|
|
7
|
-
//
|
|
34
|
+
// @ts-ignore
|
|
8
35
|
typeof WEBCHAT_PUSHER_KEY !== 'undefined' && WEBCHAT_PUSHER_KEY,
|
|
9
36
|
'WEBCHAT_PUSHER_KEY',
|
|
10
37
|
'434ca667c8e6cb3f641c'
|
|
11
38
|
)
|
|
12
39
|
const _HUBTYPE_API_URL_ = getWebpackEnvVar(
|
|
13
|
-
//
|
|
40
|
+
// @ts-ignore
|
|
14
41
|
typeof HUBTYPE_API_URL !== 'undefined' && HUBTYPE_API_URL,
|
|
15
42
|
'HUBTYPE_API_URL',
|
|
16
43
|
'https://api.hubtype.com'
|
|
@@ -23,6 +50,15 @@ const PONG_TIMEOUT = 5 * 1000 // https://pusher.com/docs/channels/using_channels
|
|
|
23
50
|
* Calls Hubtype APIs from Webchat
|
|
24
51
|
*/
|
|
25
52
|
export class HubtypeService {
|
|
53
|
+
appId: string
|
|
54
|
+
user: SessionUser
|
|
55
|
+
lastMessageId: string
|
|
56
|
+
lastMessageUpdateDate: string
|
|
57
|
+
onEvent: any
|
|
58
|
+
unsentInputs: () => UnsentInput[]
|
|
59
|
+
pusher: Pusher | null
|
|
60
|
+
channel: Channel
|
|
61
|
+
server: ServerConfig
|
|
26
62
|
PUSHER_CONNECT_TIMEOUT_MS = 10000
|
|
27
63
|
constructor({
|
|
28
64
|
appId,
|
|
@@ -32,7 +68,7 @@ export class HubtypeService {
|
|
|
32
68
|
onEvent,
|
|
33
69
|
unsentInputs,
|
|
34
70
|
server,
|
|
35
|
-
}) {
|
|
71
|
+
}: HubtypeServiceArgs) {
|
|
36
72
|
this.appId = appId
|
|
37
73
|
this.user = user || {}
|
|
38
74
|
this.lastMessageId = lastMessageId
|
|
@@ -44,6 +80,7 @@ export class HubtypeService {
|
|
|
44
80
|
// It's safe not awaiting Promise because:
|
|
45
81
|
// * it will never be called from AWS lambda
|
|
46
82
|
// * though init() is called again from postMesage, it does nothing if Pusher already created
|
|
83
|
+
// @ts-ignore
|
|
47
84
|
this.init()
|
|
48
85
|
}
|
|
49
86
|
}
|
|
@@ -51,7 +88,7 @@ export class HubtypeService {
|
|
|
51
88
|
/**
|
|
52
89
|
* @returns {Promise<void>}
|
|
53
90
|
*/
|
|
54
|
-
init(user, lastMessageId, lastMessageUpdateDate) {
|
|
91
|
+
init(user, lastMessageId, lastMessageUpdateDate): Promise<void> {
|
|
55
92
|
if (user) this.user = user
|
|
56
93
|
if (lastMessageId) this.lastMessageId = lastMessageId
|
|
57
94
|
if (lastMessageUpdateDate)
|
|
@@ -62,7 +99,7 @@ export class HubtypeService {
|
|
|
62
99
|
/**
|
|
63
100
|
* @returns {Promise<void>}
|
|
64
101
|
*/
|
|
65
|
-
_initPusher() {
|
|
102
|
+
_initPusher(): Promise<void> {
|
|
66
103
|
if (this.pusher) return Promise.resolve()
|
|
67
104
|
if (!this.user.id || !this.appId) {
|
|
68
105
|
// TODO recover user & appId somehow
|
|
@@ -74,11 +111,11 @@ export class HubtypeService {
|
|
|
74
111
|
forceTLS: true,
|
|
75
112
|
auth: {
|
|
76
113
|
headers: this.constructHeaders(),
|
|
77
|
-
},
|
|
114
|
+
} as AuthOptions,
|
|
78
115
|
...this.resolveServerConfig(),
|
|
79
116
|
})
|
|
80
117
|
this.channel = this.pusher.subscribe(this.pusherChannel)
|
|
81
|
-
const connectionPromise = new Promise((resolve, reject) => {
|
|
118
|
+
const connectionPromise = new Promise<void>((resolve, reject) => {
|
|
82
119
|
const cleanAndReject = msg => {
|
|
83
120
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
84
121
|
clearTimeout(connectTimeout)
|
|
@@ -96,18 +133,27 @@ export class HubtypeService {
|
|
|
96
133
|
resolve()
|
|
97
134
|
})
|
|
98
135
|
this.channel.bind('botonic_response', data => this.onPusherEvent(data))
|
|
99
|
-
this.channel.bind('
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
event.error && event.error.data
|
|
106
|
-
? event.error.data.code || event.error.data.message
|
|
107
|
-
: 'Connection error'
|
|
108
|
-
cleanAndReject(`Pusher error (${errorMsg})`)
|
|
136
|
+
this.channel.bind('botonic_response_compressed', compressedData => {
|
|
137
|
+
try {
|
|
138
|
+
const data = JSON.parse(decompressData(compressedData))
|
|
139
|
+
this.onPusherEvent(data)
|
|
140
|
+
} catch (e) {
|
|
141
|
+
console.error('Error: Unable to decompress data', e)
|
|
109
142
|
}
|
|
110
143
|
})
|
|
144
|
+
this.channel.bind('update_message_info', data => this.onPusherEvent(data))
|
|
145
|
+
|
|
146
|
+
this.pusher &&
|
|
147
|
+
this.pusher.connection.bind('error', event => {
|
|
148
|
+
if (event.type == 'WebSocketError') this.handleConnectionChange(false)
|
|
149
|
+
else {
|
|
150
|
+
const errorMsg =
|
|
151
|
+
event.error && event.error.data
|
|
152
|
+
? event.error.data.code || event.error.data.message
|
|
153
|
+
: 'Connection error'
|
|
154
|
+
cleanAndReject(`Pusher error (${errorMsg})`)
|
|
155
|
+
}
|
|
156
|
+
})
|
|
111
157
|
})
|
|
112
158
|
this.pusher.connection.bind('state_change', states => {
|
|
113
159
|
if (states.current === 'connecting') this.updateAuthHeaders()
|
|
@@ -118,17 +164,17 @@ export class HubtypeService {
|
|
|
118
164
|
return connectionPromise
|
|
119
165
|
}
|
|
120
166
|
|
|
121
|
-
constructHeaders() {
|
|
167
|
+
constructHeaders(): BotonicHeaders {
|
|
122
168
|
const headers = {}
|
|
123
169
|
if (this.user && this.user.id) headers['X-BOTONIC-USER-ID'] = this.user.id
|
|
124
170
|
if (this.lastMessageId)
|
|
125
171
|
headers['X-BOTONIC-LAST-MESSAGE-ID'] = this.lastMessageId
|
|
126
172
|
if (this.lastMessageUpdateDate)
|
|
127
173
|
headers['X-BOTONIC-LAST-MESSAGE-UPDATE-DATE'] = this.lastMessageUpdateDate
|
|
128
|
-
return headers
|
|
174
|
+
return headers as BotonicHeaders
|
|
129
175
|
}
|
|
130
176
|
|
|
131
|
-
resolveServerConfig() {
|
|
177
|
+
resolveServerConfig(): ServerConfig {
|
|
132
178
|
if (!this.server) {
|
|
133
179
|
return { activityTimeout: ACTIVITY_TIMEOUT, pongTimeout: PONG_TIMEOUT }
|
|
134
180
|
}
|
|
@@ -138,7 +184,7 @@ export class HubtypeService {
|
|
|
138
184
|
}
|
|
139
185
|
}
|
|
140
186
|
|
|
141
|
-
updateAuthHeaders() {
|
|
187
|
+
updateAuthHeaders(): void {
|
|
142
188
|
if (this.pusher) {
|
|
143
189
|
this.pusher.config.auth.headers = {
|
|
144
190
|
...this.pusher.config.auth.headers,
|
|
@@ -147,26 +193,26 @@ export class HubtypeService {
|
|
|
147
193
|
}
|
|
148
194
|
}
|
|
149
195
|
|
|
150
|
-
handleConnectionChange(online) {
|
|
196
|
+
handleConnectionChange(online: boolean): void {
|
|
151
197
|
this.onPusherEvent({ action: 'connectionChange', online })
|
|
152
198
|
}
|
|
153
199
|
|
|
154
|
-
onPusherEvent(event) {
|
|
200
|
+
onPusherEvent(event: any): void {
|
|
155
201
|
if (this.onEvent && typeof this.onEvent === 'function') this.onEvent(event)
|
|
156
202
|
}
|
|
157
203
|
|
|
158
|
-
get pusherChannel() {
|
|
204
|
+
get pusherChannel(): string {
|
|
159
205
|
return `private-encrypted-${this.appId}-${this.user.id}`
|
|
160
206
|
}
|
|
161
207
|
|
|
162
|
-
handleSentInput(message) {
|
|
208
|
+
handleSentInput(message: any): void {
|
|
163
209
|
this.onEvent({
|
|
164
210
|
action: 'update_message_info',
|
|
165
211
|
message: { id: message.id, ack: 1 },
|
|
166
212
|
})
|
|
167
213
|
}
|
|
168
214
|
|
|
169
|
-
handleUnsentInput(message) {
|
|
215
|
+
handleUnsentInput(message: any): void {
|
|
170
216
|
this.onEvent({
|
|
171
217
|
action: 'update_message_info',
|
|
172
218
|
message: { id: message.id, ack: 0, unsentInput: message },
|
|
@@ -176,8 +222,9 @@ export class HubtypeService {
|
|
|
176
222
|
/**
|
|
177
223
|
* @return {Promise<void>}
|
|
178
224
|
*/
|
|
179
|
-
async postMessage(user, message) {
|
|
225
|
+
async postMessage(user: SessionUser, message: any): Promise<void> {
|
|
180
226
|
try {
|
|
227
|
+
// @ts-ignore
|
|
181
228
|
await this.init(user)
|
|
182
229
|
await axios.post(
|
|
183
230
|
`${_HUBTYPE_API_URL_}/v1/provider_accounts/webhooks/webchat/${this.appId}/`,
|
|
@@ -196,26 +243,30 @@ export class HubtypeService {
|
|
|
196
243
|
return Promise.resolve()
|
|
197
244
|
}
|
|
198
245
|
|
|
199
|
-
static async getWebchatVisibility({
|
|
246
|
+
static async getWebchatVisibility({
|
|
247
|
+
appId,
|
|
248
|
+
}: {
|
|
249
|
+
appId: string
|
|
250
|
+
}): Promise<AxiosResponse<any>> {
|
|
200
251
|
return axios.get(
|
|
201
252
|
`${_HUBTYPE_API_URL_}/v1/provider_accounts/${appId}/visibility/`
|
|
202
253
|
)
|
|
203
254
|
}
|
|
204
255
|
|
|
205
|
-
destroyPusher() {
|
|
256
|
+
destroyPusher(): void {
|
|
206
257
|
if (!this.pusher) return
|
|
207
258
|
this.pusher.disconnect()
|
|
208
259
|
this.pusher.unsubscribe(this.pusherChannel)
|
|
209
260
|
this.pusher.unbind_all()
|
|
210
|
-
this.pusher.channels = {}
|
|
261
|
+
this.pusher.channels = {} as Channels
|
|
211
262
|
this.pusher = null
|
|
212
263
|
}
|
|
213
264
|
|
|
214
|
-
async onConnectionRegained() {
|
|
265
|
+
async onConnectionRegained(): Promise<void> {
|
|
215
266
|
await this.resendUnsentInputs()
|
|
216
267
|
}
|
|
217
268
|
|
|
218
|
-
async resendUnsentInputs() {
|
|
269
|
+
async resendUnsentInputs(): Promise<void> {
|
|
219
270
|
for (const message of this.unsentInputs()) {
|
|
220
271
|
message.unsentInput &&
|
|
221
272
|
(await this.postMessage(this.user, message.unsentInput))
|
package/src/{i18n.js → i18n.ts}
RENAMED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
// eslint-disable-next-line filenames/match-regex
|
|
2
|
-
|
|
2
|
+
import { Locales } from './models'
|
|
3
|
+
|
|
4
|
+
export const getString = (
|
|
5
|
+
locales: Locales,
|
|
6
|
+
locale: string,
|
|
7
|
+
stringID: string
|
|
8
|
+
): string => {
|
|
3
9
|
let l = stringID.split('.').reduce((o, i) => o[i], locales[locale])
|
|
4
10
|
if (l instanceof Array) l = l[Math.floor(Math.random() * l.length)]
|
|
5
11
|
return String(l)
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './constants'
|
|
2
|
+
export * from './core-bot'
|
|
3
|
+
// TODO: Review @botonic/react's tree-shaking to remove dataProvider from bundle
|
|
4
|
+
// export * from './data-provider'
|
|
5
|
+
export * from './debug'
|
|
6
|
+
export * from './handoff'
|
|
7
|
+
export * from './hubtype-service'
|
|
8
|
+
export * from './i18n'
|
|
9
|
+
export * from './models'
|
|
10
|
+
export * from './output-parser'
|
|
11
|
+
export * from './plugins'
|
|
12
|
+
export * from './routing'
|
|
13
|
+
export * from './utils'
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export enum EventTypes {
|
|
2
|
+
CONNECTION = 'connection',
|
|
3
|
+
MESSAGE = 'message',
|
|
4
|
+
ACK = 'ack',
|
|
5
|
+
TRACK = 'track',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface BaseEvent {
|
|
9
|
+
eventId: string
|
|
10
|
+
userId: string
|
|
11
|
+
eventType: EventTypes
|
|
12
|
+
createdAt: string
|
|
13
|
+
modifiedAt?: string
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ConnectionEvent } from './connections'
|
|
2
|
+
import {
|
|
3
|
+
AudioMessageEvent,
|
|
4
|
+
CarouselMessageEvent,
|
|
5
|
+
CustomMessageEvent,
|
|
6
|
+
DocumentMessageEvent,
|
|
7
|
+
ImageMessageEvent,
|
|
8
|
+
LocationMessageEvent,
|
|
9
|
+
PostbackMessageEvent,
|
|
10
|
+
TextMessageEvent,
|
|
11
|
+
VideoMessageEvent,
|
|
12
|
+
} from './message'
|
|
13
|
+
|
|
14
|
+
export type BotonicEvent =
|
|
15
|
+
| TextMessageEvent
|
|
16
|
+
| PostbackMessageEvent
|
|
17
|
+
| AudioMessageEvent
|
|
18
|
+
| DocumentMessageEvent
|
|
19
|
+
| ImageMessageEvent
|
|
20
|
+
| VideoMessageEvent
|
|
21
|
+
| LocationMessageEvent
|
|
22
|
+
| CarouselMessageEvent
|
|
23
|
+
| CustomMessageEvent
|
|
24
|
+
| ConnectionEvent
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseEvent, EventTypes } from '../base-event'
|
|
2
|
+
|
|
3
|
+
export enum ConnectionEventStatuses {
|
|
4
|
+
CONNECTED = 'connected',
|
|
5
|
+
DISCONNECTED = 'disconnected',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ConnectionEvent extends BaseEvent {
|
|
9
|
+
eventType: EventTypes.CONNECTION
|
|
10
|
+
status: ConnectionEventStatuses
|
|
11
|
+
}
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export enum ConnectionEventStatuses {
|
|
4
|
-
CONNECTED = 'connected',
|
|
5
|
-
DISCONNECTED = 'disconnected',
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface ConnectionEvent extends BaseEvent {
|
|
9
|
-
eventType: EventTypes.CONNECTION
|
|
10
|
-
status: ConnectionEventStatuses
|
|
11
|
-
}
|
|
1
|
+
export * from './connection-event'
|