@botonic/core 0.26.0 → 0.27.0-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.
Files changed (106) hide show
  1. package/lib/cjs/core-bot.d.ts +1 -3
  2. package/lib/cjs/core-bot.js +3 -33
  3. package/lib/cjs/core-bot.js.map +1 -1
  4. package/lib/cjs/handoff.d.ts +16 -16
  5. package/lib/cjs/handoff.js +9 -2
  6. package/lib/cjs/handoff.js.map +1 -1
  7. package/lib/cjs/index.d.ts +0 -1
  8. package/lib/cjs/index.js +0 -3
  9. package/lib/cjs/index.js.map +1 -1
  10. package/lib/cjs/models/legacy-types.d.ts +44 -39
  11. package/lib/cjs/models/legacy-types.js +15 -32
  12. package/lib/cjs/models/legacy-types.js.map +1 -1
  13. package/lib/cjs/plugins.d.ts +2 -3
  14. package/lib/cjs/plugins.js +2 -4
  15. package/lib/cjs/plugins.js.map +1 -1
  16. package/lib/cjs/utils.d.ts +8 -0
  17. package/lib/cjs/utils.js +32 -1
  18. package/lib/cjs/utils.js.map +1 -1
  19. package/lib/esm/core-bot.d.ts +1 -3
  20. package/lib/esm/core-bot.js +4 -34
  21. package/lib/esm/core-bot.js.map +1 -1
  22. package/lib/esm/handoff.d.ts +16 -16
  23. package/lib/esm/handoff.js +9 -2
  24. package/lib/esm/handoff.js.map +1 -1
  25. package/lib/esm/index.d.ts +0 -1
  26. package/lib/esm/index.js +0 -3
  27. package/lib/esm/index.js.map +1 -1
  28. package/lib/esm/models/legacy-types.d.ts +44 -39
  29. package/lib/esm/models/legacy-types.js +14 -31
  30. package/lib/esm/models/legacy-types.js.map +1 -1
  31. package/lib/esm/plugins.d.ts +2 -3
  32. package/lib/esm/plugins.js +2 -4
  33. package/lib/esm/plugins.js.map +1 -1
  34. package/lib/esm/utils.d.ts +8 -0
  35. package/lib/esm/utils.js +24 -0
  36. package/lib/esm/utils.js.map +1 -1
  37. package/package.json +1 -6
  38. package/src/core-bot.ts +2 -56
  39. package/src/handoff.ts +29 -19
  40. package/src/index.ts +0 -3
  41. package/src/models/legacy-types.ts +78 -76
  42. package/src/plugins.ts +2 -8
  43. package/src/utils.ts +32 -0
  44. package/lib/cjs/data-provider/dynamodb-data-provider.d.ts +0 -26
  45. package/lib/cjs/data-provider/dynamodb-data-provider.js +0 -107
  46. package/lib/cjs/data-provider/dynamodb-data-provider.js.map +0 -1
  47. package/lib/cjs/data-provider/dynamodb-utils.d.ts +0 -11
  48. package/lib/cjs/data-provider/dynamodb-utils.js +0 -121
  49. package/lib/cjs/data-provider/dynamodb-utils.js.map +0 -1
  50. package/lib/cjs/data-provider/factory.d.ts +0 -25
  51. package/lib/cjs/data-provider/factory.js +0 -31
  52. package/lib/cjs/data-provider/factory.js.map +0 -1
  53. package/lib/cjs/data-provider/index.d.ts +0 -4
  54. package/lib/cjs/data-provider/index.js +0 -8
  55. package/lib/cjs/data-provider/index.js.map +0 -1
  56. package/lib/cjs/data-provider/local-data-provider.d.ts +0 -26
  57. package/lib/cjs/data-provider/local-data-provider.js +0 -137
  58. package/lib/cjs/data-provider/local-data-provider.js.map +0 -1
  59. package/lib/cjs/output-parser/botonic-output-parser.d.ts +0 -16
  60. package/lib/cjs/output-parser/botonic-output-parser.js +0 -37
  61. package/lib/cjs/output-parser/botonic-output-parser.js.map +0 -1
  62. package/lib/cjs/output-parser/factory.d.ts +0 -4
  63. package/lib/cjs/output-parser/factory.js +0 -36
  64. package/lib/cjs/output-parser/factory.js.map +0 -1
  65. package/lib/cjs/output-parser/index.d.ts +0 -3
  66. package/lib/cjs/output-parser/index.js +0 -7
  67. package/lib/cjs/output-parser/index.js.map +0 -1
  68. package/lib/cjs/output-parser/parsers.d.ts +0 -26
  69. package/lib/cjs/output-parser/parsers.js +0 -171
  70. package/lib/cjs/output-parser/parsers.js.map +0 -1
  71. package/lib/esm/data-provider/dynamodb-data-provider.d.ts +0 -26
  72. package/lib/esm/data-provider/dynamodb-data-provider.js +0 -103
  73. package/lib/esm/data-provider/dynamodb-data-provider.js.map +0 -1
  74. package/lib/esm/data-provider/dynamodb-utils.d.ts +0 -11
  75. package/lib/esm/data-provider/dynamodb-utils.js +0 -113
  76. package/lib/esm/data-provider/dynamodb-utils.js.map +0 -1
  77. package/lib/esm/data-provider/factory.d.ts +0 -25
  78. package/lib/esm/data-provider/factory.js +0 -27
  79. package/lib/esm/data-provider/factory.js.map +0 -1
  80. package/lib/esm/data-provider/index.d.ts +0 -4
  81. package/lib/esm/data-provider/index.js +0 -5
  82. package/lib/esm/data-provider/index.js.map +0 -1
  83. package/lib/esm/data-provider/local-data-provider.d.ts +0 -26
  84. package/lib/esm/data-provider/local-data-provider.js +0 -133
  85. package/lib/esm/data-provider/local-data-provider.js.map +0 -1
  86. package/lib/esm/output-parser/botonic-output-parser.d.ts +0 -16
  87. package/lib/esm/output-parser/botonic-output-parser.js +0 -33
  88. package/lib/esm/output-parser/botonic-output-parser.js.map +0 -1
  89. package/lib/esm/output-parser/factory.d.ts +0 -4
  90. package/lib/esm/output-parser/factory.js +0 -32
  91. package/lib/esm/output-parser/factory.js.map +0 -1
  92. package/lib/esm/output-parser/index.d.ts +0 -3
  93. package/lib/esm/output-parser/index.js +0 -4
  94. package/lib/esm/output-parser/index.js.map +0 -1
  95. package/lib/esm/output-parser/parsers.d.ts +0 -26
  96. package/lib/esm/output-parser/parsers.js +0 -151
  97. package/lib/esm/output-parser/parsers.js.map +0 -1
  98. package/src/data-provider/dynamodb-data-provider.ts +0 -105
  99. package/src/data-provider/dynamodb-utils.ts +0 -149
  100. package/src/data-provider/factory.ts +0 -60
  101. package/src/data-provider/index.ts +0 -4
  102. package/src/data-provider/local-data-provider.ts +0 -154
  103. package/src/output-parser/botonic-output-parser.ts +0 -38
  104. package/src/output-parser/factory.ts +0 -45
  105. package/src/output-parser/index.ts +0 -3
  106. package/src/output-parser/parsers.ts +0 -237
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":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pD,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,OAAgB;IACzC,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,QAAQ,CAAC,QAAQ,CAAA;AACpD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,QAAQ,CAAC,SAAS,CAAA;AACrD,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,OAAgB;IACxC,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,QAAQ,CAAC,OAAO,CAAA;AACnD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botonic/core",
3
- "version": "0.26.0",
3
+ "version": "0.27.0-alpha.0",
4
4
  "license": "MIT",
5
5
  "description": "Build Chatbots using React",
6
6
  "main": "./lib/cjs/index.js",
@@ -30,13 +30,8 @@
30
30
  ],
31
31
  "dependencies": {
32
32
  "@babel/plugin-transform-runtime": "^7.23.9",
33
- "aws-sdk": "^2.1404.0",
34
33
  "axios": "^1.6.8",
35
34
  "decode": "^0.3.0",
36
- "dynamodb-toolbox": "^0.3.4",
37
- "fast-xml-parser": "3.19.0",
38
- "html-entities": "^2.4.0",
39
- "node-json-db": "^1.6.0",
40
35
  "pako": "^2.1.0",
41
36
  "process": "^0.11.10",
42
37
  "pusher-js": "^5.1.1",
package/src/core-bot.ts CHANGED
@@ -1,21 +1,15 @@
1
- import { ulid } from 'ulid'
2
-
3
1
  import { Inspector } from './debug'
4
2
  import { getString } from './i18n'
5
3
  import {
6
- BotonicEvent,
7
4
  BotRequest,
8
5
  BotResponse,
9
6
  INPUT,
10
7
  Locales,
11
- MessageEventAck,
12
- MessageEventFrom,
13
8
  ResolvedPlugins,
14
9
  Route,
15
10
  Routes,
16
11
  Session,
17
12
  } from './models'
18
- import { BotonicOutputParser } from './output-parser'
19
13
  import { loadPlugins, runPlugins } from './plugins'
20
14
  import { getComputedRoutes, Router } from './routing'
21
15
 
@@ -44,7 +38,6 @@ export class CoreBot {
44
38
  router: Router | null
45
39
  routes: Routes
46
40
  theme?: any
47
- botonicOutputParser = new BotonicOutputParser()
48
41
 
49
42
  constructor({
50
43
  // TODO: Receives dataProvider
@@ -96,7 +89,6 @@ export class CoreBot {
96
89
  input,
97
90
  session,
98
91
  lastRoutePath,
99
- dataProvider,
100
92
  }: BotRequest): Promise<BotResponse> {
101
93
  session = session || {}
102
94
  if (!session.__locale) session.__locale = 'en'
@@ -106,27 +98,10 @@ export class CoreBot {
106
98
  input,
107
99
  session,
108
100
  lastRoutePath,
109
- dataProvider,
110
101
  response: [],
111
- messageEvents: null,
112
102
  }
113
103
  }
114
104
 
115
- const parsedUserEvent = this.botonicOutputParser.parseFromUserInput(input)
116
- const userId = session.user.id
117
- if (dataProvider) {
118
- // TODO: Next iterations. Review cycle of commited events to DB when messages change their ACK
119
- // @ts-ignore
120
- const userEvent = await dataProvider.saveEvent({
121
- ...parsedUserEvent,
122
- userId,
123
- eventId: ulid(),
124
- createdAt: new Date().toISOString(),
125
- from: MessageEventFrom.USER,
126
- ack: MessageEventAck.RECEIVED,
127
- })
128
- }
129
-
130
105
  if (this.plugins) {
131
106
  await runPlugins(
132
107
  this.plugins,
@@ -134,9 +109,7 @@ export class CoreBot {
134
109
  input,
135
110
  session,
136
111
  lastRoutePath,
137
- undefined,
138
- undefined,
139
- dataProvider
112
+ undefined
140
113
  )
141
114
  }
142
115
 
@@ -169,20 +142,12 @@ export class CoreBot {
169
142
  defaultTyping: this.defaultTyping,
170
143
  defaultDelay: this.defaultDelay,
171
144
  lastRoutePath,
172
- dataProvider,
173
145
  }
174
146
 
175
147
  const response = await this.renderer({
176
148
  request,
177
149
  actions: [output.fallbackAction, output.action, output.emptyAction],
178
150
  })
179
- let messageEvents: Partial<BotonicEvent>[] = []
180
- try {
181
- messageEvents = this.botonicOutputParser.xmlToMessageEvents(response)
182
- } catch (e) {
183
- // Disabling Botonic 1.0 error log for LTS version:
184
- // console.error(e)
185
- }
186
151
 
187
152
  lastRoutePath = output.lastRoutePath
188
153
  if (this.plugins) {
@@ -192,35 +157,16 @@ export class CoreBot {
192
157
  input,
193
158
  session,
194
159
  lastRoutePath,
195
- response,
196
- messageEvents,
197
- dataProvider
160
+ response
198
161
  )
199
162
  }
200
163
 
201
- if (dataProvider) {
202
- // TODO: save bot responses to db and update user with new session and new params
203
- for (const messageEvent of messageEvents) {
204
- // @ts-ignore
205
- const botEvent = await dataProvider.saveEvent({
206
- ...messageEvent,
207
- userId,
208
- eventId: ulid(),
209
- createdAt: new Date().toISOString(),
210
- from: MessageEventFrom.BOT,
211
- ack: MessageEventAck.SENT,
212
- })
213
- }
214
- }
215
-
216
164
  session.is_first_interaction = false
217
165
  return {
218
166
  input,
219
167
  response,
220
- messageEvents,
221
168
  session,
222
169
  lastRoutePath,
223
- dataProvider,
224
170
  }
225
171
  }
226
172
  }
package/src/handoff.ts CHANGED
@@ -12,14 +12,7 @@ export interface HubtypeAgentsInfo {
12
12
  last_message_sent: string
13
13
  status: string
14
14
  }
15
- export interface HubtypeSession extends Session {
16
- _hubtype_api?: string
17
- _access_token: string
18
- }
19
15
 
20
- export interface SessionWithBotonicAction extends Session {
21
- _botonic_action: string
22
- }
23
16
  export interface BackendContext {
24
17
  timeoutMs: number
25
18
  }
@@ -36,6 +29,11 @@ export type HandoffExtraData = {
36
29
  location?: string
37
30
  }
38
31
 
32
+ interface BotEventData {
33
+ language: string
34
+ country: string
35
+ }
36
+
39
37
  function contextDefaults(context: any): BackendContext {
40
38
  return {
41
39
  timeoutMs: context.timeoutMs || 10000,
@@ -43,7 +41,7 @@ function contextDefaults(context: any): BackendContext {
43
41
  }
44
42
 
45
43
  export async function getOpenQueues(
46
- session: HubtypeSession,
44
+ session: Session,
47
45
  context = {}
48
46
  ): Promise<{ queues: string[] }> {
49
47
  //be aware of https://github.com/axios/axios/issues/1543
@@ -63,7 +61,7 @@ export async function getOpenQueues(
63
61
  }
64
62
 
65
63
  export class HandOffBuilder {
66
- _session: SessionWithBotonicAction
64
+ _session: Session
67
65
  _queue: string
68
66
  _onFinish: string
69
67
  _email: string
@@ -75,8 +73,9 @@ export class HandOffBuilder {
75
73
  _autoIdleMessage: string
76
74
  _shadowing: boolean
77
75
  _extraData: HandoffExtraData
76
+ _bot_event: BotEventData
78
77
 
79
- constructor(session: SessionWithBotonicAction) {
78
+ constructor(session: Session) {
80
79
  this._session = session
81
80
  }
82
81
 
@@ -140,6 +139,11 @@ export class HandOffBuilder {
140
139
  return this
141
140
  }
142
141
 
142
+ withBotEvent(botEvent: BotEventData): this {
143
+ this._bot_event = botEvent
144
+ return this
145
+ }
146
+
143
147
  async handOff(): Promise<void> {
144
148
  return _humanHandOff(
145
149
  this._session,
@@ -153,7 +157,8 @@ export class HandOffBuilder {
153
157
  this._note,
154
158
  this._autoIdleMessage,
155
159
  this._shadowing,
156
- this._extraData
160
+ this._extraData,
161
+ this._bot_event
157
162
  )
158
163
  }
159
164
  }
@@ -190,9 +195,10 @@ interface HubtypeHandoffParams {
190
195
  shadowing?: boolean
191
196
  on_finish?: string
192
197
  case_extra_data?: HandoffExtraData
198
+ bot_event?: BotEventData
193
199
  }
194
200
  async function _humanHandOff(
195
- session: SessionWithBotonicAction,
201
+ session: Session,
196
202
  queueNameOrId = '',
197
203
  onFinish: string,
198
204
  agentEmail = '',
@@ -203,7 +209,8 @@ async function _humanHandOff(
203
209
  note = '',
204
210
  autoIdleMessage = '',
205
211
  shadowing = false,
206
- extraData: HandoffExtraData | undefined = undefined
212
+ extraData: HandoffExtraData | undefined = undefined,
213
+ botEvent: BotEventData
207
214
  ) {
208
215
  const params: HubtypeHandoffParams = {}
209
216
 
@@ -239,11 +246,14 @@ async function _humanHandOff(
239
246
  if (extraData) {
240
247
  params.case_extra_data = extraData
241
248
  }
249
+ if (botEvent) {
250
+ params.bot_event = botEvent
251
+ }
242
252
  session._botonic_action = `create_case:${JSON.stringify(params)}`
243
253
  }
244
254
 
245
255
  export async function storeCaseRating(
246
- session: HubtypeSession,
256
+ session: Session,
247
257
  rating: number,
248
258
  context: any = {}
249
259
  ): Promise<{ status: string }> {
@@ -263,7 +273,7 @@ export async function storeCaseRating(
263
273
  }
264
274
 
265
275
  export async function getAvailableAgentsByQueue(
266
- session: HubtypeSession,
276
+ session: Session,
267
277
  queueId: string
268
278
  ): Promise<{ agents: string[] }> {
269
279
  const baseUrl = session._hubtype_api || HUBTYPE_API_URL
@@ -278,7 +288,7 @@ export async function getAvailableAgentsByQueue(
278
288
  }
279
289
 
280
290
  export async function getAvailableAgents(
281
- session: HubtypeSession
291
+ session: Session
282
292
  ): Promise<{ agents: HubtypeAgentsInfo[] }> {
283
293
  const baseUrl = session._hubtype_api || HUBTYPE_API_URL
284
294
  const botId = session.bot.id
@@ -293,7 +303,7 @@ export async function getAvailableAgents(
293
303
  }
294
304
 
295
305
  export async function getAgentVacationRanges(
296
- session: HubtypeSession,
306
+ session: Session,
297
307
  { agentId, agentEmail }: { agentId?: string; agentEmail?: string }
298
308
  ): Promise<{ vacation_ranges: VacationRange[] }> {
299
309
  const baseUrl = session._hubtype_api || HUBTYPE_API_URL
@@ -310,7 +320,7 @@ export async function getAgentVacationRanges(
310
320
  }
311
321
 
312
322
  export function cancelHandoff(
313
- session: SessionWithBotonicAction,
323
+ session: Session,
314
324
  typification: string | null = null
315
325
  ): void {
316
326
  let action = 'discard_case'
@@ -318,6 +328,6 @@ export function cancelHandoff(
318
328
  session._botonic_action = action
319
329
  }
320
330
 
321
- export function deleteUser(session: SessionWithBotonicAction): void {
331
+ export function deleteUser(session: Session): void {
322
332
  session._botonic_action = `delete_user`
323
333
  }
package/src/index.ts CHANGED
@@ -1,13 +1,10 @@
1
1
  export * from './constants'
2
2
  export * from './core-bot'
3
- // TODO: Review @botonic/react's tree-shaking to remove dataProvider from bundle
4
- // export * from './data-provider'
5
3
  export * from './debug'
6
4
  export * from './handoff'
7
5
  export * from './hubtype-service'
8
6
  export * from './i18n'
9
7
  export * from './models'
10
- export * from './output-parser'
11
8
  export * from './plugins'
12
9
  export * from './routing'
13
10
  export * from './utils'
@@ -1,19 +1,30 @@
1
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
2
 
3
- import { DataProvider } from '../data-provider'
4
- import { BotonicEvent } from './events'
3
+ export enum CASE_STATUS {
4
+ WAITING = 'status_waiting',
5
+ ATTENDING = 'status_attending',
6
+ IDLE = 'status_idle',
7
+ RESOLVED = 'status_resolved',
8
+ }
5
9
 
6
10
  export type CaseStatusType =
7
- | typeof CASE_STATUS.ATTENDING
8
- | typeof CASE_STATUS.IDLE
9
- | typeof CASE_STATUS.RESOLVED
10
- | typeof CASE_STATUS.WAITING
11
+ | CASE_STATUS.ATTENDING
12
+ | CASE_STATUS.IDLE
13
+ | CASE_STATUS.RESOLVED
14
+ | CASE_STATUS.WAITING
15
+
16
+ export enum CASE_RESOLUTION {
17
+ OK = 'result_ok',
18
+ NOK = 'result_nok',
19
+ NOT_SOLVED = 'result_not_solved',
20
+ BANNED = 'result_banned',
21
+ }
11
22
 
12
23
  export type CaseResolution =
13
- | typeof CASE_RESOLUTION.BANNED
14
- | typeof CASE_RESOLUTION.NOK
15
- | typeof CASE_RESOLUTION.NOT_SOLVED
16
- | typeof CASE_RESOLUTION.OK
24
+ | CASE_RESOLUTION.BANNED
25
+ | CASE_RESOLUTION.NOK
26
+ | CASE_RESOLUTION.NOT_SOLVED
27
+ | CASE_RESOLUTION.OK
17
28
 
18
29
  export enum PROVIDER {
19
30
  APPLE = 'apple',
@@ -30,6 +41,19 @@ export enum PROVIDER {
30
41
  WHATSAPP = 'whatsapp',
31
42
  }
32
43
 
44
+ export type ProviderType =
45
+ | PROVIDER.DEV
46
+ | PROVIDER.FACEBOOK
47
+ | PROVIDER.GENERIC
48
+ | PROVIDER.INSTAGRAM
49
+ | PROVIDER.INTERCOM
50
+ | PROVIDER.SMOOCH
51
+ | PROVIDER.TELEGRAM
52
+ | PROVIDER.TWITTER
53
+ | PROVIDER.WEBCHAT
54
+ | PROVIDER.WECHAT
55
+ | PROVIDER.WHATSAPP
56
+
33
57
  export enum INPUT {
34
58
  TEXT = 'text',
35
59
  POSTBACK = 'postback',
@@ -50,20 +74,6 @@ export enum INPUT {
50
74
  WHATSAPP_CTA_URL_BUTTON = 'whatsapp-cta-url-button',
51
75
  }
52
76
 
53
- export enum CASE_STATUS {
54
- WAITING = 'status_waiting',
55
- ATTENDING = 'status_attending',
56
- IDLE = 'status_idle',
57
- RESOLVED = 'status_resolved',
58
- }
59
-
60
- export enum CASE_RESOLUTION {
61
- OK = 'result_ok',
62
- NOK = 'result_nok',
63
- NOT_SOLVED = 'result_not_solved',
64
- BANNED = 'result_banned',
65
- }
66
-
67
77
  export interface Locales {
68
78
  [id: string]: string | string[] | Locales
69
79
  }
@@ -86,22 +96,22 @@ export interface ResolvedPlugin extends Plugin {
86
96
  export type ResolvedPlugins = Record<string, ResolvedPlugin>
87
97
 
88
98
  export type InputType =
89
- | typeof INPUT.AUDIO
90
- | typeof INPUT.BUTTON_MESSAGE
91
- | typeof INPUT.CAROUSEL
92
- | typeof INPUT.CONTACT
93
- | typeof INPUT.CUSTOM
94
- | typeof INPUT.DOCUMENT
95
- | typeof INPUT.IMAGE
96
- | typeof INPUT.LOCATION
97
- | typeof INPUT.POSTBACK
98
- | typeof INPUT.TEXT
99
- | typeof INPUT.VIDEO
100
- | typeof INPUT.WEBCHAT_SETTINGS
101
- | typeof INPUT.WHATSAPP_TEMPLATE
102
- | typeof INPUT.CHAT_EVENT
103
- | typeof INPUT.WHATSAPP_BUTTON_LIST
104
- | typeof INPUT.WHATSAPP_CTA_URL_BUTTON
99
+ | INPUT.AUDIO
100
+ | INPUT.BUTTON_MESSAGE
101
+ | INPUT.CAROUSEL
102
+ | INPUT.CONTACT
103
+ | INPUT.CUSTOM
104
+ | INPUT.DOCUMENT
105
+ | INPUT.IMAGE
106
+ | INPUT.LOCATION
107
+ | INPUT.POSTBACK
108
+ | INPUT.TEXT
109
+ | INPUT.VIDEO
110
+ | INPUT.WEBCHAT_SETTINGS
111
+ | INPUT.WHATSAPP_TEMPLATE
112
+ | INPUT.CHAT_EVENT
113
+ | INPUT.WHATSAPP_BUTTON_LIST
114
+ | INPUT.WHATSAPP_CTA_URL_BUTTON
105
115
 
106
116
  export interface IntentResult {
107
117
  intent: string
@@ -132,21 +142,23 @@ export interface Input extends Partial<NluResult> {
132
142
  data?: string
133
143
  path?: string
134
144
  payload?: string
145
+ referral?: string
135
146
  type: InputType
147
+ context?: {
148
+ campaign?: Campaign
149
+ }
150
+ message_id?: string
136
151
  }
137
152
 
138
- export type ProviderType =
139
- | typeof PROVIDER.DEV
140
- | typeof PROVIDER.FACEBOOK
141
- | typeof PROVIDER.GENERIC
142
- | typeof PROVIDER.INSTAGRAM
143
- | typeof PROVIDER.INTERCOM
144
- | typeof PROVIDER.SMOOCH
145
- | typeof PROVIDER.TELEGRAM
146
- | typeof PROVIDER.TWITTER
147
- | typeof PROVIDER.WEBCHAT
148
- | typeof PROVIDER.WECHAT
149
- | typeof PROVIDER.WHATSAPP
153
+ export interface Campaign {
154
+ id: string
155
+ name: string
156
+ status: string
157
+ start_date: string
158
+ end_date: string
159
+ bot_path: string
160
+ template_name: string
161
+ }
150
162
 
151
163
  export interface SessionUser {
152
164
  id: string
@@ -161,8 +173,12 @@ export interface SessionUser {
161
173
  imp_id?: string
162
174
  provider_id?: string
163
175
  }
176
+ export interface HubtypeCaseContactReason {
177
+ id: string
178
+ name: string
179
+ project_id: string
180
+ }
164
181
 
165
- // eslint-disable @typescript-eslint/naming-convention
166
182
  export interface Session {
167
183
  bot: {
168
184
  id: string
@@ -170,18 +186,24 @@ export interface Session {
170
186
  }
171
187
  __locale?: string
172
188
  __retries: number
189
+ _access_token: string
190
+ _hubtype_api: string
173
191
  is_first_interaction: boolean
174
192
  last_session?: any
175
- organization: string
176
193
  organization_id: string
194
+ organization: string
177
195
  user: SessionUser
178
196
  // after handoff
197
+ _botonic_action?: string
179
198
  _hubtype_case_status?: CaseStatusType
199
+ _hubtype_case_id?: string
180
200
  _hubtype_case_typification?: string
201
+ _hubtype_case_contact_reasons?: HubtypeCaseContactReason[]
181
202
  _shadowing?: boolean
182
- _access_token?: string
203
+ external?: any
204
+ zendesk_ticket_id?: string
205
+ flow_thread_id?: string
183
206
  }
184
- // eslint-enable @typescript-eslint/naming-convention
185
207
 
186
208
  export type InputMatcher = (input: Input) => boolean
187
209
  export type ParamsMatcher =
@@ -225,7 +247,6 @@ export interface BotRequest {
225
247
  input: Input
226
248
  lastRoutePath: RoutePath
227
249
  session: Session
228
- dataProvider?: DataProvider
229
250
  }
230
251
 
231
252
  /** The response of the bot for the triggered actions, which can be
@@ -234,7 +255,6 @@ export interface BotRequest {
234
255
  * */
235
256
  export interface BotResponse extends BotRequest {
236
257
  response: any
237
- messageEvents: Partial<BotonicEvent>[] | null
238
258
  }
239
259
 
240
260
  export interface PluginPreRequest extends BotRequest {
@@ -253,24 +273,6 @@ export interface Params {
253
273
  [key: string]: any
254
274
  }
255
275
 
256
- export const Providers = Object.freeze({
257
- Messaging: {
258
- APPLE: 'apple',
259
- FACEBOOK: 'facebook',
260
- GENERIC: 'generic',
261
- IMBEE: 'imbee',
262
- INSTAGRAM: 'instagram',
263
- INTERCOM: 'intercom',
264
- SMOOCH_WEB: 'smooch_web',
265
- SMOOCH: 'smooch',
266
- TELEGRAM: 'telegram',
267
- TWITTER: 'twitter',
268
- WEBCHAT: 'webchat',
269
- WECHAT: 'wechat',
270
- WHATSAPP: 'whatsapp',
271
- },
272
- })
273
-
274
276
  export type Nullable<T> = T | null
275
277
 
276
278
  export type Action = Nullable<() => any>
package/src/plugins.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { DataProvider } from './data-provider'
2
1
  import {
3
- BotonicEvent,
4
2
  Input,
5
3
  PluginConfig,
6
4
  ResolvedPlugins,
@@ -34,15 +32,13 @@ export async function runPlugins(
34
32
  input: Input,
35
33
  session: Session,
36
34
  lastRoutePath: RoutePath,
37
- response: string | null = null,
38
- messageEvents: Partial<BotonicEvent>[] | null = null,
39
- dataProvider?: DataProvider
35
+ response: string | null = null
40
36
  ): Promise<void> {
41
37
  for (const key in plugins) {
42
38
  const p = await plugins[key]
43
39
  try {
44
40
  if (mode === 'pre' && p.pre) {
45
- await p.pre({ input, session, lastRoutePath, dataProvider, plugins })
41
+ await p.pre({ input, session, lastRoutePath, plugins })
46
42
  }
47
43
  if (mode === 'post' && p.post) {
48
44
  await p.post({
@@ -50,8 +46,6 @@ export async function runPlugins(
50
46
  session,
51
47
  lastRoutePath,
52
48
  response,
53
- messageEvents,
54
- dataProvider,
55
49
  plugins,
56
50
  })
57
51
  }
package/src/utils.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { PROVIDER, Session } from './models/legacy-types'
2
+
1
3
  export const isNode = (): boolean => {
2
4
  // @ts-ignore
3
5
  return typeof IS_NODE !== 'undefined'
@@ -76,3 +78,33 @@ export const join = (...segments: string[]): string => {
76
78
  // A simple function to get the dirname of a path
77
79
  // Trailing slashes are ignored. Leading slash is preserved.
78
80
  export const dirname = (path: string): string => join(path, '..')
81
+
82
+ // To check Provider in session
83
+ export function isDev(session: Session) {
84
+ return session.user.provider === PROVIDER.DEV
85
+ }
86
+
87
+ export function isWebchat(session: Session) {
88
+ // When the provider is DEV should we return true because it is a webchat?
89
+ return session.user.provider === PROVIDER.WEBCHAT
90
+ }
91
+
92
+ export function isWhatsapp(session: Session) {
93
+ return session.user.provider === PROVIDER.WHATSAPP
94
+ }
95
+
96
+ export function isTelegram(session: Session) {
97
+ return session.user.provider === PROVIDER.TELEGRAM
98
+ }
99
+
100
+ export function isFacebook(session: Session) {
101
+ return session.user.provider === PROVIDER.FACEBOOK
102
+ }
103
+
104
+ export function isInstagram(session: Session) {
105
+ return session.user.provider === PROVIDER.INSTAGRAM
106
+ }
107
+
108
+ export function isTwitter(session: Session) {
109
+ return session.user.provider === PROVIDER.TWITTER
110
+ }
@@ -1,26 +0,0 @@
1
- import { Entity, Table } from 'dynamodb-toolbox';
2
- import { BotonicEvent, User } from '../models';
3
- import { DataProvider } from './factory';
4
- export declare class DynamoDBDataProvider implements DataProvider {
5
- region: string;
6
- tableName: string;
7
- userEventsTable: Table;
8
- userEntity: Entity<any>;
9
- eventEntity: Entity<any>;
10
- messageEventEntities: Record<string, Entity<any>>;
11
- textMessageEventEntity: Entity<any>;
12
- connectionEventEntity: Entity<any>;
13
- constructor(url: string);
14
- getUsers(limit?: number, offset?: number): Promise<User[]>;
15
- getUser(id: string): Promise<User | undefined>;
16
- getUserByWebsocketId(websocketId: string): Promise<User | undefined>;
17
- getUserByField(field: string, value: any): Promise<User | undefined>;
18
- saveUser(user: User): Promise<User>;
19
- updateUser(user: User): Promise<User>;
20
- deleteUser(id: string): Promise<User | undefined>;
21
- getEvents(limit?: number, offset?: number): Promise<BotonicEvent[]>;
22
- getEvent(id: string): Promise<BotonicEvent | undefined>;
23
- saveEvent(event: BotonicEvent): Promise<BotonicEvent>;
24
- updateEvent(event: BotonicEvent): Promise<BotonicEvent>;
25
- deleteEvent(id: string): Promise<BotonicEvent | undefined>;
26
- }