@botonic/core 0.56.0-alpha.0 → 0.57.0-rslib-esm.1

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 (175) hide show
  1. package/lib/constants.js +8 -0
  2. package/lib/constants.js.map +1 -0
  3. package/lib/{esm/core-bot.d.ts → core-bot.d.ts} +3 -3
  4. package/lib/{cjs/core-bot.js → core-bot.js} +87 -50
  5. package/lib/core-bot.js.map +1 -0
  6. package/lib/debug/index.d.ts +1 -0
  7. package/lib/debug/index.js +6 -0
  8. package/lib/debug/index.js.map +1 -0
  9. package/lib/{cjs/debug → debug}/inspector.d.ts +1 -1
  10. package/lib/{cjs/debug → debug}/inspector.js +27 -21
  11. package/lib/debug/inspector.js.map +1 -0
  12. package/lib/{cjs/handoff.d.ts → handoff.d.ts} +1 -1
  13. package/lib/{esm/handoff.js → handoff.js} +82 -53
  14. package/lib/handoff.js.map +1 -0
  15. package/lib/{esm/hubtype-service.d.ts → hubtype-service.d.ts} +3 -3
  16. package/lib/{cjs/hubtype-service.js → hubtype-service.js} +100 -64
  17. package/lib/hubtype-service.js.map +1 -0
  18. package/lib/index.d.ts +9 -0
  19. package/lib/index.js +22 -0
  20. package/lib/index.js.map +1 -0
  21. package/lib/{esm/models → models}/ai-agents.d.ts +1 -8
  22. package/lib/models/ai-agents.js +30 -0
  23. package/lib/models/ai-agents.js.map +1 -0
  24. package/lib/models/bot-config.js +10 -0
  25. package/lib/models/bot-config.js.map +1 -0
  26. package/lib/{esm/models → models}/hubtype-analytics.d.ts +1 -1
  27. package/lib/{esm/models → models}/hubtype-analytics.js +10 -10
  28. package/lib/models/hubtype-analytics.js.map +1 -0
  29. package/lib/models/index.d.ts +4 -0
  30. package/lib/models/index.js +12 -0
  31. package/lib/models/index.js.map +1 -0
  32. package/lib/{esm/models → models}/legacy-types.js +24 -24
  33. package/lib/models/legacy-types.js.map +1 -0
  34. package/lib/{cjs/plugins.d.ts → plugins.d.ts} +1 -1
  35. package/lib/{esm/plugins.js → plugins.js} +7 -8
  36. package/lib/plugins.js.map +1 -0
  37. package/lib/pusher-utils.js +23 -0
  38. package/lib/pusher-utils.js.map +1 -0
  39. package/lib/routing/index.d.ts +2 -0
  40. package/lib/routing/index.js +8 -0
  41. package/lib/routing/index.js.map +1 -0
  42. package/lib/{cjs/routing → routing}/router-utils.d.ts +1 -1
  43. package/lib/{cjs/routing → routing}/router-utils.js +37 -30
  44. package/lib/routing/router-utils.js.map +1 -0
  45. package/lib/{cjs/routing → routing}/router.d.ts +2 -2
  46. package/lib/routing/router.js +333 -0
  47. package/lib/routing/router.js.map +1 -0
  48. package/lib/{esm/testing → testing}/index.d.ts +1 -1
  49. package/lib/testing/index.js +162 -0
  50. package/lib/testing/index.js.map +1 -0
  51. package/lib/{cjs/utils → utils}/bot-config.d.ts +1 -1
  52. package/lib/{esm/utils → utils}/bot-config.js +57 -28
  53. package/lib/utils/bot-config.js.map +1 -0
  54. package/lib/{cjs/utils → utils}/check-providers.d.ts +1 -1
  55. package/lib/utils/check-providers.js +31 -0
  56. package/lib/utils/check-providers.js.map +1 -0
  57. package/lib/utils/functional.js +69 -0
  58. package/lib/utils/functional.js.map +1 -0
  59. package/lib/utils/index.d.ts +3 -0
  60. package/lib/utils/index.js +10 -0
  61. package/lib/utils/index.js.map +1 -0
  62. package/package.json +14 -12
  63. package/src/hubtype-service.ts +4 -2
  64. package/src/models/ai-agents.ts +0 -9
  65. package/lib/cjs/constants.js +0 -8
  66. package/lib/cjs/constants.js.map +0 -1
  67. package/lib/cjs/core-bot.d.ts +0 -43
  68. package/lib/cjs/core-bot.js.map +0 -1
  69. package/lib/cjs/debug/index.d.ts +0 -1
  70. package/lib/cjs/debug/index.js +0 -5
  71. package/lib/cjs/debug/index.js.map +0 -1
  72. package/lib/cjs/debug/inspector.js.map +0 -1
  73. package/lib/cjs/handoff.js +0 -238
  74. package/lib/cjs/handoff.js.map +0 -1
  75. package/lib/cjs/hubtype-service.d.ts +0 -58
  76. package/lib/cjs/hubtype-service.js.map +0 -1
  77. package/lib/cjs/index.d.ts +0 -9
  78. package/lib/cjs/index.js +0 -13
  79. package/lib/cjs/index.js.map +0 -1
  80. package/lib/cjs/models/ai-agents.d.ts +0 -147
  81. package/lib/cjs/models/ai-agents.js +0 -31
  82. package/lib/cjs/models/ai-agents.js.map +0 -1
  83. package/lib/cjs/models/bot-config.js +0 -10
  84. package/lib/cjs/models/bot-config.js.map +0 -1
  85. package/lib/cjs/models/hubtype-analytics.d.ts +0 -210
  86. package/lib/cjs/models/hubtype-analytics.js +0 -38
  87. package/lib/cjs/models/hubtype-analytics.js.map +0 -1
  88. package/lib/cjs/models/index.d.ts +0 -4
  89. package/lib/cjs/models/index.js +0 -8
  90. package/lib/cjs/models/index.js.map +0 -1
  91. package/lib/cjs/models/legacy-types.js +0 -84
  92. package/lib/cjs/models/legacy-types.js.map +0 -1
  93. package/lib/cjs/plugins.js +0 -24
  94. package/lib/cjs/plugins.js.map +0 -1
  95. package/lib/cjs/pusher-utils.js +0 -18
  96. package/lib/cjs/pusher-utils.js.map +0 -1
  97. package/lib/cjs/routing/index.d.ts +0 -2
  98. package/lib/cjs/routing/index.js +0 -6
  99. package/lib/cjs/routing/index.js.map +0 -1
  100. package/lib/cjs/routing/router-utils.js.map +0 -1
  101. package/lib/cjs/routing/router.js +0 -330
  102. package/lib/cjs/routing/router.js.map +0 -1
  103. package/lib/cjs/testing/index.d.ts +0 -91
  104. package/lib/cjs/testing/index.js +0 -196
  105. package/lib/cjs/testing/index.js.map +0 -1
  106. package/lib/cjs/utils/bot-config.js +0 -94
  107. package/lib/cjs/utils/bot-config.js.map +0 -1
  108. package/lib/cjs/utils/check-providers.js +0 -34
  109. package/lib/cjs/utils/check-providers.js.map +0 -1
  110. package/lib/cjs/utils/functional.js +0 -88
  111. package/lib/cjs/utils/functional.js.map +0 -1
  112. package/lib/cjs/utils/index.d.ts +0 -3
  113. package/lib/cjs/utils/index.js +0 -7
  114. package/lib/cjs/utils/index.js.map +0 -1
  115. package/lib/esm/constants.d.ts +0 -4
  116. package/lib/esm/constants.js +0 -8
  117. package/lib/esm/constants.js.map +0 -1
  118. package/lib/esm/core-bot.js +0 -205
  119. package/lib/esm/core-bot.js.map +0 -1
  120. package/lib/esm/debug/index.d.ts +0 -1
  121. package/lib/esm/debug/index.js +0 -5
  122. package/lib/esm/debug/index.js.map +0 -1
  123. package/lib/esm/debug/inspector.d.ts +0 -24
  124. package/lib/esm/debug/inspector.js +0 -70
  125. package/lib/esm/debug/inspector.js.map +0 -1
  126. package/lib/esm/handoff.d.ts +0 -110
  127. package/lib/esm/handoff.js.map +0 -1
  128. package/lib/esm/hubtype-service.js +0 -205
  129. package/lib/esm/hubtype-service.js.map +0 -1
  130. package/lib/esm/index.d.ts +0 -9
  131. package/lib/esm/index.js +0 -13
  132. package/lib/esm/index.js.map +0 -1
  133. package/lib/esm/models/ai-agents.js +0 -31
  134. package/lib/esm/models/ai-agents.js.map +0 -1
  135. package/lib/esm/models/bot-config.d.ts +0 -24
  136. package/lib/esm/models/bot-config.js +0 -10
  137. package/lib/esm/models/bot-config.js.map +0 -1
  138. package/lib/esm/models/hubtype-analytics.js.map +0 -1
  139. package/lib/esm/models/index.d.ts +0 -4
  140. package/lib/esm/models/index.js +0 -8
  141. package/lib/esm/models/index.js.map +0 -1
  142. package/lib/esm/models/legacy-types.d.ts +0 -332
  143. package/lib/esm/models/legacy-types.js.map +0 -1
  144. package/lib/esm/plugins.d.ts +0 -9
  145. package/lib/esm/plugins.js.map +0 -1
  146. package/lib/esm/pusher-utils.d.ts +0 -7
  147. package/lib/esm/pusher-utils.js +0 -18
  148. package/lib/esm/pusher-utils.js.map +0 -1
  149. package/lib/esm/routing/index.d.ts +0 -2
  150. package/lib/esm/routing/index.js +0 -6
  151. package/lib/esm/routing/index.js.map +0 -1
  152. package/lib/esm/routing/router-utils.d.ts +0 -11
  153. package/lib/esm/routing/router-utils.js +0 -96
  154. package/lib/esm/routing/router-utils.js.map +0 -1
  155. package/lib/esm/routing/router.d.ts +0 -54
  156. package/lib/esm/routing/router.js +0 -330
  157. package/lib/esm/routing/router.js.map +0 -1
  158. package/lib/esm/testing/index.js +0 -196
  159. package/lib/esm/testing/index.js.map +0 -1
  160. package/lib/esm/utils/bot-config.d.ts +0 -4
  161. package/lib/esm/utils/bot-config.js.map +0 -1
  162. package/lib/esm/utils/check-providers.d.ts +0 -8
  163. package/lib/esm/utils/check-providers.js +0 -34
  164. package/lib/esm/utils/check-providers.js.map +0 -1
  165. package/lib/esm/utils/functional.d.ts +0 -10
  166. package/lib/esm/utils/functional.js +0 -88
  167. package/lib/esm/utils/functional.js.map +0 -1
  168. package/lib/esm/utils/index.d.ts +0 -3
  169. package/lib/esm/utils/index.js +0 -7
  170. package/lib/esm/utils/index.js.map +0 -1
  171. /package/lib/{cjs/constants.d.ts → constants.d.ts} +0 -0
  172. /package/lib/{cjs/models → models}/bot-config.d.ts +0 -0
  173. /package/lib/{cjs/models → models}/legacy-types.d.ts +0 -0
  174. /package/lib/{cjs/pusher-utils.d.ts → pusher-utils.d.ts} +0 -0
  175. /package/lib/{cjs/utils → utils}/functional.d.ts +0 -0
@@ -1,332 +0,0 @@
1
- export declare enum CASE_STATUS {
2
- WAITING = "status_waiting",
3
- ATTENDING = "status_attending",
4
- IDLE = "status_idle",
5
- RESOLVED = "status_resolved"
6
- }
7
- export type CaseStatusType = CASE_STATUS.ATTENDING | CASE_STATUS.IDLE | CASE_STATUS.RESOLVED | CASE_STATUS.WAITING;
8
- export declare enum CASE_RESOLUTION {
9
- OK = "result_ok",
10
- NOK = "result_nok",
11
- NOT_SOLVED = "result_not_solved",
12
- BANNED = "result_banned"
13
- }
14
- export type CaseResolution = CASE_RESOLUTION.BANNED | CASE_RESOLUTION.NOK | CASE_RESOLUTION.NOT_SOLVED | CASE_RESOLUTION.OK;
15
- export declare enum PROVIDER {
16
- APPLE = "apple",
17
- DEV = "dev",
18
- FACEBOOK = "facebook",
19
- GENERIC = "generic",
20
- INSTAGRAM = "instagram",
21
- INTERCOM = "intercom",
22
- SMOOCH = "smooch",
23
- TELEGRAM = "telegram",
24
- TWITTER = "twitter",
25
- WEBCHAT = "webchat",
26
- WECHAT = "wechat",
27
- WHATSAPP = "whatsapp"
28
- }
29
- export type ProviderType = PROVIDER.DEV | PROVIDER.FACEBOOK | PROVIDER.GENERIC | PROVIDER.INSTAGRAM | PROVIDER.INTERCOM | PROVIDER.SMOOCH | PROVIDER.TELEGRAM | PROVIDER.TWITTER | PROVIDER.WEBCHAT | PROVIDER.WECHAT | PROVIDER.WHATSAPP;
30
- export declare enum INPUT {
31
- TEXT = "text",
32
- POSTBACK = "postback",
33
- AUDIO = "audio",
34
- IMAGE = "image",
35
- VIDEO = "video",
36
- DOCUMENT = "document",
37
- LOCATION = "location",
38
- CONTACT = "contact",
39
- BUTTON_MESSAGE = "buttonmessage",
40
- CAROUSEL = "carousel",
41
- CUSTOM = "custom",
42
- WEBCHAT_SETTINGS = "webchatsettings",
43
- WHATSAPP_TEMPLATE = "whatsapptemplate",
44
- RAW = "raw",
45
- CHAT_EVENT = "chatevent",
46
- WHATSAPP_BUTTON_LIST = "whatsapp-button-list",
47
- WHATSAPP_CTA_URL_BUTTON = "whatsapp-cta-url-button",
48
- WHATSAPP_REQUEST_CONTACT_INFO = "whatsapp-request-contact-info",
49
- WHATSAPP_CATALOG = "whatsapp-catalog",
50
- WHATSAPP_PRODUCT = "whatsapp-product",
51
- WHATSAPP_PRODUCT_LIST = "whatsapp-product-list",
52
- WHATSAPP_PRODUCT_CAROUSEL = "whatsapp-product-carousel",
53
- WHATSAPP_MEDIA_CAROUSEL = "whatsapp-media-carousel",
54
- WHATSAPP_ORDER = "whatsapp_order",
55
- EVENT_AGENT_MESSAGE_CREATED = "case_event_agent_message_created",
56
- EVENT_QUEUE_POSITION_CHANGED = "case_event_queue_position_changed",
57
- EVENT_CASE_STATUS_CHANGED = "case_event_status_changed",
58
- SYSTEM_DEBUG_TRACE = "system_debug_trace"
59
- }
60
- interface PluginConstructor<T> {
61
- new (arg: T): Plugin;
62
- }
63
- export interface PluginConfig<T> {
64
- id: string;
65
- options?: T;
66
- resolve: {
67
- default: PluginConstructor<T>;
68
- };
69
- }
70
- export type ResolvedPlugins = Record<string, Plugin>;
71
- export type InputType = INPUT.AUDIO | INPUT.BUTTON_MESSAGE | INPUT.CAROUSEL | INPUT.CONTACT | INPUT.CUSTOM | INPUT.DOCUMENT | INPUT.IMAGE | INPUT.LOCATION | INPUT.POSTBACK | INPUT.TEXT | INPUT.VIDEO | INPUT.CHAT_EVENT | INPUT.WEBCHAT_SETTINGS | INPUT.WHATSAPP_TEMPLATE | INPUT.WHATSAPP_BUTTON_LIST | INPUT.WHATSAPP_CTA_URL_BUTTON | INPUT.WHATSAPP_REQUEST_CONTACT_INFO | INPUT.WHATSAPP_CATALOG | INPUT.WHATSAPP_PRODUCT | INPUT.WHATSAPP_PRODUCT_LIST | INPUT.WHATSAPP_PRODUCT_CAROUSEL | INPUT.WHATSAPP_MEDIA_CAROUSEL | INPUT.WHATSAPP_ORDER | INPUT.EVENT_AGENT_MESSAGE_CREATED | INPUT.EVENT_QUEUE_POSITION_CHANGED | INPUT.EVENT_CASE_STATUS_CHANGED;
72
- /** Generated by Translation plugins: GoogleTranslation **/
73
- export interface Translations {
74
- [languageCode: string]: string;
75
- }
76
- export declare enum NluType {
77
- Keyword = "keyword",
78
- SmartIntent = "smart-intent"
79
- }
80
- export interface Input {
81
- text?: string;
82
- src?: string;
83
- data?: string;
84
- path?: string;
85
- payload?: string;
86
- referral?: string;
87
- type: InputType;
88
- context?: {
89
- campaign?: Campaign;
90
- campaigns_v2?: CampaignV2[];
91
- salesforce?: {
92
- access_token: string;
93
- };
94
- };
95
- transcript?: string;
96
- message_id: string;
97
- bot_interaction_id: string;
98
- catalog_id?: string;
99
- product_items?: ProductItem[];
100
- nluResolution?: {
101
- type: NluType;
102
- matchedValue: string;
103
- payload?: string;
104
- };
105
- origin?: string;
106
- }
107
- export interface CaseEventQueuePositionChangedInput {
108
- type: INPUT.EVENT_QUEUE_POSITION_CHANGED;
109
- case_id: string;
110
- prev_queue_position: number | null;
111
- prev_queue_position_notified_at: string | null;
112
- current_queue_position: number;
113
- current_queue_position_notified_at: string;
114
- total_queue_waiting_cases_number: number;
115
- }
116
- export declare enum CaseStatus {
117
- Waiting = "status_waiting",
118
- Attending = "status_attending",
119
- Idle = "status_idle",
120
- Resolved = "status_resolved"
121
- }
122
- export interface CaseEventStatusChangedInput {
123
- type: INPUT.EVENT_CASE_STATUS_CHANGED;
124
- case_id: string;
125
- prev_status: CaseStatus | null;
126
- next_status: CaseStatus;
127
- }
128
- export interface CaseEventAgentMessageCreatedInput {
129
- type: INPUT.EVENT_AGENT_MESSAGE_CREATED;
130
- agent_id?: string;
131
- agent_name?: string;
132
- message?: {
133
- type: string;
134
- data: string;
135
- };
136
- }
137
- interface ProductItem {
138
- product_retailer_id: string;
139
- quantity: number;
140
- item_price: number;
141
- currency: string;
142
- }
143
- export interface Campaign {
144
- id: string;
145
- name: string;
146
- status: string;
147
- start_date: string;
148
- end_date: string;
149
- bot_path: string;
150
- template_name: string;
151
- }
152
- export interface CampaignV2 {
153
- id: string;
154
- name: string;
155
- agent_context?: string;
156
- end_date?: string;
157
- }
158
- export interface ContactInfo {
159
- name: string;
160
- type: string;
161
- value: string;
162
- description?: string;
163
- }
164
- export interface SessionUser<TExtraData = any> {
165
- id: string;
166
- username?: string;
167
- name?: string;
168
- provider: ProviderType;
169
- extra_data?: TExtraData;
170
- contact_info?: ContactInfo[];
171
- imp_id?: string;
172
- provider_id?: string;
173
- locale: string;
174
- country: string;
175
- system_locale: string;
176
- system_locale_updated?: boolean;
177
- }
178
- export interface HubtypeCaseContactReason {
179
- id: string;
180
- name: string;
181
- project_id: string;
182
- }
183
- export interface SessionBot {
184
- id: string;
185
- name?: string;
186
- }
187
- export interface Session<TExtraData = any> {
188
- bot: SessionBot;
189
- __retries: number;
190
- _access_token: string;
191
- _hubtype_api: string;
192
- is_first_interaction: boolean;
193
- is_test_integration: boolean;
194
- last_session?: any;
195
- organization_id: string;
196
- organization: string;
197
- user: SessionUser<TExtraData>;
198
- _botonic_action?: BotonicActionType;
199
- _hubtype_case_resolution?: CaseResolution;
200
- _hubtype_case_id?: string;
201
- _hubtype_case_typification?: string;
202
- _hubtype_case_contact_reasons?: HubtypeCaseContactReason[];
203
- _shadowing?: boolean;
204
- external?: any;
205
- zendesk_ticket_id?: string;
206
- flow_thread_id?: string;
207
- __campaign?: {
208
- id: string;
209
- path: string;
210
- active: boolean;
211
- };
212
- capture_user_input?: {
213
- node_id: string;
214
- };
215
- }
216
- export type InputMatcher = (input: Input) => boolean;
217
- export type ParamsMatcher = {
218
- [key: string]: string;
219
- } | ((params: {
220
- [key: string]: string;
221
- }) => boolean);
222
- export type SessionMatcher<TExtraData = any> = (session: Session<TExtraData>) => boolean;
223
- export type RequestMatcher<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = (request: BotContext<TPlugins, TExtraData>) => boolean;
224
- export type StringMatcher = RegExp | string | ((data: string) => boolean);
225
- export type RouteMatcher = InputMatcher | ParamsMatcher | RequestMatcher | SessionMatcher | StringMatcher;
226
- export interface Route<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
227
- action?: any;
228
- childRoutes?: Route[];
229
- lastRoutePath?: string;
230
- ignoreRetry?: boolean;
231
- path: RoutePath;
232
- redirect?: string;
233
- retry?: number;
234
- input?: InputMatcher;
235
- params?: ParamsMatcher;
236
- payload?: StringMatcher;
237
- request?: RequestMatcher<TPlugins, TExtraData>;
238
- session?: SessionMatcher<TExtraData>;
239
- text?: StringMatcher;
240
- data?: StringMatcher;
241
- type?: StringMatcher;
242
- }
243
- export type Routes<R = Route> = R[] | ((request: BotContext) => R[]);
244
- export interface BotRequest<TExtraData = any> {
245
- input: Input;
246
- lastRoutePath: RoutePath;
247
- session: Session<TExtraData>;
248
- settings: BotSettings;
249
- secrets: BotSecrets;
250
- }
251
- export interface BotSettings {
252
- HUBTYPE_API_URL: string;
253
- STATIC_URL: string;
254
- LITELLM_API_URL: string;
255
- AZURE_OPENAI_API_BASE: string;
256
- AZURE_OPENAI_API_VERSION: string;
257
- LANGUAGE_DETECTION_ENABLED?: boolean;
258
- CUSTOM_SHORT_URL_HOST: string | null;
259
- custom: Record<string, any>;
260
- }
261
- export interface BotSecrets {
262
- HUBTYPE_ACCESS_TOKEN: string;
263
- LITELLM_API_KEY: string;
264
- AZURE_OPENAI_API_KEY: string;
265
- custom: Record<string, any>;
266
- }
267
- export interface BotContext<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> extends BotRequest<TExtraData> {
268
- getUserCountry: () => string;
269
- getUserLocale: () => string;
270
- getSystemLocale: () => string;
271
- setUserCountry: (country: string) => void;
272
- setUserLocale: (locale: string) => void;
273
- setSystemLocale: (locale: string) => void;
274
- defaultDelay: number;
275
- defaultTyping: number;
276
- params: Record<string, string>;
277
- plugins: TPlugins;
278
- }
279
- /** The response of the bot for the triggered actions, which can be
280
- * the one matched by the routes, the default action and the retry actions.
281
- * See Response at @botonic/react's index.d.ts for the React type
282
- * */
283
- export interface BotResponse extends BotRequest {
284
- response: any;
285
- }
286
- export type PluginPreRequest<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = BotContext<TPlugins, TExtraData>;
287
- export type PluginPostRequest<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = BotContext<TPlugins, TExtraData> & {
288
- response: string | null;
289
- };
290
- export interface Plugin {
291
- post?(request: PluginPostRequest): void | Promise<void>;
292
- pre?(request: PluginPreRequest): void | Promise<void>;
293
- }
294
- export interface Params {
295
- [key: string]: any;
296
- }
297
- export type Nullable<T> = T | null;
298
- export type Action = Nullable<() => any>;
299
- export type RoutePath = Nullable<string>;
300
- export interface ProcessInputResult {
301
- action: Action;
302
- emptyAction: Action;
303
- fallbackAction: Action;
304
- lastRoutePath: RoutePath;
305
- params: Params;
306
- }
307
- export type MatchedValue = boolean | RegExpExecArray | null;
308
- export type RoutingState = {
309
- currentRoute: Nullable<Route>;
310
- matchedRoute: Nullable<Route>;
311
- params: Params;
312
- isFlowBroken: boolean;
313
- };
314
- export interface RouteParams {
315
- route: Nullable<Route>;
316
- params: Params;
317
- }
318
- export interface PathParams {
319
- path: RoutePath;
320
- params: Params;
321
- }
322
- export type MatchingProp = 'text' | 'payload' | 'type' | 'input' | 'session' | 'request';
323
- export type Matcher = string | RegExp | ((args: any) => boolean);
324
- export type BotonicActionType = `${BotonicAction.CreateCase}${BotonicActionSeparator}${string}` | `${BotonicAction.Redirect}${BotonicActionSeparator}${string}` | `${BotonicAction.DiscardCase}${BotonicActionSeparator}${string}` | `${BotonicAction.DiscardCase}` | `${BotonicAction.DeleteUser}`;
325
- type BotonicActionSeparator = ':';
326
- export declare enum BotonicAction {
327
- Redirect = "redirect_action",
328
- CreateCase = "create_case",
329
- DeleteUser = "delete_user",
330
- DiscardCase = "discard_case"
331
- }
332
- export {};
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy-types.js","sourceRoot":"","sources":["../../../src/models/legacy-types.ts"],"names":[],"mappings":";AAAA,wIAAwI;;;AAExI,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,yCAA0B,CAAA;IAC1B,6CAA8B,CAAA;IAC9B,mCAAoB,CAAA;IACpB,2CAA4B,CAAA;AAC9B,CAAC,EALW,WAAW,2BAAX,WAAW,QAKtB;AAQD,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,mCAAgB,CAAA;IAChB,qCAAkB,CAAA;IAClB,mDAAgC,CAAA;IAChC,2CAAwB,CAAA;AAC1B,CAAC,EALW,eAAe,+BAAf,eAAe,QAK1B;AAQD,IAAY,QAaX;AAbD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,uBAAW,CAAA;IACX,iCAAqB,CAAA;IACrB,+BAAmB,CAAA;IACnB,mCAAuB,CAAA;IACvB,iCAAqB,CAAA;IACrB,6BAAiB,CAA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a,6BAAb,aAAa,QAKxB"}
@@ -1,9 +0,0 @@
1
- import type { BotContext } from './models';
2
- interface RunPluginArgs {
3
- botContext: BotContext;
4
- mode: PluginMode;
5
- response?: string | null;
6
- }
7
- type PluginMode = 'pre' | 'post';
8
- export declare function runPlugins({ botContext, mode, response, }: RunPluginArgs): Promise<void>;
9
- export {};
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../src/plugins.ts"],"names":[],"mappings":";;AAUA,gCAsBC;AAtBM,KAAK,UAAU,UAAU,CAAC,EAC/B,UAAU,EACV,IAAI,EACJ,QAAQ,GAAG,IAAI,GACD;IACd,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAA;IAClC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAW,OAAO,CAAC,GAAG,CAAC,CAAA;QACnC,IAAI,CAAC;YACH,IAAI,IAAI,KAAK,KAAK,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;gBACvD,MAAM,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;YAC9B,CAAC;YACD,IAAI,IAAI,KAAK,MAAM,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACzD,MAAM,MAAM,CAAC,IAAI,CAAC;oBAChB,GAAG,UAAU;oBACb,QAAQ;iBACT,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QAChB,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -1,7 +0,0 @@
1
- /**
2
- *
3
- * @param compressedData a string representing gzipped data previously encoded to base64 for very large contents
4
- * @returns a string representing the information of a very large content
5
- * Ref: https://stackoverflow.com/questions/4875020/javascript-decompress-inflate-unzip-ungzip-strings (check jsfiddle proposal)
6
- */
7
- export declare function decompressData(compressedData: string): string;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decompressData = decompressData;
4
- const pako_1 = require("pako");
5
- /**
6
- *
7
- * @param compressedData a string representing gzipped data previously encoded to base64 for very large contents
8
- * @returns a string representing the information of a very large content
9
- * Ref: https://stackoverflow.com/questions/4875020/javascript-decompress-inflate-unzip-ungzip-strings (check jsfiddle proposal)
10
- */
11
- function decompressData(compressedData) {
12
- const strData = atob(compressedData); // Decode base64 (convert ascii to binary)
13
- const charData = strData.split('').map(x => x.charCodeAt(0)); // Convert binary string to character-number array
14
- const binData = new Uint8Array(charData); // Turn number array into byte-array
15
- const data = (0, pako_1.inflate)(binData);
16
- return new TextDecoder('utf-8').decode(data);
17
- }
18
- //# sourceMappingURL=pusher-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pusher-utils.js","sourceRoot":"","sources":["../../src/pusher-utils.ts"],"names":[],"mappings":";;AAQA,wCAMC;AAdD,+BAA8B;AAE9B;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,cAAsB;IACnD,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,CAAA,CAAC,0CAA0C;IAC/E,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA,CAAC,kDAAkD;IAC/G,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAA,CAAC,oCAAoC;IAC7E,MAAM,IAAI,GAAG,IAAA,cAAO,EAAC,OAAO,CAAC,CAAA;IAC7B,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAC9C,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './router';
2
- export * from './router-utils';
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./router"), exports);
5
- tslib_1.__exportStar(require("./router-utils"), exports);
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/routing/index.ts"],"names":[],"mappings":";;;AAAA,mDAAwB;AACxB,yDAA8B"}
@@ -1,11 +0,0 @@
1
- import type { Action, BotContext, Input, Params, PathParams, Route, Routes } from '../models';
2
- export declare class NoMatchingRouteError extends Error {
3
- input: Input;
4
- constructor(input: Input);
5
- }
6
- export declare function isPathPayload(payload?: string): boolean;
7
- export declare function getPathParamsFromPathPayload(payload?: string): PathParams;
8
- export declare function pathParamsToParams(pathParams?: string): Params;
9
- export declare function getEmptyAction(childRoutes?: Route[]): Action;
10
- export declare function getNotFoundAction(input: Input, routes: Route[]): Action;
11
- export declare function getComputedRoutes(routes: Routes, botContext: BotContext): Promise<Route[]>;
@@ -1,96 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NoMatchingRouteError = void 0;
4
- exports.isPathPayload = isPathPayload;
5
- exports.getPathParamsFromPathPayload = getPathParamsFromPathPayload;
6
- exports.pathParamsToParams = pathParamsToParams;
7
- exports.getEmptyAction = getEmptyAction;
8
- exports.getNotFoundAction = getNotFoundAction;
9
- exports.getComputedRoutes = getComputedRoutes;
10
- const constants_1 = require("../constants");
11
- class NoMatchingRouteError extends Error {
12
- constructor(input) {
13
- super(`No route found for input '${JSON.stringify(input)}' and no ${constants_1.NOT_FOUND_PATH} route defined`);
14
- this.input = input;
15
- }
16
- }
17
- exports.NoMatchingRouteError = NoMatchingRouteError;
18
- function isPathPayload(payload) {
19
- if (!payload) {
20
- return false;
21
- }
22
- const isPathPayload = constants_1.PATH_PAYLOAD_REGEXP.exec(payload);
23
- return Boolean(isPathPayload);
24
- }
25
- function getPathParamsFromPathPayload(payload) {
26
- const defaultPathParams = {
27
- path: null,
28
- params: {},
29
- };
30
- if (!payload) {
31
- return defaultPathParams;
32
- }
33
- if (!isPathPayload(payload)) {
34
- return defaultPathParams;
35
- }
36
- try {
37
- const pathWithParams = payload.split(constants_1.PATH_PAYLOAD_IDENTIFIER)[1];
38
- if (!pathWithParams) {
39
- throw `${constants_1.PATH_PAYLOAD_IDENTIFIER} is empty`;
40
- }
41
- const [path, params] = pathWithParams.split('?');
42
- return { path: path ?? null, params: pathParamsToParams(params) };
43
- }
44
- catch (e) {
45
- console.error('Error getting path and params from input.payload:', e);
46
- return defaultPathParams;
47
- }
48
- }
49
- function pathParamsToParams(pathParams) {
50
- if (!pathParams) {
51
- return {};
52
- }
53
- try {
54
- const params = {};
55
- const searchParams = new URLSearchParams(pathParams);
56
- for (const [key, value] of searchParams) {
57
- params[key] = value;
58
- }
59
- return params;
60
- }
61
- catch (_e) {
62
- return {};
63
- }
64
- }
65
- function getEmptyAction(childRoutes) {
66
- if (!childRoutes) {
67
- return null;
68
- }
69
- const emptyActionRoute = childRoutes.find(r => r.path === constants_1.EMPTY_ACTION_PATH);
70
- if (!emptyActionRoute) {
71
- return null;
72
- }
73
- return emptyActionRoute.action;
74
- }
75
- function getNotFoundAction(input, routes) {
76
- const notFoundActionRoute = routes.find(r => r.path === constants_1.NOT_FOUND_PATH);
77
- if (!notFoundActionRoute) {
78
- throw new NoMatchingRouteError(input);
79
- }
80
- return notFoundActionRoute.action;
81
- }
82
- async function getComputedRoutes(routes, botContext) {
83
- if (routes instanceof Function) {
84
- return await getComputedRoutes(await routes(botContext), botContext);
85
- }
86
- for (const [key, route] of Object.entries(routes)) {
87
- if (route.childRoutes && route.childRoutes instanceof Function) {
88
- routes[key].childRoutes = await getComputedRoutes(await route.childRoutes(botContext), botContext);
89
- }
90
- else {
91
- routes[key] = route;
92
- }
93
- }
94
- return routes;
95
- }
96
- //# sourceMappingURL=router-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"router-utils.js","sourceRoot":"","sources":["../../../src/routing/router-utils.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mB,CAAC,MAAM,CAAA;AACnC,CAAC;AAEM,KAAK,UAAU,iBAAiB,CACrC,MAAc,EACd,UAAsB;IAEtB,IAAI,MAAM,YAAY,QAAQ,EAAE,CAAC;QAC/B,OAAO,MAAM,iBAAiB,CAAC,MAAM,MAAM,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAA;IACtE,CAAC;IACD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAQ,EAAE,CAAC;QACzD,IAAI,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,YAAY,QAAQ,EAAE,CAAC;YAC/D,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,GAAG,MAAM,iBAAiB,CAC/C,MAAM,KAAK,CAAC,WAAW,CAAC,UAAU,CAAC,EACnC,UAAU,CACX,CAAA;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QACrB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -1,54 +0,0 @@
1
- import { RouteInspector } from '../debug/inspector';
2
- import type { Input, MatchedValue, Matcher, MatchingProp, Nullable, ProcessInputResult, Route, RouteParams, RoutePath, RoutingState, Session } from '../models';
3
- export declare class Router {
4
- routes: Route[];
5
- routeInspector: RouteInspector;
6
- constructor(routes: Route[], routeInspector?: RouteInspector | undefined);
7
- /**
8
- * Processes an input and return a representation of the new bot state.
9
- * The algorithm is splitted in two main parts:
10
- * 1. Getting the current routing state.
11
- * 2. Given a routing state, resolve the different possible scenarios and return the new bot state.
12
- * The new bot state can return three type of actions:
13
- * - action: an action directly resolved from a matching route
14
- * - emptyAction: optional action that can exists or not only within childRoutes
15
- * - fallbackAction: any other action that acts as a fallback (404, )
16
- */
17
- processInput(input: Input, session: Session, lastRoutePath?: RoutePath): ProcessInputResult;
18
- /**
19
- * Find the route that matches the given input, if it match with some of the entries, return the whole Route of the entry with optional params captured if matcher was a regex.
20
- * IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects
21
- * */
22
- getRoute(input: Input | Partial<Input>, routes: Route[], session: Session, lastRoutePath: RoutePath): RouteParams | null;
23
- /**
24
- * Find the route that matches the given path. Path can include concatenations, e.g: 'Flow1/Subflow1.1'.
25
- * IMPORTANT: It returns a cloned route instead of the route itself to avoid modifying original routes and introduce side effects
26
- * */
27
- getRouteByPath(path: RoutePath, routeList?: Route[]): Nullable<Route>;
28
- /**
29
- * Returns the matched value for a specific route.
30
- * Matching Props: ('text' | 'payload' | 'intent' | 'type' | 'input' | 'session' | 'request' ...)
31
- * Matchers: (string: exact match | regex: regular expression match | function: return true)
32
- * input: user input object, e.g.: {type: 'text', data: 'Hi'}
33
- * */
34
- matchRoute(route: Route, prop: MatchingProp, matcher: Matcher, input: Input, session: Session, lastRoutePath: RoutePath): MatchedValue;
35
- /**
36
- * Runs the matcher against the given value.
37
- * If there is a match, it will return a truthy value (true, RegExp result), o.w., it will return a falsy value.
38
- * */
39
- matchValue(matcher: Matcher, value: any): MatchedValue;
40
- /**
41
- * It resolves the current state of navigation. Two scenarios:
42
- * 1. Given a path payload input (__PATH_PAYLOAD__somePath?someParam=someValue), we can resolve the routing state directly from it (using getRouteByPath).
43
- * 2. Given any other type of input, we resolve the routing state with normal resolution (using getRoute).
44
- * */
45
- getRoutingState(input: Input, session: Session, lastRoutePath: RoutePath): RoutingState;
46
- /**
47
- * Given a non path payload input, try to run it against the routes, update matching routes information in consequence and dictamine if the flow has been broken.
48
- * */
49
- getRoutingStateFromInput(currentRoute: Nullable<Route>, input: Input, session: Session): RoutingState;
50
- /**
51
- * Given a path payload input, try to run the path against the routes, update matching routes information in consequence and dictamine if the flow has been broken.
52
- * */
53
- getRoutingStateFromPathPayload(currentRoute: Nullable<Route>, pathPayload: string): RoutingState;
54
- }