@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,39 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
AudioMessageEvent,
|
|
7
|
-
DocumentMessageEvent,
|
|
8
|
-
ImageMessageEvent,
|
|
9
|
-
VideoMessageEvent,
|
|
10
|
-
} from './message/media'
|
|
11
|
-
import { PostbackMessageEvent } from './message/postback'
|
|
12
|
-
import { TextMessageEvent } from './message/text'
|
|
13
|
-
|
|
14
|
-
export enum EventTypes {
|
|
15
|
-
CONNECTION = 'connection',
|
|
16
|
-
MESSAGE = 'message',
|
|
17
|
-
ACK = 'ack',
|
|
18
|
-
TRACK = 'track',
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface BaseEvent {
|
|
22
|
-
eventId: string
|
|
23
|
-
userId: string
|
|
24
|
-
eventType: EventTypes
|
|
25
|
-
createdAt: string
|
|
26
|
-
modifiedAt?: string
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export type BotonicEvent =
|
|
30
|
-
| TextMessageEvent
|
|
31
|
-
| PostbackMessageEvent
|
|
32
|
-
| AudioMessageEvent
|
|
33
|
-
| DocumentMessageEvent
|
|
34
|
-
| ImageMessageEvent
|
|
35
|
-
| VideoMessageEvent
|
|
36
|
-
| LocationMessageEvent
|
|
37
|
-
| CarouselMessageEvent
|
|
38
|
-
| CustomMessageEvent
|
|
39
|
-
| ConnectionEvent
|
|
1
|
+
export * from './base-event'
|
|
2
|
+
export * from './botonic-event'
|
|
3
|
+
export * from './connection'
|
|
4
|
+
export * from './message'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './integration-event'
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseEvent, EventTypes } from '../base-event'
|
|
2
|
+
|
|
3
|
+
export type IntegrationEventType =
|
|
4
|
+
| EventTypes.NEW_USER
|
|
5
|
+
| EventTypes.RECEIVED_MESSAGE
|
|
6
|
+
| EventTypes.BOT_EXECUTED
|
|
7
|
+
| EventTypes.BOT_ACTION
|
|
8
|
+
| EventTypes.ACTION_SENT
|
|
9
|
+
|
|
10
|
+
export interface IntegrationEvent extends BaseEvent {
|
|
11
|
+
eventType: IntegrationEventType
|
|
12
|
+
details: any
|
|
13
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BotonicMessageEvent, MessageEventTypes } from '
|
|
1
|
+
import { BotonicMessageEvent, MessageEventTypes } from './message-event'
|
|
2
2
|
import { WithReplies } from './replies'
|
|
3
3
|
|
|
4
4
|
export interface CustomMessageEvent extends BotonicMessageEvent, WithReplies {
|
|
5
5
|
type: MessageEventTypes.CUSTOM
|
|
6
|
-
|
|
6
|
+
json: any
|
|
7
7
|
}
|
|
@@ -1,37 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
TEXT = 'text',
|
|
11
|
-
POSTBACK = 'postback',
|
|
12
|
-
VIDEO = 'video',
|
|
13
|
-
/**
|
|
14
|
-
* TODO: contact, buttonmessage?, webchatsettings, whatsapp template
|
|
15
|
-
*/
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export enum MessageEventAck {
|
|
19
|
-
DRAFT = 'draft',
|
|
20
|
-
READ = 'read',
|
|
21
|
-
RECEIVED = 'received',
|
|
22
|
-
SENT = 'sent',
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export enum MessageEventFrom {
|
|
26
|
-
AGENT = 'agent',
|
|
27
|
-
BOT = 'bot',
|
|
28
|
-
USER = 'user',
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface BotonicMessageEvent extends BaseEvent {
|
|
32
|
-
ack: MessageEventAck
|
|
33
|
-
from: MessageEventFrom
|
|
34
|
-
type: MessageEventTypes
|
|
35
|
-
typing: number
|
|
36
|
-
delay: number
|
|
37
|
-
}
|
|
1
|
+
export * from './buttons'
|
|
2
|
+
export * from './carousel'
|
|
3
|
+
export * from './custom'
|
|
4
|
+
export * from './location'
|
|
5
|
+
export * from './media'
|
|
6
|
+
export * from './message-event'
|
|
7
|
+
export * from './postback'
|
|
8
|
+
export * from './replies'
|
|
9
|
+
export * from './text'
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BaseEvent } from '../base-event'
|
|
2
|
+
|
|
3
|
+
export enum MessageEventTypes {
|
|
4
|
+
AUDIO = 'audio',
|
|
5
|
+
CAROUSEL = 'carousel',
|
|
6
|
+
CUSTOM = 'custom',
|
|
7
|
+
DOCUMENT = 'document',
|
|
8
|
+
IMAGE = 'image',
|
|
9
|
+
LOCATION = 'location',
|
|
10
|
+
TEXT = 'text',
|
|
11
|
+
POSTBACK = 'postback',
|
|
12
|
+
VIDEO = 'video',
|
|
13
|
+
/**
|
|
14
|
+
* TODO: contact, buttonmessage?, webchatsettings, whatsapp template
|
|
15
|
+
*/
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export enum MessageEventAck {
|
|
19
|
+
DRAFT = 'draft',
|
|
20
|
+
READ = 'read',
|
|
21
|
+
RECEIVED = 'received',
|
|
22
|
+
SENT = 'sent',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export enum MessageEventFrom {
|
|
26
|
+
AGENT = 'agent',
|
|
27
|
+
BOT = 'bot',
|
|
28
|
+
USER = 'user',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface BotonicMessageEvent extends BaseEvent {
|
|
32
|
+
ack: MessageEventAck
|
|
33
|
+
from: MessageEventFrom
|
|
34
|
+
type: MessageEventTypes
|
|
35
|
+
typing: number
|
|
36
|
+
delay: number
|
|
37
|
+
}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
// TODO: This file contains all the legacy types we had in index.ts. After some refactors, we should be able to get rid of many of them.
|
|
2
|
+
import { BotState } from './bot-state'
|
|
3
|
+
import { BotonicEvent } from './events'
|
|
4
|
+
import { Session } from './session'
|
|
5
|
+
|
|
6
|
+
export type CaseStatusType =
|
|
7
|
+
| typeof CASE_STATUS.ATTENDING
|
|
8
|
+
| typeof CASE_STATUS.IDLE
|
|
9
|
+
| typeof CASE_STATUS.RESOLVED
|
|
10
|
+
| typeof CASE_STATUS.WAITING
|
|
11
|
+
|
|
12
|
+
export type CaseResolution =
|
|
13
|
+
| typeof CASE_RESOLUTION.BANNED
|
|
14
|
+
| typeof CASE_RESOLUTION.NOK
|
|
15
|
+
| typeof CASE_RESOLUTION.NOT_SOLVED
|
|
16
|
+
| typeof CASE_RESOLUTION.OK
|
|
17
|
+
|
|
18
|
+
export const PROVIDER = Object.freeze({
|
|
19
|
+
DEV: 'dev',
|
|
20
|
+
FACEBOOK: 'facebook',
|
|
21
|
+
GENERIC: 'generic',
|
|
22
|
+
INTERCOM: 'intercom',
|
|
23
|
+
SMOOCH: 'smooch',
|
|
24
|
+
TELEGRAM: 'telegram',
|
|
25
|
+
TWITTER: 'twitter',
|
|
26
|
+
WEBCHAT: 'webchat',
|
|
27
|
+
WECHAT: 'wechat',
|
|
28
|
+
WHATSAPP: 'whatsapp',
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
export const INPUT = Object.freeze({
|
|
32
|
+
TEXT: 'text',
|
|
33
|
+
POSTBACK: 'postback',
|
|
34
|
+
AUDIO: 'audio',
|
|
35
|
+
IMAGE: 'image',
|
|
36
|
+
VIDEO: 'video',
|
|
37
|
+
DOCUMENT: 'document',
|
|
38
|
+
LOCATION: 'location',
|
|
39
|
+
CONTACT: 'contact',
|
|
40
|
+
BUTTON_MESSAGE: 'buttonmessage',
|
|
41
|
+
CAROUSEL: 'carousel',
|
|
42
|
+
CUSTOM: 'custom',
|
|
43
|
+
WEBCHAT_SETTINGS: 'webchatsettings',
|
|
44
|
+
WHATSAPP_TEMPLATE: 'whatsapptemplate',
|
|
45
|
+
RAW: 'raw',
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
export const CASE_STATUS = Object.freeze({
|
|
49
|
+
WAITING: 'status_waiting',
|
|
50
|
+
ATTENDING: 'status_attending',
|
|
51
|
+
IDLE: 'status_idle',
|
|
52
|
+
RESOLVED: 'status_resolved',
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
export const CASE_RESOLUTION = Object.freeze({
|
|
56
|
+
OK: 'result_ok',
|
|
57
|
+
NOK: 'result_nok',
|
|
58
|
+
NOT_SOLVED: 'result_not_solved',
|
|
59
|
+
BANNED: 'result_banned',
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
export interface Locales {
|
|
63
|
+
[id: string]: string | string[] | Locales
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface PluginConstructor<T> {
|
|
67
|
+
new (arg: T): Plugin
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface PluginConfig<T> {
|
|
71
|
+
id: string
|
|
72
|
+
options?: T
|
|
73
|
+
resolve: { default: PluginConstructor<T> }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type InputType =
|
|
77
|
+
| typeof INPUT.AUDIO
|
|
78
|
+
| typeof INPUT.BUTTON_MESSAGE
|
|
79
|
+
| typeof INPUT.CAROUSEL
|
|
80
|
+
| typeof INPUT.CONTACT
|
|
81
|
+
| typeof INPUT.CUSTOM
|
|
82
|
+
| typeof INPUT.DOCUMENT
|
|
83
|
+
| typeof INPUT.IMAGE
|
|
84
|
+
| typeof INPUT.LOCATION
|
|
85
|
+
| typeof INPUT.POSTBACK
|
|
86
|
+
| typeof INPUT.TEXT
|
|
87
|
+
| typeof INPUT.VIDEO
|
|
88
|
+
| typeof INPUT.WEBCHAT_SETTINGS
|
|
89
|
+
| typeof INPUT.WHATSAPP_TEMPLATE
|
|
90
|
+
|
|
91
|
+
export interface IntentResult {
|
|
92
|
+
intent: string
|
|
93
|
+
confidence: number
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Generated by Translation plugins: GoogleTranslation **/
|
|
97
|
+
export interface Translations {
|
|
98
|
+
[languageCode: string]: string
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Fields set by NLU plugins: Luis, Dialogflow, ... **/
|
|
102
|
+
export interface NluResult {
|
|
103
|
+
// the name of the highest confidence intent
|
|
104
|
+
confidence: number
|
|
105
|
+
intent: string
|
|
106
|
+
intents: IntentResult[]
|
|
107
|
+
language: string
|
|
108
|
+
// entity recognition results in the format provided by the NLU engine
|
|
109
|
+
entities?: any
|
|
110
|
+
translations: Translations
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface Input extends Partial<NluResult> {
|
|
114
|
+
text?: string
|
|
115
|
+
src?: string
|
|
116
|
+
data?: string
|
|
117
|
+
path?: string
|
|
118
|
+
payload?: string
|
|
119
|
+
type: InputType
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export type ProviderType =
|
|
123
|
+
| typeof PROVIDER.DEV
|
|
124
|
+
| typeof PROVIDER.FACEBOOK
|
|
125
|
+
| typeof PROVIDER.GENERIC
|
|
126
|
+
| typeof PROVIDER.INTERCOM
|
|
127
|
+
| typeof PROVIDER.SMOOCH
|
|
128
|
+
| typeof PROVIDER.TELEGRAM
|
|
129
|
+
| typeof PROVIDER.TWITTER
|
|
130
|
+
| typeof PROVIDER.WEBCHAT
|
|
131
|
+
| typeof PROVIDER.WECHAT
|
|
132
|
+
| typeof PROVIDER.WHATSAPP
|
|
133
|
+
|
|
134
|
+
// eslint-enable @typescript-eslint/naming-convention
|
|
135
|
+
|
|
136
|
+
export type InputMatcher = (input: Input) => boolean
|
|
137
|
+
export type ParamsMatcher =
|
|
138
|
+
| { [key: string]: string }
|
|
139
|
+
| ((params: { [key: string]: string }) => boolean)
|
|
140
|
+
export type SessionMatcher = (session: Session) => boolean
|
|
141
|
+
export type RequestMatcher = (request: BotRequest) => boolean
|
|
142
|
+
export type StringMatcher = RegExp | string | ((data: string) => boolean)
|
|
143
|
+
|
|
144
|
+
export type RouteMatcher =
|
|
145
|
+
| InputMatcher
|
|
146
|
+
| ParamsMatcher
|
|
147
|
+
| RequestMatcher
|
|
148
|
+
| SessionMatcher
|
|
149
|
+
| StringMatcher
|
|
150
|
+
|
|
151
|
+
export interface Route {
|
|
152
|
+
action?: any
|
|
153
|
+
childRoutes?: Route[]
|
|
154
|
+
lastRoutePath?: string
|
|
155
|
+
ignoreRetry?: boolean
|
|
156
|
+
path: RoutePath
|
|
157
|
+
redirect?: string
|
|
158
|
+
retry?: number
|
|
159
|
+
|
|
160
|
+
// matchers
|
|
161
|
+
input?: InputMatcher
|
|
162
|
+
intent?: StringMatcher
|
|
163
|
+
params?: ParamsMatcher
|
|
164
|
+
payload?: StringMatcher
|
|
165
|
+
request?: RequestMatcher
|
|
166
|
+
session?: SessionMatcher
|
|
167
|
+
text?: StringMatcher
|
|
168
|
+
data?: StringMatcher
|
|
169
|
+
type?: StringMatcher
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export type Routes<R = Route> = R[] | ((_: BotRequest) => R[])
|
|
173
|
+
|
|
174
|
+
export interface BotRequest {
|
|
175
|
+
input: Input
|
|
176
|
+
session: Session
|
|
177
|
+
botState: BotState
|
|
178
|
+
dataProvider?: any // TODO: type as dataProvider
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The response of the bot for the triggered actions, which can be
|
|
182
|
+
* the one matched by the routes, the default action and the retry actions.
|
|
183
|
+
* See Response at @botonic/react's index.d.ts for the React type
|
|
184
|
+
* */
|
|
185
|
+
export interface BotResponse extends BotRequest {
|
|
186
|
+
response: any
|
|
187
|
+
messageEvents: Partial<BotonicEvent>[] | null
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface PluginPreRequest extends BotRequest {
|
|
191
|
+
plugins: Plugin[]
|
|
192
|
+
}
|
|
193
|
+
export interface PluginPostRequest extends BotResponse {
|
|
194
|
+
plugins: Plugin[]
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export interface Plugin {
|
|
198
|
+
post(request: PluginPostRequest): void
|
|
199
|
+
pre(request: PluginPreRequest): void
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface Params {
|
|
203
|
+
[key: string]: any
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export const Providers = Object.freeze({
|
|
207
|
+
Messaging: {
|
|
208
|
+
FACEBOOK: 'facebook',
|
|
209
|
+
GENERIC: 'generic',
|
|
210
|
+
IMBEE: 'imbee',
|
|
211
|
+
INTERCOM: 'intercom',
|
|
212
|
+
SMOOCH_WEB: 'smooch_web',
|
|
213
|
+
SMOOCH: 'smooch',
|
|
214
|
+
TELEGRAM: 'telegram',
|
|
215
|
+
TWITTER: 'twitter',
|
|
216
|
+
WEBCHAT: 'webchat',
|
|
217
|
+
WECHAT: 'wechat',
|
|
218
|
+
WHATSAPP: 'whatsapp',
|
|
219
|
+
},
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
export type Nullable<T> = T | null
|
|
223
|
+
|
|
224
|
+
export type Action = Nullable<() => any>
|
|
225
|
+
export type RoutePath = Nullable<string>
|
|
226
|
+
|
|
227
|
+
export interface ProcessInputResult {
|
|
228
|
+
action: Action
|
|
229
|
+
emptyAction: Action
|
|
230
|
+
fallbackAction: Action
|
|
231
|
+
botState: BotState
|
|
232
|
+
params: Params
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export type MatchedValue = boolean | RegExpExecArray | null
|
|
236
|
+
|
|
237
|
+
export type RoutingState = {
|
|
238
|
+
currentRoute: Nullable<Route>
|
|
239
|
+
matchedRoute: Nullable<Route>
|
|
240
|
+
params: Params
|
|
241
|
+
isFlowBroken: boolean
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export interface RouteParams {
|
|
245
|
+
route: Nullable<Route>
|
|
246
|
+
params: Params
|
|
247
|
+
}
|
|
248
|
+
export interface PathParams {
|
|
249
|
+
path: RoutePath
|
|
250
|
+
params: Params
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export type MatchingProp =
|
|
254
|
+
| 'text'
|
|
255
|
+
| 'payload'
|
|
256
|
+
| 'intent'
|
|
257
|
+
| 'type'
|
|
258
|
+
| 'input'
|
|
259
|
+
| 'session'
|
|
260
|
+
| 'request'
|
|
261
|
+
|
|
262
|
+
export type Matcher = string | RegExp | ((args) => boolean)
|
package/src/models/user.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BotState } from './bot-state'
|
|
2
|
+
import { Session } from './session'
|
|
3
|
+
|
|
2
4
|
export interface User {
|
|
3
5
|
id: string //TODO: UUID
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
name?: string
|
|
7
|
+
userName?: string
|
|
8
|
+
channel: string
|
|
9
|
+
idFromChannel: string // providerId
|
|
6
10
|
session: Session
|
|
7
|
-
|
|
11
|
+
botState: BotState
|
|
8
12
|
isOnline: boolean
|
|
13
|
+
websocketId?: string
|
|
14
|
+
// part of details?
|
|
9
15
|
locationInfo: string
|
|
10
16
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// eslint-disable-next-line import/named
|
|
2
|
+
import { parse, X2jOptions } from 'fast-xml-parser'
|
|
3
|
+
import { decode } from 'html-entities'
|
|
4
|
+
|
|
5
|
+
import { BotonicEvent } from '../models'
|
|
6
|
+
import { MessageParsingFactory } from './factory'
|
|
7
|
+
|
|
8
|
+
export const TEXT_NODE_NAME = 'text'
|
|
9
|
+
|
|
10
|
+
export class BotonicOutputParser {
|
|
11
|
+
private static OPTIONS: Partial<X2jOptions> = {
|
|
12
|
+
ignoreAttributes: false,
|
|
13
|
+
attributeNamePrefix: '',
|
|
14
|
+
textNodeName: TEXT_NODE_NAME,
|
|
15
|
+
arrayMode: true,
|
|
16
|
+
attrValueProcessor: a => decode(a),
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
constructor(private readonly factory = new MessageParsingFactory()) {}
|
|
20
|
+
|
|
21
|
+
xmlToMessageEvents(html: string): Partial<BotonicEvent>[] {
|
|
22
|
+
const jsonMessages = this.xmlToJSONMessages(html)
|
|
23
|
+
return jsonMessages.map(msgToParse => this.factory.parse(msgToParse))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Right now, when saving BotonicEvents to DataProvider, we need the standarized Botonic event
|
|
28
|
+
* to be saved. This is, converting a botonic input like: '{id: 'msgId', data: 'rawData', payload: 'somePayload'}'
|
|
29
|
+
* into a BotonicEvent with the expected properties.
|
|
30
|
+
*/
|
|
31
|
+
inputToBotonicEvent(input: any): Partial<BotonicEvent> {
|
|
32
|
+
return this.factory.parse(input)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private xmlToJSONMessages(html: any): any {
|
|
36
|
+
return parse(html, BotonicOutputParser.OPTIONS).message
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { BotonicEvent } from '../models
|
|
2
|
-
import { MessageEventTypes } from '../models/events/message'
|
|
3
|
-
import { MEDIA_TYPES } from '../models/events/message/media'
|
|
1
|
+
import { BotonicEvent, MEDIA_TYPES, MessageEventTypes } from '../models'
|
|
4
2
|
import {
|
|
5
3
|
parseButtons,
|
|
6
4
|
parseCarousel,
|
|
@@ -1,38 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { BotonicEvent } from '../models/events'
|
|
6
|
-
import { MessageParsingFactory } from './factory'
|
|
7
|
-
|
|
8
|
-
export const TEXT_NODE_NAME = 'text'
|
|
9
|
-
|
|
10
|
-
export class BotonicOutputParser {
|
|
11
|
-
private static OPTIONS: Partial<X2jOptions> = {
|
|
12
|
-
ignoreAttributes: false,
|
|
13
|
-
attributeNamePrefix: '',
|
|
14
|
-
textNodeName: TEXT_NODE_NAME,
|
|
15
|
-
arrayMode: true,
|
|
16
|
-
attrValueProcessor: a => decode(a),
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
constructor(private readonly factory = new MessageParsingFactory()) {}
|
|
20
|
-
|
|
21
|
-
xmlToMessageEvents(html: string): Partial<BotonicEvent>[] {
|
|
22
|
-
const jsonMessages = this.xmlToJSONMessages(html)
|
|
23
|
-
return jsonMessages.map(msgToParse => this.factory.parse(msgToParse))
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Right now, when saving BotonicEvents to DataProvider, we need the standarized Botonic event
|
|
28
|
-
* to be saved. This is, converting a botonic input like: '{id: 'msgId', data: 'rawData', payload: 'somePayload'}'
|
|
29
|
-
* into a BotonicEvent with the expected properties.
|
|
30
|
-
*/
|
|
31
|
-
parseFromUserInput(input: any): Partial<BotonicEvent> {
|
|
32
|
-
return this.factory.parse(input)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private xmlToJSONMessages(html: any): any {
|
|
36
|
-
return parse(html, BotonicOutputParser.OPTIONS).message
|
|
37
|
-
}
|
|
38
|
-
}
|
|
1
|
+
export * from './botonic-output-parser'
|
|
2
|
+
export * from './factory'
|
|
3
|
+
export * from './parsers'
|
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
import { EventTypes } from '../models/events'
|
|
2
|
-
import { BotonicMessageEvent } from '../models/events/message'
|
|
3
|
-
import { Button, WithButtons } from '../models/events/message/buttons'
|
|
4
1
|
import {
|
|
2
|
+
AudioMessageEvent,
|
|
3
|
+
BotonicMessageEvent,
|
|
4
|
+
Button,
|
|
5
5
|
CarouselElement,
|
|
6
6
|
CarouselMessageEvent,
|
|
7
|
-
|
|
8
|
-
import { CustomMessageEvent } from '../models/events/message/custom'
|
|
9
|
-
import { LocationMessageEvent } from '../models/events/message/location'
|
|
10
|
-
import {
|
|
11
|
-
AudioMessageEvent,
|
|
7
|
+
CustomMessageEvent,
|
|
12
8
|
DocumentMessageEvent,
|
|
9
|
+
EventTypes,
|
|
13
10
|
ImageMessageEvent,
|
|
11
|
+
LocationMessageEvent,
|
|
12
|
+
PostbackMessageEvent,
|
|
13
|
+
Reply,
|
|
14
|
+
TextMessageEvent,
|
|
14
15
|
VideoMessageEvent,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
WithButtons,
|
|
17
|
+
WithReplies,
|
|
18
|
+
} from '../models'
|
|
19
|
+
import { TEXT_NODE_NAME } from './botonic-output-parser'
|
|
20
|
+
|
|
21
|
+
export function parseNumber(strNumber: string): number {
|
|
22
|
+
return parseInt(strNumber)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function parseBoolean(strNumber: string): boolean {
|
|
26
|
+
if (strNumber === '0') return false
|
|
27
|
+
return true
|
|
28
|
+
}
|
|
21
29
|
|
|
22
30
|
export type ParseFunction<Out> = (args: {
|
|
23
31
|
toParse: any
|
|
@@ -42,6 +50,10 @@ export const parseMessage: ParseFunction<BotonicMessageEvent> = args => {
|
|
|
42
50
|
// Following properties added later before saving event: eventId, userId, createdAt, from, ack
|
|
43
51
|
eventType: EventTypes.MESSAGE,
|
|
44
52
|
type: args.toParse.type,
|
|
53
|
+
ack: args.toParse.ack,
|
|
54
|
+
from: args.toParse.from,
|
|
55
|
+
channel: args.toParse.channel,
|
|
56
|
+
idFromChannel: args.toParse.idFromChannel,
|
|
45
57
|
...typingAndDelay,
|
|
46
58
|
},
|
|
47
59
|
}
|
|
@@ -110,7 +122,7 @@ export const parseText: ParseFunction<TextMessageEvent> = args => {
|
|
|
110
122
|
toParse: args.toParse,
|
|
111
123
|
parsed: {
|
|
112
124
|
...args.parsed,
|
|
113
|
-
text: args.toParse[TEXT_NODE_NAME]
|
|
125
|
+
text: args.toParse[TEXT_NODE_NAME],
|
|
114
126
|
markdown: parseBoolean(args.toParse.markdown),
|
|
115
127
|
},
|
|
116
128
|
}
|
|
@@ -139,7 +151,7 @@ export const parseMedia: ParseFunction<
|
|
|
139
151
|
toParse: args.toParse,
|
|
140
152
|
parsed: {
|
|
141
153
|
...args.parsed,
|
|
142
|
-
src: args.toParse.src
|
|
154
|
+
src: args.toParse.src,
|
|
143
155
|
},
|
|
144
156
|
}
|
|
145
157
|
}
|
|
@@ -184,7 +196,7 @@ export const parseCustom: ParseFunction<CustomMessageEvent> = args => {
|
|
|
184
196
|
toParse: args.toParse,
|
|
185
197
|
parsed: {
|
|
186
198
|
...args.parsed,
|
|
187
|
-
|
|
199
|
+
json: JSON.parse(args.toParse.json),
|
|
188
200
|
},
|
|
189
201
|
}
|
|
190
202
|
}
|