@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
package/src/core-bot.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
import { Inspector } from './debug
|
|
1
|
+
import { Inspector } from './debug'
|
|
2
2
|
import { getString } from './i18n'
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
BotonicEvent,
|
|
5
|
+
BotRequest,
|
|
6
|
+
BotResponse,
|
|
7
|
+
BotState,
|
|
8
|
+
Locales,
|
|
9
|
+
Route,
|
|
10
|
+
Routes,
|
|
11
|
+
Session,
|
|
12
|
+
} from './models'
|
|
5
13
|
import { BotonicOutputParser } from './output-parser'
|
|
6
14
|
import { loadPlugins, runPlugins } from './plugins'
|
|
7
|
-
import { Router } from './
|
|
8
|
-
import { isFunction } from './utils'
|
|
15
|
+
import { getComputedRoutes, Router } from './routing'
|
|
9
16
|
|
|
10
17
|
interface CoreBotConfig {
|
|
11
18
|
appId?: string
|
|
12
19
|
defaultDelay?: number
|
|
13
|
-
defaultRoutes?:
|
|
20
|
+
defaultRoutes?: Route[]
|
|
14
21
|
defaultTyping?: number
|
|
15
22
|
inspector?: Inspector
|
|
16
23
|
locales: Locales
|
|
@@ -22,18 +29,20 @@ interface CoreBotConfig {
|
|
|
22
29
|
export class CoreBot {
|
|
23
30
|
appId?: string
|
|
24
31
|
defaultDelay?: number
|
|
25
|
-
defaultRoutes
|
|
32
|
+
defaultRoutes: Route[]
|
|
26
33
|
defaultTyping?: number
|
|
27
|
-
inspector
|
|
34
|
+
inspector: Inspector
|
|
28
35
|
locales: Locales
|
|
29
36
|
plugins?: Record<string, Plugin>
|
|
30
37
|
renderer: any
|
|
31
38
|
rootElement: any
|
|
32
|
-
router:
|
|
39
|
+
router: Router | null
|
|
33
40
|
routes: Routes
|
|
34
41
|
theme?: any
|
|
42
|
+
botonicOutputParser = new BotonicOutputParser()
|
|
35
43
|
|
|
36
44
|
constructor({
|
|
45
|
+
// TODO: Receives dataProvider
|
|
37
46
|
renderer,
|
|
38
47
|
routes,
|
|
39
48
|
locales,
|
|
@@ -60,85 +69,113 @@ export class CoreBot {
|
|
|
60
69
|
this.inspector = inspector || new Inspector()
|
|
61
70
|
this.routes = routes
|
|
62
71
|
this.defaultRoutes = defaultRoutes || []
|
|
63
|
-
this.router =
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
this.router =
|
|
73
|
+
this.routes instanceof Function
|
|
74
|
+
? null
|
|
75
|
+
: new Router(
|
|
76
|
+
[...this.routes, ...this.defaultRoutes],
|
|
77
|
+
this.inspector.routeInspector
|
|
78
|
+
)
|
|
70
79
|
}
|
|
71
80
|
|
|
72
|
-
getString(id: string,
|
|
73
|
-
|
|
74
|
-
|
|
81
|
+
getString(id: string, botState: BotState): string {
|
|
82
|
+
if (!botState.locale) {
|
|
83
|
+
console.error('Locale is not defined')
|
|
84
|
+
return ''
|
|
85
|
+
}
|
|
86
|
+
return getString(this.locales, botState.locale, id)
|
|
75
87
|
}
|
|
76
88
|
|
|
77
|
-
setLocale(locale: string,
|
|
78
|
-
|
|
89
|
+
setLocale(locale: string, botState: BotState): void {
|
|
90
|
+
botState.locale = locale
|
|
79
91
|
}
|
|
80
92
|
|
|
81
93
|
async input({
|
|
82
94
|
input,
|
|
83
95
|
session,
|
|
84
|
-
|
|
96
|
+
botState,
|
|
97
|
+
dataProvider,
|
|
85
98
|
}: BotRequest): Promise<BotResponse> {
|
|
86
|
-
|
|
87
|
-
if (!session.__locale) session.__locale = 'en'
|
|
88
|
-
|
|
99
|
+
if (!botState?.locale) botState.locale = 'en'
|
|
89
100
|
if (this.plugins) {
|
|
90
|
-
await runPlugins(
|
|
101
|
+
await runPlugins(
|
|
102
|
+
this.plugins,
|
|
103
|
+
'pre',
|
|
104
|
+
input,
|
|
105
|
+
session,
|
|
106
|
+
botState,
|
|
107
|
+
undefined,
|
|
108
|
+
undefined,
|
|
109
|
+
dataProvider
|
|
110
|
+
)
|
|
91
111
|
}
|
|
92
112
|
|
|
93
|
-
if (
|
|
113
|
+
if (this.routes instanceof Function) {
|
|
94
114
|
this.router = new Router(
|
|
95
115
|
[
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
116
|
+
...(await getComputedRoutes(this.routes, {
|
|
117
|
+
input,
|
|
118
|
+
session,
|
|
119
|
+
botState,
|
|
120
|
+
})),
|
|
99
121
|
...this.defaultRoutes,
|
|
100
122
|
],
|
|
101
|
-
// @ts-ignore
|
|
102
123
|
this.inspector.routeInspector
|
|
103
124
|
)
|
|
104
125
|
}
|
|
105
126
|
|
|
106
|
-
const output = this.router.processInput(
|
|
127
|
+
const output = (this.router as Router).processInput(
|
|
128
|
+
input,
|
|
129
|
+
session,
|
|
130
|
+
botState
|
|
131
|
+
)
|
|
107
132
|
|
|
108
133
|
const request = {
|
|
109
|
-
getString: stringId => this.getString(stringId,
|
|
110
|
-
setLocale: locale => this.setLocale(locale,
|
|
134
|
+
getString: stringId => this.getString(stringId, botState),
|
|
135
|
+
setLocale: locale => this.setLocale(locale, botState),
|
|
111
136
|
session: session || {},
|
|
112
137
|
params: output.params || {},
|
|
113
138
|
input: input,
|
|
114
139
|
plugins: this.plugins,
|
|
115
140
|
defaultTyping: this.defaultTyping,
|
|
116
141
|
defaultDelay: this.defaultDelay,
|
|
117
|
-
|
|
142
|
+
botState,
|
|
143
|
+
dataProvider,
|
|
118
144
|
}
|
|
119
145
|
|
|
120
|
-
const
|
|
146
|
+
const response = await this.renderer({
|
|
147
|
+
request,
|
|
148
|
+
actions: [output.fallbackAction, output.action, output.emptyAction],
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
const messageEvents: Partial<BotonicEvent>[] = this.botonicOutputParser.xmlToMessageEvents(
|
|
152
|
+
response
|
|
153
|
+
)
|
|
121
154
|
|
|
122
|
-
|
|
123
|
-
let parsedResponse: Partial<BotonicEvent>[] | null = null
|
|
124
|
-
try {
|
|
125
|
-
parsedResponse = new BotonicOutputParser().xmlToMessageEvents(response)
|
|
126
|
-
} catch (e) {}
|
|
155
|
+
botState.lastRoutePath = output.botState.lastRoutePath // not needed if updated below
|
|
127
156
|
|
|
128
|
-
lastRoutePath = output.lastRoutePath
|
|
129
157
|
if (this.plugins) {
|
|
130
158
|
await runPlugins(
|
|
131
159
|
this.plugins,
|
|
132
160
|
'post',
|
|
133
161
|
input,
|
|
134
|
-
session,
|
|
135
|
-
|
|
162
|
+
session, // passing output.session instead
|
|
163
|
+
botState, // passing output.botState instead
|
|
136
164
|
response,
|
|
137
|
-
|
|
165
|
+
messageEvents,
|
|
166
|
+
dataProvider
|
|
138
167
|
)
|
|
139
168
|
}
|
|
140
169
|
|
|
141
|
-
|
|
142
|
-
|
|
170
|
+
botState.isFirstInteraction = false
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
input, // Delete
|
|
174
|
+
response, // xml/rendered react for actions (not needed)
|
|
175
|
+
messageEvents, // xml to Botonic Events
|
|
176
|
+
session, // to be output.session
|
|
177
|
+
botState, // to be output.botState
|
|
178
|
+
dataProvider, // no need to return it
|
|
179
|
+
}
|
|
143
180
|
}
|
|
144
181
|
}
|
package/src/debug/index.ts
CHANGED
package/src/debug/inspector.ts
CHANGED
package/src/handoff.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { PATH_PAYLOAD_IDENTIFIER } from './constants'
|
|
4
|
+
import { BotState, Session } from './models'
|
|
4
5
|
|
|
5
6
|
const HUBTYPE_API_URL = 'https://api.hubtype.com'
|
|
6
7
|
|
|
@@ -56,7 +57,7 @@ export async function getOpenQueues(
|
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
export class HandOffBuilder {
|
|
59
|
-
|
|
60
|
+
_botState: any
|
|
60
61
|
_queue: string
|
|
61
62
|
_onFinish: string
|
|
62
63
|
_email: string
|
|
@@ -65,8 +66,8 @@ export class HandOffBuilder {
|
|
|
65
66
|
_caseInfo: string
|
|
66
67
|
_shadowing: boolean
|
|
67
68
|
|
|
68
|
-
constructor(
|
|
69
|
-
this.
|
|
69
|
+
constructor(botState: any) {
|
|
70
|
+
this._botState = botState
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
withQueue(queueNameOrId: string): this {
|
|
@@ -80,7 +81,7 @@ export class HandOffBuilder {
|
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
withOnFinishPath(path: string): this {
|
|
83
|
-
this._onFinish =
|
|
84
|
+
this._onFinish = `${PATH_PAYLOAD_IDENTIFIER}${path}`
|
|
84
85
|
return this
|
|
85
86
|
}
|
|
86
87
|
|
|
@@ -111,7 +112,7 @@ export class HandOffBuilder {
|
|
|
111
112
|
|
|
112
113
|
async handOff(): Promise<void> {
|
|
113
114
|
return _humanHandOff(
|
|
114
|
-
this.
|
|
115
|
+
this._botState,
|
|
115
116
|
this._queue,
|
|
116
117
|
this._onFinish,
|
|
117
118
|
this._email,
|
|
@@ -153,7 +154,7 @@ interface HubtypeHandoffParams {
|
|
|
153
154
|
on_finish?: string
|
|
154
155
|
}
|
|
155
156
|
async function _humanHandOff(
|
|
156
|
-
|
|
157
|
+
botState: any,
|
|
157
158
|
queueNameOrId = '',
|
|
158
159
|
onFinish: string,
|
|
159
160
|
agentEmail = '',
|
|
@@ -184,7 +185,8 @@ async function _humanHandOff(
|
|
|
184
185
|
if (onFinish) {
|
|
185
186
|
params.on_finish = onFinish
|
|
186
187
|
}
|
|
187
|
-
|
|
188
|
+
botState.botonicAction = `create_case:${JSON.stringify(params)}`
|
|
189
|
+
botState.isHandoff = true
|
|
188
190
|
}
|
|
189
191
|
|
|
190
192
|
export async function storeCaseRating(
|
|
@@ -255,14 +257,15 @@ export async function getAgentVacationRanges(
|
|
|
255
257
|
}
|
|
256
258
|
|
|
257
259
|
export function cancelHandoff(
|
|
258
|
-
|
|
260
|
+
botState: BotState,
|
|
259
261
|
typification: string | null = null
|
|
260
262
|
): void {
|
|
261
263
|
let action = 'discard_case'
|
|
262
264
|
if (typification) action = `${action}:${JSON.stringify({ typification })}`
|
|
263
|
-
|
|
265
|
+
botState.botonicAction = action
|
|
266
|
+
botState.isHandoff = false // TODO: Review handoff functionalities
|
|
264
267
|
}
|
|
265
268
|
|
|
266
|
-
export function deleteUser(
|
|
267
|
-
|
|
269
|
+
export function deleteUser(botState: BotState): void {
|
|
270
|
+
botState.botonicAction = `delete_user`
|
|
268
271
|
}
|
package/src/hubtype-service.ts
CHANGED
|
@@ -2,7 +2,7 @@ import axios, { AxiosResponse } from 'axios'
|
|
|
2
2
|
import Pusher, { AuthOptions, Channel } from 'pusher-js'
|
|
3
3
|
import Channels from 'pusher-js/types/src/core/channels/channels'
|
|
4
4
|
|
|
5
|
-
import { Input
|
|
5
|
+
import { Input } from './models'
|
|
6
6
|
import { getWebpackEnvVar } from './utils'
|
|
7
7
|
|
|
8
8
|
interface UnsentInput {
|
|
@@ -21,7 +21,7 @@ interface ServerConfig {
|
|
|
21
21
|
}
|
|
22
22
|
interface HubtypeServiceArgs {
|
|
23
23
|
appId: string
|
|
24
|
-
user:
|
|
24
|
+
user: any
|
|
25
25
|
lastMessageId: string
|
|
26
26
|
lastMessageUpdateDate: string
|
|
27
27
|
onEvent: any
|
|
@@ -50,7 +50,7 @@ const PONG_TIMEOUT = 5 * 1000 // https://pusher.com/docs/channels/using_channels
|
|
|
50
50
|
*/
|
|
51
51
|
export class HubtypeService {
|
|
52
52
|
appId: string
|
|
53
|
-
user:
|
|
53
|
+
user: any
|
|
54
54
|
lastMessageId: string
|
|
55
55
|
lastMessageUpdateDate: string
|
|
56
56
|
onEvent: any
|
|
@@ -185,7 +185,7 @@ export class HubtypeService {
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
handleConnectionChange(online: boolean): void {
|
|
188
|
-
this.onPusherEvent({ action: '
|
|
188
|
+
this.onPusherEvent({ action: 'connection_change', online })
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
onPusherEvent(event: any): void {
|
|
@@ -213,7 +213,7 @@ export class HubtypeService {
|
|
|
213
213
|
/**
|
|
214
214
|
* @return {Promise<void>}
|
|
215
215
|
*/
|
|
216
|
-
async postMessage(user:
|
|
216
|
+
async postMessage(user: any, message: any): Promise<void> {
|
|
217
217
|
try {
|
|
218
218
|
// @ts-ignore
|
|
219
219
|
await this.init(user)
|
package/src/i18n.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,233 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export { CoreBot } from './core-bot'
|
|
1
|
+
export * from './constants'
|
|
2
|
+
export * from './core-bot'
|
|
4
3
|
export * from './debug'
|
|
5
4
|
export * from './handoff'
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
5
|
+
export * from './hubtype-service'
|
|
6
|
+
export * from './i18n'
|
|
7
|
+
export * from './models'
|
|
8
|
+
export * from './output-parser'
|
|
9
|
+
export * from './plugins'
|
|
10
|
+
export * from './routing'
|
|
9
11
|
export * from './utils'
|
|
10
|
-
|
|
11
|
-
export type CaseStatusType =
|
|
12
|
-
| typeof CASE_STATUS.ATTENDING
|
|
13
|
-
| typeof CASE_STATUS.IDLE
|
|
14
|
-
| typeof CASE_STATUS.RESOLVED
|
|
15
|
-
| typeof CASE_STATUS.WAITING
|
|
16
|
-
|
|
17
|
-
export type CaseResolution =
|
|
18
|
-
| typeof CASE_RESOLUTION.BANNED
|
|
19
|
-
| typeof CASE_RESOLUTION.NOK
|
|
20
|
-
| typeof CASE_RESOLUTION.NOT_SOLVED
|
|
21
|
-
| typeof CASE_RESOLUTION.OK
|
|
22
|
-
|
|
23
|
-
export const PROVIDER = Object.freeze({
|
|
24
|
-
DEV: 'dev',
|
|
25
|
-
FACEBOOK: 'facebook',
|
|
26
|
-
GENERIC: 'generic',
|
|
27
|
-
INTERCOM: 'intercom',
|
|
28
|
-
SMOOCH: 'smooch',
|
|
29
|
-
TELEGRAM: 'telegram',
|
|
30
|
-
TWITTER: 'twitter',
|
|
31
|
-
WEBCHAT: 'webchat',
|
|
32
|
-
WECHAT: 'wechat',
|
|
33
|
-
WHATSAPP: 'whatsapp',
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
export const INPUT = Object.freeze({
|
|
37
|
-
TEXT: 'text',
|
|
38
|
-
POSTBACK: 'postback',
|
|
39
|
-
AUDIO: 'audio',
|
|
40
|
-
IMAGE: 'image',
|
|
41
|
-
VIDEO: 'video',
|
|
42
|
-
DOCUMENT: 'document',
|
|
43
|
-
LOCATION: 'location',
|
|
44
|
-
CONTACT: 'contact',
|
|
45
|
-
BUTTON_MESSAGE: 'buttonmessage',
|
|
46
|
-
CAROUSEL: 'carousel',
|
|
47
|
-
CUSTOM: 'custom',
|
|
48
|
-
WEBCHAT_SETTINGS: 'webchatsettings',
|
|
49
|
-
WHATSAPP_TEMPLATE: 'whatsapptemplate',
|
|
50
|
-
RAW: 'raw',
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
export const CASE_STATUS = Object.freeze({
|
|
54
|
-
WAITING: 'status_waiting',
|
|
55
|
-
ATTENDING: 'status_attending',
|
|
56
|
-
IDLE: 'status_idle',
|
|
57
|
-
RESOLVED: 'status_resolved',
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
export const CASE_RESOLUTION = Object.freeze({
|
|
61
|
-
OK: 'result_ok',
|
|
62
|
-
NOK: 'result_nok',
|
|
63
|
-
NOT_SOLVED: 'result_not_solved',
|
|
64
|
-
BANNED: 'result_banned',
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
export interface Locales {
|
|
68
|
-
[id: string]: string | string[] | Locales
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
interface PluginConstructor<T> {
|
|
72
|
-
new (arg: T): Plugin
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface PluginConfig<T> {
|
|
76
|
-
id: string
|
|
77
|
-
options?: T
|
|
78
|
-
resolve: { default: PluginConstructor<T> }
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export type InputType =
|
|
82
|
-
| typeof INPUT.AUDIO
|
|
83
|
-
| typeof INPUT.BUTTON_MESSAGE
|
|
84
|
-
| typeof INPUT.CAROUSEL
|
|
85
|
-
| typeof INPUT.CONTACT
|
|
86
|
-
| typeof INPUT.CUSTOM
|
|
87
|
-
| typeof INPUT.DOCUMENT
|
|
88
|
-
| typeof INPUT.IMAGE
|
|
89
|
-
| typeof INPUT.LOCATION
|
|
90
|
-
| typeof INPUT.POSTBACK
|
|
91
|
-
| typeof INPUT.TEXT
|
|
92
|
-
| typeof INPUT.VIDEO
|
|
93
|
-
| typeof INPUT.WEBCHAT_SETTINGS
|
|
94
|
-
| typeof INPUT.WHATSAPP_TEMPLATE
|
|
95
|
-
|
|
96
|
-
export interface IntentResult {
|
|
97
|
-
intent: string
|
|
98
|
-
confidence: number
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** Generated by Translation plugins: GoogleTranslation **/
|
|
102
|
-
export interface Translations {
|
|
103
|
-
[languageCode: string]: string
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/** Fields set by NLU plugins: Luis, Dialogflow, ... **/
|
|
107
|
-
export interface NluResult {
|
|
108
|
-
// the name of the highest confidence intent
|
|
109
|
-
confidence: number
|
|
110
|
-
intent: string
|
|
111
|
-
intents: IntentResult[]
|
|
112
|
-
language: string
|
|
113
|
-
// entity recognition results in the format provided by the NLU engine
|
|
114
|
-
entities?: any
|
|
115
|
-
translations: Translations
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export interface Input extends Partial<NluResult> {
|
|
119
|
-
data?: string
|
|
120
|
-
path?: string
|
|
121
|
-
payload?: string
|
|
122
|
-
type: InputType
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export type ProviderType =
|
|
126
|
-
| typeof PROVIDER.DEV
|
|
127
|
-
| typeof PROVIDER.FACEBOOK
|
|
128
|
-
| typeof PROVIDER.GENERIC
|
|
129
|
-
| typeof PROVIDER.INTERCOM
|
|
130
|
-
| typeof PROVIDER.SMOOCH
|
|
131
|
-
| typeof PROVIDER.TELEGRAM
|
|
132
|
-
| typeof PROVIDER.TWITTER
|
|
133
|
-
| typeof PROVIDER.WEBCHAT
|
|
134
|
-
| typeof PROVIDER.WECHAT
|
|
135
|
-
| typeof PROVIDER.WHATSAPP
|
|
136
|
-
|
|
137
|
-
export interface SessionUser {
|
|
138
|
-
id: string
|
|
139
|
-
// login
|
|
140
|
-
username?: string
|
|
141
|
-
// person name
|
|
142
|
-
name?: string
|
|
143
|
-
// whatsapp, telegram,...
|
|
144
|
-
provider: ProviderType
|
|
145
|
-
// The provider's user id
|
|
146
|
-
extra_data?: any
|
|
147
|
-
imp_id?: string
|
|
148
|
-
provider_id?: string
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// eslint-disable @typescript-eslint/naming-convention
|
|
152
|
-
export interface Session {
|
|
153
|
-
bot: {
|
|
154
|
-
id: string
|
|
155
|
-
name?: string
|
|
156
|
-
}
|
|
157
|
-
__locale?: string
|
|
158
|
-
__retries?: number
|
|
159
|
-
is_first_interaction: boolean
|
|
160
|
-
last_session?: any
|
|
161
|
-
organization?: string
|
|
162
|
-
user: SessionUser
|
|
163
|
-
// after handoff
|
|
164
|
-
_hubtype_case_status?: CaseStatusType
|
|
165
|
-
_hubtype_case_typification?: string
|
|
166
|
-
_shadowing?: boolean
|
|
167
|
-
}
|
|
168
|
-
// eslint-enable @typescript-eslint/naming-convention
|
|
169
|
-
|
|
170
|
-
type InputMatcher = (input: Input) => boolean
|
|
171
|
-
type ParamsMatcher =
|
|
172
|
-
| { [key: string]: string }
|
|
173
|
-
| ((params: { [key: string]: string }) => boolean)
|
|
174
|
-
type SessionMatcher = (session: Session) => boolean
|
|
175
|
-
type RequestMatcher = (request: BotRequest) => boolean
|
|
176
|
-
type StringMatcher = RegExp | string | ((data: string) => boolean)
|
|
177
|
-
|
|
178
|
-
export type RouteMatcher =
|
|
179
|
-
| InputMatcher
|
|
180
|
-
| ParamsMatcher
|
|
181
|
-
| RequestMatcher
|
|
182
|
-
| SessionMatcher
|
|
183
|
-
| StringMatcher
|
|
184
|
-
|
|
185
|
-
export interface Route {
|
|
186
|
-
action?: any
|
|
187
|
-
childRoutes?: Route[]
|
|
188
|
-
defaultAction?: any
|
|
189
|
-
lastRoutePath?: string
|
|
190
|
-
ignoreRetry?: boolean
|
|
191
|
-
path?: StringMatcher
|
|
192
|
-
redirect?: string
|
|
193
|
-
retry?: number
|
|
194
|
-
retryAction?: any
|
|
195
|
-
|
|
196
|
-
// matchers
|
|
197
|
-
input?: InputMatcher
|
|
198
|
-
intent?: StringMatcher
|
|
199
|
-
params?: ParamsMatcher
|
|
200
|
-
payload?: StringMatcher
|
|
201
|
-
request?: RequestMatcher
|
|
202
|
-
session?: SessionMatcher
|
|
203
|
-
text?: StringMatcher
|
|
204
|
-
data?: StringMatcher
|
|
205
|
-
type?: StringMatcher
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export type Routes<R = Route> = R[] | ((_: BotRequest) => R[])
|
|
209
|
-
|
|
210
|
-
export interface BotRequest {
|
|
211
|
-
input: Input
|
|
212
|
-
lastRoutePath: string
|
|
213
|
-
session: Session
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/** The response of the bot for the triggered actions, which can be
|
|
217
|
-
* the one matched by the routes, the default action and the retry actions.
|
|
218
|
-
* See Response at @botonic/react's index.d.ts for the React type
|
|
219
|
-
* */
|
|
220
|
-
export interface BotResponse extends BotRequest {
|
|
221
|
-
response: any
|
|
222
|
-
parsedResponse: Partial<BotonicEvent>[] | null
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export type PluginPreRequest = BotRequest
|
|
226
|
-
export type PluginPostRequest = BotResponse
|
|
227
|
-
|
|
228
|
-
export interface Plugin {
|
|
229
|
-
post(_: PluginPostRequest): void
|
|
230
|
-
pre(pluginRequest: PluginPreRequest): void
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export type Params = { [key: string]: string }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export enum EventTypes {
|
|
2
|
+
CONNECTION = 'connection',
|
|
3
|
+
MESSAGE = 'message',
|
|
4
|
+
ACK = 'ack',
|
|
5
|
+
TRACK = 'track',
|
|
6
|
+
// Integration Events
|
|
7
|
+
NEW_USER = 'newUser',
|
|
8
|
+
RECEIVED_MESSAGE = 'receivedMessage',
|
|
9
|
+
BOT_EXECUTED = 'botExecuted',
|
|
10
|
+
BOT_ACTION = 'botAction',
|
|
11
|
+
ACTION_SENT = 'actionSent',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface BaseEvent {
|
|
15
|
+
eventId: string
|
|
16
|
+
userId: string
|
|
17
|
+
eventType: EventTypes
|
|
18
|
+
createdAt: string
|
|
19
|
+
modifiedAt?: string
|
|
20
|
+
channel: string
|
|
21
|
+
idFromChannel: string
|
|
22
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ConnectionEvent } from './connection'
|
|
2
|
+
import { IntegrationEvent } from './integration'
|
|
3
|
+
import {
|
|
4
|
+
AudioMessageEvent,
|
|
5
|
+
CarouselMessageEvent,
|
|
6
|
+
CustomMessageEvent,
|
|
7
|
+
DocumentMessageEvent,
|
|
8
|
+
ImageMessageEvent,
|
|
9
|
+
LocationMessageEvent,
|
|
10
|
+
PostbackMessageEvent,
|
|
11
|
+
TextMessageEvent,
|
|
12
|
+
VideoMessageEvent,
|
|
13
|
+
} from './message'
|
|
14
|
+
|
|
15
|
+
export type BotonicEvent =
|
|
16
|
+
| TextMessageEvent
|
|
17
|
+
| PostbackMessageEvent
|
|
18
|
+
| AudioMessageEvent
|
|
19
|
+
| DocumentMessageEvent
|
|
20
|
+
| ImageMessageEvent
|
|
21
|
+
| VideoMessageEvent
|
|
22
|
+
| LocationMessageEvent
|
|
23
|
+
| CarouselMessageEvent
|
|
24
|
+
| CustomMessageEvent
|
|
25
|
+
| ConnectionEvent
|
|
26
|
+
| IntegrationEvent
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './connection-event'
|