@botonic/core 2.27.0 → 2.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/package.json +7 -2
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
- package/src/index.js.map +1 -1
- package/src/lib/actions/update-webchat-client-settings.d.ts +1 -1
- package/src/lib/actions/update-webchat-client-settings.js +2 -1
- package/src/lib/actions/update-webchat-client-settings.js.map +1 -1
- package/src/lib/core-bot/index.d.ts +2 -1
- package/src/lib/core-bot/index.js +3 -1
- package/src/lib/core-bot/index.js.map +1 -1
- package/src/lib/plugins/index.d.ts +1 -1
- package/src/lib/plugins/index.js +1 -1
- package/src/lib/plugins/index.js.map +1 -1
- package/src/lib/routes/router.d.ts +1 -1
- package/src/lib/routes/router.js.map +1 -1
- package/src/lib/routes/types.d.ts +4 -1
- package/src/lib/server/bot-server-message.d.ts +71 -0
- package/src/lib/server/bot-server-message.js +111 -0
- package/src/lib/server/bot-server-message.js.map +1 -0
- package/src/lib/server/botonic-context/botonic-action.d.ts +10 -0
- package/src/lib/server/botonic-context/botonic-action.js +9 -0
- package/src/lib/server/botonic-context/botonic-action.js.map +1 -0
- package/src/lib/server/botonic-context/botonic-context-input.d.ts +96 -0
- package/src/lib/server/botonic-context/botonic-context-input.js +123 -0
- package/src/lib/server/botonic-context/botonic-context-input.js.map +1 -0
- package/src/lib/server/botonic-context/botonic-context-session.d.ts +159 -0
- package/src/lib/server/botonic-context/botonic-context-session.js +297 -0
- package/src/lib/server/botonic-context/botonic-context-session.js.map +1 -0
- package/src/lib/server/botonic-context/botonic-context-settings.d.ts +16 -0
- package/src/lib/server/botonic-context/botonic-context-settings.js +48 -0
- package/src/lib/server/botonic-context/botonic-context-settings.js.map +1 -0
- package/src/lib/server/botonic-context/botonic-context.d.ts +59 -0
- package/src/lib/server/botonic-context/botonic-context.js +42 -0
- package/src/lib/server/botonic-context/botonic-context.js.map +1 -0
- package/src/lib/server/botonic-context/botonic-session-patch-slice.d.ts +30 -0
- package/src/lib/server/botonic-context/botonic-session-patch-slice.js +80 -0
- package/src/lib/server/botonic-context/botonic-session-patch-slice.js.map +1 -0
- package/src/lib/server/botonic-context/factory.d.ts +29 -0
- package/src/lib/server/botonic-context/factory.js +31 -0
- package/src/lib/server/botonic-context/factory.js.map +1 -0
- package/src/lib/server/botonic-context/index.d.ts +9 -0
- package/src/lib/server/botonic-context/index.js +10 -0
- package/src/lib/server/botonic-context/index.js.map +1 -0
- package/src/lib/server/botonic-context/send-messages-utils.d.ts +3 -0
- package/src/lib/server/botonic-context/send-messages-utils.js +33 -0
- package/src/lib/server/botonic-context/send-messages-utils.js.map +1 -0
- package/src/lib/server/botonic-context/types.d.ts +24 -0
- package/src/lib/server/botonic-context/types.js +6 -0
- package/src/lib/server/botonic-context/types.js.map +1 -0
- package/src/lib/server/factory.d.ts +182 -0
- package/src/lib/server/factory.js +209 -0
- package/src/lib/server/factory.js.map +1 -0
- package/src/lib/server/index.d.ts +3 -0
- package/src/lib/server/index.js +4 -0
- package/src/lib/server/index.js.map +1 -0
- package/src/lib/services/hubtype-api-service.d.ts +13 -0
- package/src/lib/services/hubtype-api-service.js +67 -0
- package/src/lib/services/hubtype-api-service.js.map +1 -0
- package/src/lib/services/hubtype-external-api-client.d.ts +22 -0
- package/src/lib/services/hubtype-external-api-client.js +111 -0
- package/src/lib/services/hubtype-external-api-client.js.map +1 -0
- package/src/lib/services/index.d.ts +2 -0
- package/src/lib/services/index.js +3 -0
- package/src/lib/services/index.js.map +1 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { BotonicSession, BotonicSessionBot, BotonicSessionHubtypeCase, BotonicSessionUser, BotonicSessionUserContactInfoItem, UserExtraData } from '@botonic/shared';
|
|
2
|
+
import { MessagingChannel } from '@botonic/shared';
|
|
3
|
+
import { WebchatClientSettings } from '@botonic/shared';
|
|
4
|
+
import { BotonicAction } from './botonic-action';
|
|
5
|
+
export type { UserExtraData };
|
|
6
|
+
export interface BotonicRequestSessionBasicEntity {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
export type BotonicRequestSessionOrganization = BotonicRequestSessionBasicEntity;
|
|
11
|
+
export type BotonicRequestSessionBot = BotonicRequestSessionBasicEntity;
|
|
12
|
+
export interface BotonicRequestSessionUserContactInfoItem {
|
|
13
|
+
name: string;
|
|
14
|
+
type: string;
|
|
15
|
+
value: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface BotonicRequestSessionChannel {
|
|
19
|
+
provider: MessagingChannel;
|
|
20
|
+
imp_id?: string;
|
|
21
|
+
unformatted_phone_number?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface BotonicRequestSessionUser<TExtraData extends UserExtraData = UserExtraData> {
|
|
24
|
+
id: string;
|
|
25
|
+
provider_id: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
override_name?: string;
|
|
28
|
+
extra_data?: TExtraData;
|
|
29
|
+
contact_info?: BotonicRequestSessionUserContactInfoItem[];
|
|
30
|
+
locale: string;
|
|
31
|
+
country: string;
|
|
32
|
+
system_locale: string;
|
|
33
|
+
}
|
|
34
|
+
export interface BotonicRequestSession<TExtraData extends UserExtraData = UserExtraData> {
|
|
35
|
+
organization: BotonicRequestSessionOrganization;
|
|
36
|
+
bot: BotonicRequestSessionBot;
|
|
37
|
+
channel: BotonicRequestSessionChannel;
|
|
38
|
+
user: BotonicRequestSessionUser<TExtraData>;
|
|
39
|
+
is_test_integration: boolean;
|
|
40
|
+
is_first_interaction: boolean;
|
|
41
|
+
shadowing: boolean;
|
|
42
|
+
flow_thread_id?: string;
|
|
43
|
+
had_hubtype_handoff: boolean;
|
|
44
|
+
hubtype_case?: BotonicSessionHubtypeCase;
|
|
45
|
+
custom: Record<string, any>;
|
|
46
|
+
external: Record<string, any>;
|
|
47
|
+
webviews_custom: Record<string, any>;
|
|
48
|
+
webchat_client_settings: WebchatClientSettings;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Hydrated BotonicSession from Lambda `session`.
|
|
52
|
+
* Field names match backend `model_dump(mode="json")` (snake_case).
|
|
53
|
+
*/
|
|
54
|
+
export interface BotonicSessionUpdate<TExtraData extends UserExtraData = UserExtraData> {
|
|
55
|
+
shadowing?: boolean | null;
|
|
56
|
+
flowThreadId?: string | null;
|
|
57
|
+
custom?: Record<string, unknown>;
|
|
58
|
+
webviewsCustom?: Record<string, unknown>;
|
|
59
|
+
webchatClientSettings?: Record<string, unknown>;
|
|
60
|
+
/** Flow Builder capture node id; maps to `capture_user_input_node_id` on `PATCH …/session/`. */
|
|
61
|
+
captureUserInputNodeId?: string | null;
|
|
62
|
+
/** Stored as `_botonic_action` on session; not sent on v2 session PATCH. */
|
|
63
|
+
botonicAction?: string | null;
|
|
64
|
+
/** Maps to `is_first_interaction` on session; included in `PATCH …/session/` when set. */
|
|
65
|
+
isFirstInteraction?: boolean;
|
|
66
|
+
user?: {
|
|
67
|
+
overrideName?: string | null;
|
|
68
|
+
extraData?: TExtraData;
|
|
69
|
+
locale?: string;
|
|
70
|
+
country?: string;
|
|
71
|
+
systemLocale?: string;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Maps camelCase session updates to snake_case PATCH body (v2 only).
|
|
76
|
+
*/
|
|
77
|
+
export declare function sessionUpdateToPatchBody<TExtraData extends UserExtraData = UserExtraData>(update: BotonicSessionUpdate<TExtraData>): Record<string, unknown>;
|
|
78
|
+
/**
|
|
79
|
+
* Mutates `session.raw` immediately so the rest of the turn sees updates.
|
|
80
|
+
* Handles `capture_user_input_node_id` (mirror of {@link sessionUpdateToPatchBody}) and
|
|
81
|
+
* `_botonic_action` (not sent on session PATCH).
|
|
82
|
+
* For `isFirstInteraction`, also updates in-memory `is_first_interaction`; the same
|
|
83
|
+
* value is emitted by {@link sessionUpdateToPatchBody} for `PATCH …/session/`.
|
|
84
|
+
*/
|
|
85
|
+
export declare function applyNonPatchSessionUpdateFields<TExtraData extends UserExtraData = UserExtraData>(session: BotonicSession<TExtraData>, updates: BotonicSessionUpdate<TExtraData>): void;
|
|
86
|
+
/**
|
|
87
|
+
* Maps `BotonicSessionUpdate.user` to `PATCH …/users/<user_id>/` body (ChatUserPatchSerializer keys, snake_case).
|
|
88
|
+
* Unknown keys are omitted — only serializer fields are sent.
|
|
89
|
+
*/
|
|
90
|
+
export declare function userUpdateToChatUserPatchBody<TExtraData extends UserExtraData = UserExtraData>(user: BotonicSessionUpdate<TExtraData>['user'] | undefined): Record<string, unknown>;
|
|
91
|
+
export declare class BotonicContextSessionUser<TExtraData extends UserExtraData = UserExtraData> {
|
|
92
|
+
private rawUser;
|
|
93
|
+
private readonly onUserUpdate?;
|
|
94
|
+
constructor(rawUser: BotonicSessionUser<TExtraData>, onUserUpdate?: ((updates: {
|
|
95
|
+
extraData?: TExtraData;
|
|
96
|
+
}) => void) | undefined);
|
|
97
|
+
get raw(): BotonicSessionUser<TExtraData>;
|
|
98
|
+
get id(): string;
|
|
99
|
+
get username(): string | undefined;
|
|
100
|
+
get name(): string | undefined;
|
|
101
|
+
get overrideName(): string | undefined;
|
|
102
|
+
get providerId(): string;
|
|
103
|
+
get locale(): string;
|
|
104
|
+
set locale(v: string);
|
|
105
|
+
get country(): string;
|
|
106
|
+
set country(v: string);
|
|
107
|
+
get systemLocale(): string;
|
|
108
|
+
set systemLocale(v: string);
|
|
109
|
+
get extraData(): TExtraData | undefined;
|
|
110
|
+
set extraData(v: TExtraData | undefined);
|
|
111
|
+
get contactInfo(): BotonicSessionUserContactInfoItem[] | undefined;
|
|
112
|
+
}
|
|
113
|
+
export declare class BotonicContextSession<TExtraData extends UserExtraData = UserExtraData> {
|
|
114
|
+
private sessionData;
|
|
115
|
+
private onUpdate?;
|
|
116
|
+
constructor(sessionData: BotonicSession<TExtraData>);
|
|
117
|
+
setOnUpdate(cb: (updates: BotonicSessionUpdate<TExtraData>) => void): void;
|
|
118
|
+
/** Replace underlying session object (e.g. after GET session from Hubtype). */
|
|
119
|
+
replaceSession(next: BotonicSession<TExtraData>): void;
|
|
120
|
+
get raw(): BotonicSession<TExtraData>;
|
|
121
|
+
get bot(): BotonicSessionBot;
|
|
122
|
+
get user(): BotonicContextSessionUser<TExtraData>;
|
|
123
|
+
get organizationId(): string;
|
|
124
|
+
get organizationName(): string;
|
|
125
|
+
get isFirstInteraction(): boolean;
|
|
126
|
+
set isFirstInteraction(v: boolean);
|
|
127
|
+
get botonicAction(): string | undefined;
|
|
128
|
+
set botonicAction(v: string | undefined);
|
|
129
|
+
isBotonicActionRedirect(): boolean;
|
|
130
|
+
getBotonicActionPayload(action: BotonicAction): string | undefined;
|
|
131
|
+
get isTestIntegration(): boolean;
|
|
132
|
+
get flowThreadId(): string | null | undefined;
|
|
133
|
+
get shadowing(): boolean | undefined;
|
|
134
|
+
set shadowing(v: boolean | undefined);
|
|
135
|
+
get hadHubtypeHandoff(): boolean | undefined;
|
|
136
|
+
get hubtypeCase(): BotonicSessionHubtypeCase | undefined;
|
|
137
|
+
/** Convenience for legacy code paths; prefer {@link hubtypeCase}. */
|
|
138
|
+
get hubtypeCaseId(): string | undefined;
|
|
139
|
+
get custom(): Record<string, unknown> | undefined;
|
|
140
|
+
get external(): Record<string, unknown> | undefined;
|
|
141
|
+
get webviewsCustom(): Record<string, unknown> | undefined;
|
|
142
|
+
set webviewsCustom(v: Record<string, unknown> | undefined);
|
|
143
|
+
get webchatClientSettings(): WebchatClientSettings;
|
|
144
|
+
set webchatClientSettings(v: WebchatClientSettings);
|
|
145
|
+
/** Flow Builder: node id capturing user input (`capture_user_input_node_id` in JSON). */
|
|
146
|
+
get captureUserInputNodeId(): string | undefined;
|
|
147
|
+
/** Channel provider (e.g. webchat, whatsapp). */
|
|
148
|
+
get provider(): string;
|
|
149
|
+
get impId(): string;
|
|
150
|
+
get unformattedPhoneNumber(): string | undefined;
|
|
151
|
+
isDev(): boolean;
|
|
152
|
+
isWebchat(): boolean;
|
|
153
|
+
isTelegram(): boolean;
|
|
154
|
+
isFacebook(): boolean;
|
|
155
|
+
isInstagram(): boolean;
|
|
156
|
+
isTwitter(): boolean;
|
|
157
|
+
isWhatsapp(): boolean;
|
|
158
|
+
hasFlowThreadId(): boolean;
|
|
159
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { MessagingChannel } from '@botonic/shared';
|
|
2
|
+
import { DEFAULT_WEBCHAT_CLIENT_SETTINGS, } from '@botonic/shared';
|
|
3
|
+
import { BotonicAction } from './botonic-action';
|
|
4
|
+
/**
|
|
5
|
+
* Maps camelCase session updates to snake_case PATCH body (v2 only).
|
|
6
|
+
*/
|
|
7
|
+
export function sessionUpdateToPatchBody(update) {
|
|
8
|
+
const body = {};
|
|
9
|
+
if (update.isFirstInteraction !== undefined) {
|
|
10
|
+
body.is_first_interaction = update.isFirstInteraction;
|
|
11
|
+
}
|
|
12
|
+
if (update.shadowing !== undefined)
|
|
13
|
+
body.shadowing = update.shadowing;
|
|
14
|
+
if (update.flowThreadId !== undefined) {
|
|
15
|
+
body.flow_thread_id = update.flowThreadId;
|
|
16
|
+
}
|
|
17
|
+
if (update.custom !== undefined)
|
|
18
|
+
body.custom = update.custom;
|
|
19
|
+
if (update.webviewsCustom !== undefined) {
|
|
20
|
+
body.webviews_custom = update.webviewsCustom;
|
|
21
|
+
}
|
|
22
|
+
if (update.webchatClientSettings !== undefined) {
|
|
23
|
+
body.webchat_client_settings = update.webchatClientSettings;
|
|
24
|
+
}
|
|
25
|
+
if (update.captureUserInputNodeId !== undefined) {
|
|
26
|
+
const id = update.captureUserInputNodeId;
|
|
27
|
+
if (id === null || id === '') {
|
|
28
|
+
body.capture_user_input_node_id = null;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
body.capture_user_input_node_id = id;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return body;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Mutates `session.raw` immediately so the rest of the turn sees updates.
|
|
38
|
+
* Handles `capture_user_input_node_id` (mirror of {@link sessionUpdateToPatchBody}) and
|
|
39
|
+
* `_botonic_action` (not sent on session PATCH).
|
|
40
|
+
* For `isFirstInteraction`, also updates in-memory `is_first_interaction`; the same
|
|
41
|
+
* value is emitted by {@link sessionUpdateToPatchBody} for `PATCH …/session/`.
|
|
42
|
+
*/
|
|
43
|
+
export function applyNonPatchSessionUpdateFields(session, updates) {
|
|
44
|
+
if (updates.captureUserInputNodeId !== undefined) {
|
|
45
|
+
const id = updates.captureUserInputNodeId;
|
|
46
|
+
if (id === null || id === '') {
|
|
47
|
+
delete session.capture_user_input_node_id;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
session.capture_user_input_node_id = id;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (updates.isFirstInteraction !== undefined) {
|
|
54
|
+
session.is_first_interaction = updates.isFirstInteraction;
|
|
55
|
+
}
|
|
56
|
+
if (updates.botonicAction !== undefined) {
|
|
57
|
+
const w = session;
|
|
58
|
+
if (updates.botonicAction === null || updates.botonicAction === '') {
|
|
59
|
+
delete w._botonic_action;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
w._botonic_action = updates.botonicAction;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Maps `BotonicSessionUpdate.user` to `PATCH …/users/<user_id>/` body (ChatUserPatchSerializer keys, snake_case).
|
|
68
|
+
* Unknown keys are omitted — only serializer fields are sent.
|
|
69
|
+
*/
|
|
70
|
+
export function userUpdateToChatUserPatchBody(user) {
|
|
71
|
+
if (user === undefined)
|
|
72
|
+
return {};
|
|
73
|
+
const body = {};
|
|
74
|
+
if (user.overrideName !== undefined) {
|
|
75
|
+
body.override_name = user.overrideName;
|
|
76
|
+
}
|
|
77
|
+
if (user.locale !== undefined) {
|
|
78
|
+
body.locale = user.locale;
|
|
79
|
+
}
|
|
80
|
+
if (user.country !== undefined) {
|
|
81
|
+
body.country = user.country;
|
|
82
|
+
}
|
|
83
|
+
if (user.systemLocale !== undefined) {
|
|
84
|
+
body.system_locale = user.systemLocale;
|
|
85
|
+
}
|
|
86
|
+
if (user.extraData !== undefined) {
|
|
87
|
+
body.extra_data = user.extraData;
|
|
88
|
+
}
|
|
89
|
+
return body;
|
|
90
|
+
}
|
|
91
|
+
export class BotonicContextSessionUser {
|
|
92
|
+
constructor(rawUser, onUserUpdate) {
|
|
93
|
+
this.rawUser = rawUser;
|
|
94
|
+
this.onUserUpdate = onUserUpdate;
|
|
95
|
+
}
|
|
96
|
+
get raw() {
|
|
97
|
+
return this.rawUser;
|
|
98
|
+
}
|
|
99
|
+
get id() {
|
|
100
|
+
return this.rawUser.id;
|
|
101
|
+
}
|
|
102
|
+
get username() {
|
|
103
|
+
var _a;
|
|
104
|
+
return (_a = this.rawUser.username) !== null && _a !== void 0 ? _a : undefined;
|
|
105
|
+
}
|
|
106
|
+
get name() {
|
|
107
|
+
var _a;
|
|
108
|
+
return (_a = this.rawUser.name) !== null && _a !== void 0 ? _a : undefined;
|
|
109
|
+
}
|
|
110
|
+
get overrideName() {
|
|
111
|
+
var _a;
|
|
112
|
+
return (_a = this.rawUser.override_name) !== null && _a !== void 0 ? _a : undefined;
|
|
113
|
+
}
|
|
114
|
+
get providerId() {
|
|
115
|
+
return this.rawUser.provider_id;
|
|
116
|
+
}
|
|
117
|
+
get locale() {
|
|
118
|
+
return this.rawUser.locale;
|
|
119
|
+
}
|
|
120
|
+
set locale(v) {
|
|
121
|
+
this.rawUser.locale = v;
|
|
122
|
+
}
|
|
123
|
+
get country() {
|
|
124
|
+
return this.rawUser.country;
|
|
125
|
+
}
|
|
126
|
+
set country(v) {
|
|
127
|
+
this.rawUser.country = v;
|
|
128
|
+
}
|
|
129
|
+
get systemLocale() {
|
|
130
|
+
return this.rawUser.system_locale;
|
|
131
|
+
}
|
|
132
|
+
set systemLocale(v) {
|
|
133
|
+
this.rawUser.system_locale = v;
|
|
134
|
+
}
|
|
135
|
+
get extraData() {
|
|
136
|
+
return this.rawUser.extra_data;
|
|
137
|
+
}
|
|
138
|
+
set extraData(v) {
|
|
139
|
+
var _a;
|
|
140
|
+
this.rawUser.extra_data = v;
|
|
141
|
+
void ((_a = this.onUserUpdate) === null || _a === void 0 ? void 0 : _a.call(this, { extraData: v }));
|
|
142
|
+
}
|
|
143
|
+
get contactInfo() {
|
|
144
|
+
return this.rawUser.contact_info;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
export class BotonicContextSession {
|
|
148
|
+
constructor(sessionData) {
|
|
149
|
+
this.sessionData = sessionData;
|
|
150
|
+
}
|
|
151
|
+
setOnUpdate(cb) {
|
|
152
|
+
this.onUpdate = cb;
|
|
153
|
+
}
|
|
154
|
+
/** Replace underlying session object (e.g. after GET session from Hubtype). */
|
|
155
|
+
replaceSession(next) {
|
|
156
|
+
this.sessionData = next;
|
|
157
|
+
}
|
|
158
|
+
get raw() {
|
|
159
|
+
return this.sessionData;
|
|
160
|
+
}
|
|
161
|
+
get bot() {
|
|
162
|
+
return this.sessionData.bot;
|
|
163
|
+
}
|
|
164
|
+
get user() {
|
|
165
|
+
const notify = this.onUpdate;
|
|
166
|
+
return new BotonicContextSessionUser(this.sessionData.user, notify !== undefined
|
|
167
|
+
? updates => {
|
|
168
|
+
notify({ user: updates });
|
|
169
|
+
}
|
|
170
|
+
: undefined);
|
|
171
|
+
}
|
|
172
|
+
get organizationId() {
|
|
173
|
+
return this.sessionData.organization.id;
|
|
174
|
+
}
|
|
175
|
+
get organizationName() {
|
|
176
|
+
return this.sessionData.organization.name;
|
|
177
|
+
}
|
|
178
|
+
get isFirstInteraction() {
|
|
179
|
+
return this.sessionData.is_first_interaction;
|
|
180
|
+
}
|
|
181
|
+
set isFirstInteraction(v) {
|
|
182
|
+
this.sessionData.is_first_interaction = v;
|
|
183
|
+
}
|
|
184
|
+
get botonicAction() {
|
|
185
|
+
const w = this.sessionData;
|
|
186
|
+
const v = w._botonic_action;
|
|
187
|
+
return typeof v === 'string' ? v : undefined;
|
|
188
|
+
}
|
|
189
|
+
set botonicAction(v) {
|
|
190
|
+
const w = this.sessionData;
|
|
191
|
+
if (v === undefined || v === '') {
|
|
192
|
+
delete w._botonic_action;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
w._botonic_action = v;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
isBotonicActionRedirect() {
|
|
199
|
+
const a = this.botonicAction;
|
|
200
|
+
const prefix = `${BotonicAction.Redirect}:`;
|
|
201
|
+
return typeof a === 'string' && a.startsWith(prefix);
|
|
202
|
+
}
|
|
203
|
+
getBotonicActionPayload(action) {
|
|
204
|
+
const prefix = `${action}:`;
|
|
205
|
+
const a = this.botonicAction;
|
|
206
|
+
if (typeof a !== 'string' || !a.startsWith(prefix))
|
|
207
|
+
return undefined;
|
|
208
|
+
return a.slice(prefix.length);
|
|
209
|
+
}
|
|
210
|
+
get isTestIntegration() {
|
|
211
|
+
return this.sessionData.is_test_integration;
|
|
212
|
+
}
|
|
213
|
+
get flowThreadId() {
|
|
214
|
+
return this.sessionData.flow_thread_id;
|
|
215
|
+
}
|
|
216
|
+
get shadowing() {
|
|
217
|
+
return this.sessionData.shadowing;
|
|
218
|
+
}
|
|
219
|
+
set shadowing(v) {
|
|
220
|
+
this.sessionData.shadowing = v;
|
|
221
|
+
}
|
|
222
|
+
get hadHubtypeHandoff() {
|
|
223
|
+
return this.sessionData.had_hubtype_handoff;
|
|
224
|
+
}
|
|
225
|
+
get hubtypeCase() {
|
|
226
|
+
return this.sessionData.hubtype_case;
|
|
227
|
+
}
|
|
228
|
+
/** Convenience for legacy code paths; prefer {@link hubtypeCase}. */
|
|
229
|
+
get hubtypeCaseId() {
|
|
230
|
+
var _a;
|
|
231
|
+
return (_a = this.sessionData.hubtype_case) === null || _a === void 0 ? void 0 : _a.id;
|
|
232
|
+
}
|
|
233
|
+
get custom() {
|
|
234
|
+
return this.sessionData.custom;
|
|
235
|
+
}
|
|
236
|
+
get external() {
|
|
237
|
+
return this.sessionData.external;
|
|
238
|
+
}
|
|
239
|
+
get webviewsCustom() {
|
|
240
|
+
return this.sessionData.webviews_custom;
|
|
241
|
+
}
|
|
242
|
+
set webviewsCustom(v) {
|
|
243
|
+
this.sessionData.webviews_custom = v;
|
|
244
|
+
}
|
|
245
|
+
get webchatClientSettings() {
|
|
246
|
+
var _a;
|
|
247
|
+
return ((_a = this.sessionData.webchat_client_settings) !== null && _a !== void 0 ? _a : DEFAULT_WEBCHAT_CLIENT_SETTINGS);
|
|
248
|
+
}
|
|
249
|
+
set webchatClientSettings(v) {
|
|
250
|
+
this.sessionData.webchat_client_settings = v;
|
|
251
|
+
}
|
|
252
|
+
/** Flow Builder: node id capturing user input (`capture_user_input_node_id` in JSON). */
|
|
253
|
+
get captureUserInputNodeId() {
|
|
254
|
+
const id = this.sessionData.capture_user_input_node_id;
|
|
255
|
+
if (id == null || id === '') {
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
return id;
|
|
259
|
+
}
|
|
260
|
+
/** Channel provider (e.g. webchat, whatsapp). */
|
|
261
|
+
get provider() {
|
|
262
|
+
return this.sessionData.channel.provider;
|
|
263
|
+
}
|
|
264
|
+
get impId() {
|
|
265
|
+
return this.sessionData.channel.imp_id;
|
|
266
|
+
}
|
|
267
|
+
get unformattedPhoneNumber() {
|
|
268
|
+
var _a;
|
|
269
|
+
return (_a = this.sessionData.channel.unformatted_phone_number) !== null && _a !== void 0 ? _a : undefined;
|
|
270
|
+
}
|
|
271
|
+
isDev() {
|
|
272
|
+
return this.provider === MessagingChannel.Webchat;
|
|
273
|
+
}
|
|
274
|
+
isWebchat() {
|
|
275
|
+
return this.provider === MessagingChannel.Webchat;
|
|
276
|
+
}
|
|
277
|
+
isTelegram() {
|
|
278
|
+
return this.provider === MessagingChannel.Telegram;
|
|
279
|
+
}
|
|
280
|
+
isFacebook() {
|
|
281
|
+
return this.provider === MessagingChannel.Facebook;
|
|
282
|
+
}
|
|
283
|
+
isInstagram() {
|
|
284
|
+
return this.provider === MessagingChannel.Instagram;
|
|
285
|
+
}
|
|
286
|
+
isTwitter() {
|
|
287
|
+
return this.provider === MessagingChannel.Twitter;
|
|
288
|
+
}
|
|
289
|
+
isWhatsapp() {
|
|
290
|
+
return this.provider === MessagingChannel.Whatsapp;
|
|
291
|
+
}
|
|
292
|
+
hasFlowThreadId() {
|
|
293
|
+
const ft = this.flowThreadId;
|
|
294
|
+
return ft != null && ft !== '';
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=botonic-context-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"botonic-context-session.js","sourceRoot":"","sources":["../../../../../../../../libs/botonic/core/src/lib/server/botonic-context/botonic-context-session.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EACL,+BAA+B,GAEhC,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAqFhD;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAEtC,MAAwC;IACxC,MAAM,IAAI,GAA4B,EAAE,CAAA;IACxC,IAAI,MAAM,CAAC,kBAAkB,KAAK,SAAS,EAAE,CAAC;QAC5C,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,kBAAkB,CAAA;IACvD,CAAC;IACD,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS;QAAE,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;IACrE,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACtC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,YAAY,CAAA;IAC3C,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS;QAAE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,M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CAAC,MAAM,CAAA;IACxC,CAAC;IACD,IAAI,sBAAsB;;QACxB,OAAO,MAAA,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,wBAAwB,mCAAI,SAAS,CAAA;IACvE,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,QAAQ,KAAK,gBAAgB,CAAC,OAAO,CAAA;IACnD,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,QAAQ,KAAK,gBAAgB,CAAC,OAAO,CAAA;IACnD,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,QAAQ,KAAK,gBAAgB,CAAC,QAAQ,CAAA;IACpD,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,QAAQ,KAAK,gBAAgB,CAAC,QAAQ,CAAA;IACpD,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,KAAK,gBAAgB,CAAC,SAAS,CAAA;IACrD,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,QAAQ,KAAK,gBAAgB,CAAC,OAAO,CAAA;IACnD,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,QAAQ,KAAK,gBAAgB,CAAC,QAAQ,CAAA;IACpD,CAAC;IAED,eAAe;QACb,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,CAAA;QAC5B,OAAO,EAAE,IAAI,IAAI,IAAI,EAAE,KAAK,EAAE,CAAA;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BotonicSecrets, BotonicSettings } from '@botonic/shared';
|
|
2
|
+
export declare class BotonicContextSettings {
|
|
3
|
+
private readonly rawSettings;
|
|
4
|
+
constructor(rawSettings: BotonicSettings);
|
|
5
|
+
get raw(): BotonicSettings;
|
|
6
|
+
get hubtypeApiUrl(): string;
|
|
7
|
+
get staticUrl(): string | undefined;
|
|
8
|
+
get allSettings(): BotonicSettings;
|
|
9
|
+
}
|
|
10
|
+
export declare class BotonicContextSecrets {
|
|
11
|
+
private readonly rawSecrets;
|
|
12
|
+
constructor(rawSecrets: BotonicSecrets);
|
|
13
|
+
get raw(): BotonicSecrets;
|
|
14
|
+
get hubtypeAccessToken(): string;
|
|
15
|
+
get allSecrets(): BotonicSecrets;
|
|
16
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export class BotonicContextSettings {
|
|
2
|
+
constructor(rawSettings) {
|
|
3
|
+
this.rawSettings = rawSettings;
|
|
4
|
+
}
|
|
5
|
+
get raw() {
|
|
6
|
+
return this.rawSettings;
|
|
7
|
+
}
|
|
8
|
+
get hubtypeApiUrl() {
|
|
9
|
+
return this.rawSettings.HUBTYPE_API_URL;
|
|
10
|
+
}
|
|
11
|
+
get staticUrl() {
|
|
12
|
+
return this.rawSettings.STATIC_URL;
|
|
13
|
+
}
|
|
14
|
+
// TODO: Implement the rest getters when needed
|
|
15
|
+
get allSettings() {
|
|
16
|
+
return {
|
|
17
|
+
HUBTYPE_API_URL: this.rawSettings.HUBTYPE_API_URL,
|
|
18
|
+
FLOW_BUILDER_API_URL: this.rawSettings.FLOW_BUILDER_API_URL,
|
|
19
|
+
STATIC_URL: this.rawSettings.STATIC_URL,
|
|
20
|
+
LITELLM_API_URL: this.rawSettings.LITELLM_API_URL,
|
|
21
|
+
AZURE_OPENAI_API_BASE: this.rawSettings.AZURE_OPENAI_API_BASE,
|
|
22
|
+
AZURE_OPENAI_API_VERSION: this.rawSettings.AZURE_OPENAI_API_VERSION,
|
|
23
|
+
CUSTOM_SHORT_URL_HOST: this.rawSettings.CUSTOM_SHORT_URL_HOST,
|
|
24
|
+
custom: this.rawSettings.custom,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class BotonicContextSecrets {
|
|
29
|
+
constructor(rawSecrets) {
|
|
30
|
+
this.rawSecrets = rawSecrets;
|
|
31
|
+
}
|
|
32
|
+
get raw() {
|
|
33
|
+
return this.rawSecrets;
|
|
34
|
+
}
|
|
35
|
+
get hubtypeAccessToken() {
|
|
36
|
+
return this.rawSecrets.HUBTYPE_ACCESS_TOKEN;
|
|
37
|
+
}
|
|
38
|
+
// TODO: Implement the rest getters when needed
|
|
39
|
+
get allSecrets() {
|
|
40
|
+
return {
|
|
41
|
+
HUBTYPE_ACCESS_TOKEN: this.rawSecrets.HUBTYPE_ACCESS_TOKEN,
|
|
42
|
+
LITELLM_API_KEY: this.rawSecrets.LITELLM_API_KEY,
|
|
43
|
+
AZURE_OPENAI_API_KEY: this.rawSecrets.AZURE_OPENAI_API_KEY,
|
|
44
|
+
custom: this.rawSecrets.custom,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=botonic-context-settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"botonic-context-settings.js","sourceRoot":"","sources":["../../../../../../../../libs/botonic/core/src/lib/server/botonic-context/botonic-context-settings.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,sBAAsB;IACjC,YAA6B,WAA4B;QAA5B,gBAAW,GAAX,WAAW,CAAiB;IAAG,CAAC;IAE7D,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,WAAW,CAAA;IACzB,CAAC;IAED,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,WAAW,CAAC,eAAe,CAAA;IACzC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAA;IACpC,CAAC;IAED,+CAA+C;IAE/C,IAAI,WAAW;QACb,OAAO;YACL,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC,eAAe;YACjD,oBAAoB,EAAE,IAAI,CAAC,WAAW,CAAC,oBAAoB;YAC3D,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,UAAU;YACvC,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC,eAAe;YACjD,qBAAqB,EAAE,IAAI,CAAC,WAAW,CAAC,qBAAqB;YAC7D,wBAAwB,EAAE,IAAI,CAAC,WAAW,CAAC,wBAAwB;YACnE,qBAAqB,EAAE,IAAI,CAAC,WAAW,CAAC,qBAAqB;YAC7D,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM;SAChC,CAAA;IACH,CAAC;CACF;AAED,MAAM,OAAO,qBAAqB;IAChC,YAA6B,UAA0B;QAA1B,eAAU,GAAV,UAAU,CAAgB;IAAG,CAAC;IAE3D,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAA;IAC7C,CAAC;IAED,+CAA+C;IAE/C,IAAI,UAAU;QACZ,OAAO;YACL,oBAAoB,EAAE,IAAI,CAAC,UAAU,CAAC,oBAAoB;YAC1D,eAAe,EAAE,IAAI,CAAC,UAAU,CAAC,eAAe;YAChD,oBAAoB,EAAE,IAAI,CAAC,UAAU,CAAC,oBAAoB;YAC1D,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM;SAC/B,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { UserExtraData } from '@botonic/shared';
|
|
2
|
+
import type { HubtypeApiService } from '../../services/hubtype-api-service';
|
|
3
|
+
import { BotServerMessage } from '../bot-server-message';
|
|
4
|
+
import { BotonicContextInput } from './botonic-context-input';
|
|
5
|
+
import type { BotonicContextSession, BotonicSessionUpdate } from './botonic-context-session';
|
|
6
|
+
import type { BotonicContextSecrets, BotonicContextSettings } from './botonic-context-settings';
|
|
7
|
+
import type { ActionResponse, ResolvedPlugins, SendMessagesOptions, TypingMode } from './types';
|
|
8
|
+
/** Result of creating input/session from raw lambda request (used by BotonicContextFactory). */
|
|
9
|
+
export interface BotonicContextType<TExtraData extends UserExtraData = UserExtraData> {
|
|
10
|
+
input: BotonicContextInput;
|
|
11
|
+
session: BotonicContextSession<TExtraData>;
|
|
12
|
+
settings: BotonicContextSettings;
|
|
13
|
+
secrets: BotonicContextSecrets;
|
|
14
|
+
}
|
|
15
|
+
/** Options for handoff to human agent. */
|
|
16
|
+
export interface HandoffOptions {
|
|
17
|
+
queue?: string;
|
|
18
|
+
on_finish?: string;
|
|
19
|
+
agent_email?: string;
|
|
20
|
+
agent_id?: string;
|
|
21
|
+
case_info?: string;
|
|
22
|
+
note?: string;
|
|
23
|
+
shadowing?: boolean;
|
|
24
|
+
auto_idle_message?: string;
|
|
25
|
+
force_assign_if_not_available?: boolean;
|
|
26
|
+
auto_assign_on_waiting?: boolean;
|
|
27
|
+
case_extra_data?: Record<string, unknown>;
|
|
28
|
+
bot_event?: {
|
|
29
|
+
flow_id: string;
|
|
30
|
+
flow_name: string;
|
|
31
|
+
flow_node_id: string;
|
|
32
|
+
flow_node_content_id: string;
|
|
33
|
+
};
|
|
34
|
+
subscribe_helpdesk_events?: string[];
|
|
35
|
+
}
|
|
36
|
+
/** Full execution context with input, session, and hubtype service methods. */
|
|
37
|
+
export declare class BotonicContext<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData extends UserExtraData = UserExtraData> implements BotonicContextType<TExtraData> {
|
|
38
|
+
private readonly hubtypeService;
|
|
39
|
+
input: BotonicContextInput;
|
|
40
|
+
session: BotonicContextSession<TExtraData>;
|
|
41
|
+
readonly settings: BotonicContextSettings;
|
|
42
|
+
readonly secrets: BotonicContextSecrets;
|
|
43
|
+
defaultDelay: number;
|
|
44
|
+
defaultTyping: number;
|
|
45
|
+
defaultTypingMode: TypingMode;
|
|
46
|
+
params: Record<string, string>;
|
|
47
|
+
plugins: TPlugins;
|
|
48
|
+
response?: ActionResponse;
|
|
49
|
+
constructor(hubtypeService: HubtypeApiService, base: BotonicContextType<TExtraData>, plugins: TPlugins, defaultTyping: number, defaultDelay: number, defaultTypingMode: TypingMode, response?: ActionResponse);
|
|
50
|
+
/**
|
|
51
|
+
* Session user setters notify via sync callback; `updateBotSession` is async.
|
|
52
|
+
* Attach `.catch` so fetch/network failures are logged instead of unhandled rejections.
|
|
53
|
+
*/
|
|
54
|
+
private bindSessionUpdateCallback;
|
|
55
|
+
sendMessages: (messages: BotServerMessage[], options?: SendMessagesOptions) => Promise<unknown>;
|
|
56
|
+
doHandoff: (handoffOptions?: HandoffOptions) => Promise<unknown>;
|
|
57
|
+
getBotSession: () => Promise<import("@botonic/shared").BotonicSession<UserExtraData>>;
|
|
58
|
+
updateBotSession: (updates: BotonicSessionUpdate<TExtraData>) => Promise<void>;
|
|
59
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { injectTypingEvents } from './send-messages-utils';
|
|
3
|
+
/** Full execution context with input, session, and hubtype service methods. */
|
|
4
|
+
export class BotonicContext {
|
|
5
|
+
constructor(hubtypeService, base, plugins, defaultTyping, defaultDelay, defaultTypingMode, response) {
|
|
6
|
+
this.hubtypeService = hubtypeService;
|
|
7
|
+
this.sendMessages = (messages, options) => __awaiter(this, void 0, void 0, function* () {
|
|
8
|
+
var _a;
|
|
9
|
+
const typingMode = (_a = options === null || options === void 0 ? void 0 : options.typingMode) !== null && _a !== void 0 ? _a : this.defaultTypingMode;
|
|
10
|
+
return this.hubtypeService.sendMessages(this, injectTypingEvents(messages, typingMode));
|
|
11
|
+
});
|
|
12
|
+
this.doHandoff = (handoffOptions) => __awaiter(this, void 0, void 0, function* () { return this.hubtypeService.doHandoff(this, handoffOptions); });
|
|
13
|
+
this.getBotSession = () => __awaiter(this, void 0, void 0, function* () { return this.hubtypeService.getBotSession(this); });
|
|
14
|
+
this.updateBotSession = (updates) => __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
yield this.hubtypeService.updateBotSession(this, updates);
|
|
16
|
+
this.bindSessionUpdateCallback();
|
|
17
|
+
});
|
|
18
|
+
this.input = base.input;
|
|
19
|
+
this.session = base.session;
|
|
20
|
+
this.settings = base.settings;
|
|
21
|
+
this.secrets = base.secrets;
|
|
22
|
+
this.params = {};
|
|
23
|
+
this.plugins = plugins;
|
|
24
|
+
this.defaultTyping = defaultTyping;
|
|
25
|
+
this.defaultDelay = defaultDelay;
|
|
26
|
+
this.defaultTypingMode = defaultTypingMode;
|
|
27
|
+
this.response = response;
|
|
28
|
+
this.bindSessionUpdateCallback();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Session user setters notify via sync callback; `updateBotSession` is async.
|
|
32
|
+
* Attach `.catch` so fetch/network failures are logged instead of unhandled rejections.
|
|
33
|
+
*/
|
|
34
|
+
bindSessionUpdateCallback() {
|
|
35
|
+
this.session.setOnUpdate(u => {
|
|
36
|
+
void this.updateBotSession(u).catch((err) => {
|
|
37
|
+
console.error('[BotonicContext] updateBotSession failed (session sync)', err);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=botonic-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"botonic-context.js","sourceRoot":"","sources":["../../../../../../../../libs/botonic/core/src/lib/server/botonic-context/botonic-context.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAwC1D,+EAA+E;AAC/E,MAAM,OAAO,cAAc;IAezB,YACmB,cAAiC,EAClD,IAAoC,EACpC,OAAiB,EACjB,aAAqB,EACrB,YAAoB,EACpB,iBAA6B,EAC7B,QAAyB;QANR,mBAAc,GAAd,cAAc,CAAmB;QAoCpD,iBAAY,GAAG,CACb,QAA4B,EAC5B,OAA6B,EAC7B,EAAE;;YACF,MAAM,UAAU,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,mCAAI,IAAI,CAAC,iBAAiB,CAAA;YAChE,OAAO,IAAI,CAAC,cAAc,CAAC,YAAY,CACrC,IAAI,EACJ,kBAAkB,CAAC,QAAQ,EAAE,UAAU,CAAC,CACzC,CAAA;QACH,CAAC,CAAA,CAAA;QACD,cAAS,GAAG,CAAO,cAA+B,EAAE,EAAE,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