@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.
Files changed (65) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/package.json +7 -2
  3. package/src/index.d.ts +2 -0
  4. package/src/index.js +2 -0
  5. package/src/index.js.map +1 -1
  6. package/src/lib/actions/update-webchat-client-settings.d.ts +1 -1
  7. package/src/lib/actions/update-webchat-client-settings.js +2 -1
  8. package/src/lib/actions/update-webchat-client-settings.js.map +1 -1
  9. package/src/lib/core-bot/index.d.ts +2 -1
  10. package/src/lib/core-bot/index.js +3 -1
  11. package/src/lib/core-bot/index.js.map +1 -1
  12. package/src/lib/plugins/index.d.ts +1 -1
  13. package/src/lib/plugins/index.js +1 -1
  14. package/src/lib/plugins/index.js.map +1 -1
  15. package/src/lib/routes/router.d.ts +1 -1
  16. package/src/lib/routes/router.js.map +1 -1
  17. package/src/lib/routes/types.d.ts +4 -1
  18. package/src/lib/server/bot-server-message.d.ts +71 -0
  19. package/src/lib/server/bot-server-message.js +111 -0
  20. package/src/lib/server/bot-server-message.js.map +1 -0
  21. package/src/lib/server/botonic-context/botonic-action.d.ts +10 -0
  22. package/src/lib/server/botonic-context/botonic-action.js +9 -0
  23. package/src/lib/server/botonic-context/botonic-action.js.map +1 -0
  24. package/src/lib/server/botonic-context/botonic-context-input.d.ts +96 -0
  25. package/src/lib/server/botonic-context/botonic-context-input.js +123 -0
  26. package/src/lib/server/botonic-context/botonic-context-input.js.map +1 -0
  27. package/src/lib/server/botonic-context/botonic-context-session.d.ts +159 -0
  28. package/src/lib/server/botonic-context/botonic-context-session.js +297 -0
  29. package/src/lib/server/botonic-context/botonic-context-session.js.map +1 -0
  30. package/src/lib/server/botonic-context/botonic-context-settings.d.ts +16 -0
  31. package/src/lib/server/botonic-context/botonic-context-settings.js +48 -0
  32. package/src/lib/server/botonic-context/botonic-context-settings.js.map +1 -0
  33. package/src/lib/server/botonic-context/botonic-context.d.ts +59 -0
  34. package/src/lib/server/botonic-context/botonic-context.js +42 -0
  35. package/src/lib/server/botonic-context/botonic-context.js.map +1 -0
  36. package/src/lib/server/botonic-context/botonic-session-patch-slice.d.ts +30 -0
  37. package/src/lib/server/botonic-context/botonic-session-patch-slice.js +80 -0
  38. package/src/lib/server/botonic-context/botonic-session-patch-slice.js.map +1 -0
  39. package/src/lib/server/botonic-context/factory.d.ts +29 -0
  40. package/src/lib/server/botonic-context/factory.js +31 -0
  41. package/src/lib/server/botonic-context/factory.js.map +1 -0
  42. package/src/lib/server/botonic-context/index.d.ts +9 -0
  43. package/src/lib/server/botonic-context/index.js +10 -0
  44. package/src/lib/server/botonic-context/index.js.map +1 -0
  45. package/src/lib/server/botonic-context/send-messages-utils.d.ts +3 -0
  46. package/src/lib/server/botonic-context/send-messages-utils.js +33 -0
  47. package/src/lib/server/botonic-context/send-messages-utils.js.map +1 -0
  48. package/src/lib/server/botonic-context/types.d.ts +24 -0
  49. package/src/lib/server/botonic-context/types.js +6 -0
  50. package/src/lib/server/botonic-context/types.js.map +1 -0
  51. package/src/lib/server/factory.d.ts +182 -0
  52. package/src/lib/server/factory.js +209 -0
  53. package/src/lib/server/factory.js.map +1 -0
  54. package/src/lib/server/index.d.ts +3 -0
  55. package/src/lib/server/index.js +4 -0
  56. package/src/lib/server/index.js.map +1 -0
  57. package/src/lib/services/hubtype-api-service.d.ts +13 -0
  58. package/src/lib/services/hubtype-api-service.js +67 -0
  59. package/src/lib/services/hubtype-api-service.js.map +1 -0
  60. package/src/lib/services/hubtype-external-api-client.d.ts +22 -0
  61. package/src/lib/services/hubtype-external-api-client.js +111 -0
  62. package/src/lib/services/hubtype-external-api-client.js.map +1 -0
  63. package/src/lib/services/index.d.ts +2 -0
  64. package/src/lib/services/index.js +3 -0
  65. package/src/lib/services/index.js.map +1 -0
@@ -0,0 +1,30 @@
1
+ /**
2
+ * v2 `PATCH …/session/` success body: stored slice only (not full BotonicSessionBuilder JSON).
3
+ * @see openspec/specs/BE-botonic-v2-botonic-session-endpoints/spec.md
4
+ */
5
+ import type { BotonicSession, BotonicSessionUser, UserExtraData } from '@botonic/shared';
6
+ import { WebchatClientSettings } from '@botonic/shared';
7
+ export interface BotonicSessionPatchSlice {
8
+ shadowing?: boolean;
9
+ flow_thread_id?: string;
10
+ is_first_interaction?: boolean;
11
+ custom?: Record<string, any>;
12
+ webviews_custom?: Record<string, any>;
13
+ webchat_client_settings?: WebchatClientSettings;
14
+ /** Flow Builder capture node id (`null` clears). */
15
+ capture_user_input_node_id?: string | null;
16
+ }
17
+ /**
18
+ * Mutates `session` with fields from the PATCH session response (slice), deep-merging object fields
19
+ * to mirror server `deep_merge` behavior for nested dicts.
20
+ */
21
+ export declare function mergeBotonicSessionPatchSlice<TExtraData extends UserExtraData = UserExtraData>(session: BotonicSession<TExtraData>, slice: BotonicSessionPatchSlice): void;
22
+ /** `PATCH …/users/<user_id>/` 200 body (echo slice). */
23
+ export interface ChatUserPatchResponse {
24
+ override_name?: string;
25
+ locale?: string;
26
+ country?: string;
27
+ system_locale?: string;
28
+ extra_data?: UserExtraData;
29
+ }
30
+ export declare function mergeChatUserPatchResponseIntoSessionUser<TExtraData extends UserExtraData = UserExtraData>(user: BotonicSessionUser<TExtraData>, response: ChatUserPatchResponse): void;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * v2 `PATCH …/session/` success body: stored slice only (not full BotonicSessionBuilder JSON).
3
+ * @see openspec/specs/BE-botonic-v2-botonic-session-endpoints/spec.md
4
+ */
5
+ import { mergeWebchatClientSettings, WebchatClientSettings, } from '@botonic/shared';
6
+ function isPlainObject(v) {
7
+ return typeof v === 'object' && v !== null && !Array.isArray(v);
8
+ }
9
+ function deepMergeRecords(target, patch) {
10
+ const merged = Object.assign({}, target);
11
+ for (const [key, patchValue] of Object.entries(patch)) {
12
+ const targetValue = merged[key];
13
+ if (isPlainObject(patchValue) && isPlainObject(targetValue)) {
14
+ merged[key] = deepMergeRecords(targetValue, patchValue);
15
+ }
16
+ else {
17
+ merged[key] = patchValue;
18
+ }
19
+ }
20
+ return merged;
21
+ }
22
+ /**
23
+ * Mutates `session` with fields from the PATCH session response (slice), deep-merging object fields
24
+ * to mirror server `deep_merge` behavior for nested dicts.
25
+ */
26
+ export function mergeBotonicSessionPatchSlice(session, slice) {
27
+ var _a, _b, _c;
28
+ if (slice.shadowing !== undefined)
29
+ session.shadowing = slice.shadowing;
30
+ if (slice.flow_thread_id !== undefined)
31
+ session.flow_thread_id = slice.flow_thread_id;
32
+ if (slice.is_first_interaction !== undefined) {
33
+ session.is_first_interaction = slice.is_first_interaction;
34
+ }
35
+ if (slice.custom !== undefined) {
36
+ session.custom = deepMergeRecords(((_a = session.custom) !== null && _a !== void 0 ? _a : {}), slice.custom);
37
+ }
38
+ if (slice.webviews_custom !== undefined) {
39
+ session.webviews_custom = deepMergeRecords(((_b = session.webviews_custom) !== null && _b !== void 0 ? _b : {}), slice.webviews_custom);
40
+ }
41
+ if (slice.webchat_client_settings !== undefined) {
42
+ const current = (_c = session.webchat_client_settings) !== null && _c !== void 0 ? _c : new WebchatClientSettings();
43
+ const incoming = slice.webchat_client_settings instanceof WebchatClientSettings
44
+ ? slice.webchat_client_settings
45
+ : new WebchatClientSettings(slice.webchat_client_settings);
46
+ session.webchat_client_settings = mergeWebchatClientSettings(current, incoming);
47
+ }
48
+ if (slice.capture_user_input_node_id !== undefined) {
49
+ const id = slice.capture_user_input_node_id;
50
+ if (id === null || id === '') {
51
+ delete session.capture_user_input_node_id;
52
+ }
53
+ else {
54
+ session.capture_user_input_node_id = id;
55
+ }
56
+ }
57
+ }
58
+ export function mergeChatUserPatchResponseIntoSessionUser(user, response) {
59
+ if (response.override_name !== undefined) {
60
+ user.override_name = response.override_name;
61
+ }
62
+ if (response.locale !== undefined) {
63
+ user.locale = response.locale;
64
+ }
65
+ if (response.country !== undefined) {
66
+ user.country = response.country;
67
+ }
68
+ if (response.system_locale !== undefined) {
69
+ user.system_locale = response.system_locale;
70
+ }
71
+ if (response.extra_data !== undefined) {
72
+ if (response.extra_data === null) {
73
+ user.extra_data = undefined;
74
+ }
75
+ else {
76
+ user.extra_data = response.extra_data;
77
+ }
78
+ }
79
+ }
80
+ //# sourceMappingURL=botonic-session-patch-slice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"botonic-session-patch-slice.js","sourceRoot":"","sources":["../../../../../../../../libs/botonic/core/src/lib/server/botonic-context/botonic-session-patch-slice.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,29 @@
1
+ import type { BotonicSession, UserExtraData } from '@botonic/shared';
2
+ import type { BotonicSecrets, BotonicSettings } from '@botonic/shared';
3
+ import type { HubtypeApiService } from '../../services/hubtype-api-service';
4
+ import type { BotonicContextType } from './botonic-context';
5
+ import { BotonicContext } from './botonic-context';
6
+ import type { BotonicRequestInput } from './botonic-context-input';
7
+ import type { ResolvedPlugins, TypingMode } from './types';
8
+ /** Bot request after parsing the Hubtype v2 Lambda event (typed input + session + settings + secrets). */
9
+ export interface BotonicRequest<TExtraData extends UserExtraData = UserExtraData> {
10
+ input: BotonicRequestInput;
11
+ session: BotonicSession<TExtraData>;
12
+ settings: BotonicSettings;
13
+ secrets: BotonicSecrets;
14
+ }
15
+ /**
16
+ * Factory that creates BotonicContext from raw lambda request.
17
+ * Injects hubtypeService so the context has working sendMessages, doHandoff, etc.
18
+ */
19
+ export declare class BotonicContextFactory<TPlugins extends ResolvedPlugins = ResolvedPlugins> {
20
+ private readonly hubtypeService;
21
+ private readonly plugins;
22
+ private readonly defaultTyping;
23
+ private readonly defaultDelay;
24
+ private readonly defaultTypingMode;
25
+ constructor(hubtypeService: HubtypeApiService, plugins: TPlugins, defaultTyping: number, defaultDelay: number, defaultTypingMode?: TypingMode);
26
+ /** Creates input, session, settings, and secrets from a {@link BotonicRequest}. */
27
+ static from<TExtraData extends UserExtraData = UserExtraData>(raw: BotonicRequest<TExtraData>): BotonicContextType<TExtraData>;
28
+ create<TExtraData extends UserExtraData = UserExtraData>(raw: BotonicRequest<TExtraData>): BotonicContext<TPlugins, TExtraData>;
29
+ }
@@ -0,0 +1,31 @@
1
+ import { BotonicContext } from './botonic-context';
2
+ import { BotonicContextInput } from './botonic-context-input';
3
+ import { BotonicContextSession } from './botonic-context-session';
4
+ import { BotonicContextSecrets, BotonicContextSettings, } from './botonic-context-settings';
5
+ /**
6
+ * Factory that creates BotonicContext from raw lambda request.
7
+ * Injects hubtypeService so the context has working sendMessages, doHandoff, etc.
8
+ */
9
+ export class BotonicContextFactory {
10
+ constructor(hubtypeService, plugins, defaultTyping, defaultDelay, defaultTypingMode = 'inBetweenTyping') {
11
+ this.hubtypeService = hubtypeService;
12
+ this.plugins = plugins;
13
+ this.defaultTyping = defaultTyping;
14
+ this.defaultDelay = defaultDelay;
15
+ this.defaultTypingMode = defaultTypingMode;
16
+ }
17
+ /** Creates input, session, settings, and secrets from a {@link BotonicRequest}. */
18
+ static from(raw) {
19
+ return {
20
+ input: new BotonicContextInput(raw.input),
21
+ session: new BotonicContextSession(raw.session),
22
+ settings: new BotonicContextSettings(raw.settings),
23
+ secrets: new BotonicContextSecrets(raw.secrets),
24
+ };
25
+ }
26
+ create(raw) {
27
+ const base = BotonicContextFactory.from(raw);
28
+ return new BotonicContext(this.hubtypeService, base, this.plugins, this.defaultTyping, this.defaultDelay, this.defaultTypingMode);
29
+ }
30
+ }
31
+ //# sourceMappingURL=factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../../../../libs/botonic/core/src/lib/server/botonic-context/factory.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,4BAA4B,CAAA;AAanC;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IAGhC,YACmB,cAAiC,EACjC,OAAiB,EACjB,aAAqB,EACrB,YAAoB,EACpB,oBAAgC,iBAAiB;QAJjD,mBAAc,GAAd,cAAc,CAAmB;QACjC,YAAO,GAAP,OAAO,CAAU;QACjB,kBAAa,GAAb,aAAa,CAAQ;QACrB,iBAAY,GAAZ,YAAY,CAAQ;QACpB,sBAAiB,GAAjB,iBAAiB,CAAgC;IACjE,CAAC;IAEJ,mFAAmF;IACnF,MAAM,CAAC,IAAI,CACT,GAA+B;QAE/B,OAAO;YACL,KAAK,EAAE,IAAI,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC;YACzC,OAAO,EAAE,IAAI,qBAAqB,CAAa,GAAG,CAAC,OAAO,CAAC;YAC3D,QAAQ,EAAE,IAAI,sBAAsB,CAAC,GAAG,CAAC,QAAQ,CAAC;YAClD,OAAO,EAAE,IAAI,qBAAqB,CAAC,GAAG,CAAC,OAAO,CAAC;SAChD,CAAA;IACH,CAAC;IAED,MAAM,CACJ,GAA+B;QAE/B,MAAM,IAAI,GAAG,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC5C,OAAO,IAAI,cAAc,CACvB,IAAI,CAAC,cAAc,EACnB,IAAI,EACJ,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,iBAAiB,CACvB,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ export * from './botonic-action';
2
+ export * from './botonic-context';
3
+ export * from './botonic-context-input';
4
+ export * from './botonic-context-session';
5
+ export * from './botonic-context-settings';
6
+ export * from './botonic-session-patch-slice';
7
+ export * from './factory';
8
+ export * from './send-messages-utils';
9
+ export * from './types';
@@ -0,0 +1,10 @@
1
+ export * from './botonic-action';
2
+ export * from './botonic-context';
3
+ export * from './botonic-context-input';
4
+ export * from './botonic-context-session';
5
+ export * from './botonic-context-settings';
6
+ export * from './botonic-session-patch-slice';
7
+ export * from './factory';
8
+ export * from './send-messages-utils';
9
+ export * from './types';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../libs/botonic/core/src/lib/server/botonic-context/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CAAA;AACzC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,WAAW,CAAA;AACzB,cAAc,uBAAuB,CAAA;AACrC,cAAc,SAAS,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { BotServerMessage } from '../bot-server-message';
2
+ import type { TypingMode } from './types';
3
+ export declare function injectTypingEvents(messages: BotServerMessage[], mode: TypingMode | false | undefined): BotServerMessage[];
@@ -0,0 +1,33 @@
1
+ import { TypingEventName } from '@botonic/shared';
2
+ import { BotServerMessageFactory } from '../factory';
3
+ const DEFAULT_TYPING_DELAY = 1;
4
+ function typingEvent() {
5
+ return BotServerMessageFactory.createTypingEvent({
6
+ eventName: TypingEventName.TypingOn,
7
+ });
8
+ }
9
+ function withDefaultDelay(msg) {
10
+ if (msg.delay !== undefined)
11
+ return msg;
12
+ const clone = Object.create(Object.getPrototypeOf(msg));
13
+ return Object.assign(clone, msg, { delay: DEFAULT_TYPING_DELAY });
14
+ }
15
+ export function injectTypingEvents(messages, mode) {
16
+ if (!mode || messages.length === 0)
17
+ return messages;
18
+ if (mode === 'onlyFirst') {
19
+ const [first, ...rest] = messages;
20
+ return [typingEvent(), withDefaultDelay(first), ...rest];
21
+ }
22
+ return messages.reduce((acc, msg, index) => {
23
+ if (index > 0) {
24
+ acc.push(typingEvent());
25
+ acc.push(withDefaultDelay(msg));
26
+ }
27
+ else {
28
+ acc.push(msg);
29
+ }
30
+ return acc;
31
+ }, []);
32
+ }
33
+ //# sourceMappingURL=send-messages-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-messages-utils.js","sourceRoot":"","sources":["../../../../../../../../libs/botonic/core/src/lib/server/botonic-context/send-messages-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAGjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAGpD,MAAM,oBAAoB,GAAG,CAAC,CAAA;AAE9B,SAAS,WAAW;IAClB,OAAO,uBAAuB,CAAC,iBAAiB,CAAC;QAC/C,SAAS,EAAE,eAAe,CAAC,QAAQ;KACpC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,gBAAgB,CAA6B,GAAM;IAC1D,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,GAAG,CAAA;IACvC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAM,CAAA;IAC5D,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAAC,CAAA;AACnE,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,QAA4B,EAC5B,IAAoC;IAEpC,IAAI,CAAC,IAAI,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAA;IAEnD,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;QACzB,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAA;QACjC,OAAO,CAAC,WAAW,EAAE,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAA;IAC1D,CAAC;IAED,OAAO,QAAQ,CAAC,MAAM,CAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QAC7D,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACd,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAA;YACvB,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAA;QACjC,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACf,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { BotonicContext } from './botonic-context';
2
+ export type TypingMode = 'onlyFirst' | 'inBetweenTyping';
3
+ export interface SendMessagesOptions {
4
+ typingMode?: TypingMode | false;
5
+ }
6
+ export interface ActionResponse {
7
+ status: number;
8
+ response: string;
9
+ }
10
+ export type Action = (botonicContext: BotonicContext) => Promise<ActionResponse>;
11
+ export interface Plugin {
12
+ pre?(request: BotonicContext): void | Promise<void>;
13
+ post?(request: BotonicContext): void | Promise<void>;
14
+ }
15
+ export type ResolvedPlugins = Record<string, Plugin>;
16
+ export interface RunPluginArgs {
17
+ botonicContext: BotonicContext;
18
+ mode: PluginMode;
19
+ response?: ActionResponse;
20
+ }
21
+ export declare enum PluginMode {
22
+ PRE = "pre",
23
+ POST = "post"
24
+ }
@@ -0,0 +1,6 @@
1
+ export var PluginMode;
2
+ (function (PluginMode) {
3
+ PluginMode["PRE"] = "pre";
4
+ PluginMode["POST"] = "post";
5
+ })(PluginMode || (PluginMode = {}));
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../../libs/botonic/core/src/lib/server/botonic-context/types.ts"],"names":[],"mappings":"AA4BA,MAAM,CAAN,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,yBAAW,CAAA;IACX,2BAAa,CAAA;AACf,CAAC,EAHW,UAAU,KAAV,UAAU,QAGrB"}
@@ -0,0 +1,182 @@
1
+ import type { WebchatOutputRatingButton, WebchatOutputRatingRatingType } from '@botonic/shared';
2
+ import { BotMessageMetadata } from '@botonic/shared';
3
+ import { BotonicButtonContent, BotonicCarouselElement, TypingEventName } from '@botonic/shared';
4
+ import { WebchatClientSettings } from '@botonic/shared';
5
+ import { WhatsappButtonListSection, WhatsappHeaderType, WhatsappMediaCarouselCard, WhatsappProductCarouselCard, WhatsappProductListSection, WhatsappTemplateComponent } from '@botonic/shared';
6
+ import { BotServerMessageAudio, BotServerMessageButtonMessage, BotServerMessageCarousel, BotServerMessageCustom, BotServerMessageDocument, BotServerMessageImage, BotServerMessageLocation, BotServerMessageText, BotServerMessageTypingEvent, BotServerMessageVideo, BotServerMessageWebchatClientSettings, BotServerMessageWhatsappButtonList, BotServerMessageWhatsappCatalog, BotServerMessageWhatsappCTAUrlButton, BotServerMessageWhatsappMediaCarousel, BotServerMessageWhatsappProduct, BotServerMessageWhatsappProductCarousel, BotServerMessageWhatsappProductList, BotServerMessageWhatsappTemplate } from './bot-server-message';
7
+ import { BotonicContext } from './botonic-context';
8
+ interface WebviewButtonParams {
9
+ title: string;
10
+ webview: string;
11
+ params?: Record<string, string>;
12
+ }
13
+ export declare class BotServerMessageFactory {
14
+ static createText({ text, payload, metadata, }: {
15
+ text: string;
16
+ payload?: string;
17
+ metadata?: BotMessageMetadata;
18
+ }): BotServerMessageText;
19
+ static createAudio({ attachmentUrl, attachmentContent, caption, fileInfo, metadata, }: {
20
+ attachmentUrl: string;
21
+ attachmentContent?: string;
22
+ caption?: string;
23
+ fileInfo?: Record<string, unknown>;
24
+ metadata?: BotMessageMetadata;
25
+ }): BotServerMessageAudio;
26
+ static createImage({ attachmentUrl, attachmentContent, caption, fileInfo, metadata, }: {
27
+ attachmentUrl: string;
28
+ attachmentContent?: string;
29
+ caption?: string;
30
+ fileInfo?: Record<string, unknown>;
31
+ metadata?: BotMessageMetadata;
32
+ }): BotServerMessageImage;
33
+ static createVideo({ attachmentUrl, attachmentContent, caption, fileInfo, metadata, }: {
34
+ attachmentUrl: string;
35
+ attachmentContent?: string;
36
+ caption?: string;
37
+ fileInfo?: Record<string, unknown>;
38
+ metadata?: BotMessageMetadata;
39
+ }): BotServerMessageVideo;
40
+ static createDocument({ attachmentUrl, attachmentContent, caption, fileInfo, metadata, }: {
41
+ attachmentUrl: string;
42
+ attachmentContent?: string;
43
+ caption?: string;
44
+ fileInfo?: Record<string, unknown>;
45
+ metadata?: BotMessageMetadata;
46
+ }): BotServerMessageDocument;
47
+ static createLocation({ latitude, longitude, title, address, metadata, }: {
48
+ latitude: number;
49
+ longitude: number;
50
+ title?: string;
51
+ address?: string;
52
+ metadata?: BotMessageMetadata;
53
+ }): BotServerMessageLocation;
54
+ static createButtonMessage({ text, buttons, metadata, }: {
55
+ text: string;
56
+ buttons: BotonicButtonContent[];
57
+ metadata?: BotMessageMetadata;
58
+ }): BotServerMessageButtonMessage;
59
+ static createCarousel({ elements, text, metadata, }: {
60
+ elements: BotonicCarouselElement[];
61
+ text?: string;
62
+ metadata?: BotMessageMetadata;
63
+ }): BotServerMessageCarousel;
64
+ static createCustom({ name, props, metadata, }: {
65
+ name: string;
66
+ props: Record<string, unknown>;
67
+ metadata?: BotMessageMetadata;
68
+ }): BotServerMessageCustom;
69
+ /**
70
+ * Built-in webchat rating custom message (see {@link WEBCHAT_OUTPUT_RATING}).
71
+ * Callers must supply `payloads` — one postback per option, low → high (aligned with star/smiley order).
72
+ */
73
+ static createRating({ messageText, buttonText, ratingType, payloads, metadata, }: {
74
+ messageText: string;
75
+ buttonText: string;
76
+ ratingType: WebchatOutputRatingRatingType;
77
+ /** One entry per rating option; order does not matter — the client looks up by `value`. */
78
+ payloads?: WebchatOutputRatingButton[];
79
+ metadata?: BotMessageMetadata;
80
+ }): BotServerMessageCustom;
81
+ static createTypingEvent({ eventName, metadata, }: {
82
+ eventName: TypingEventName;
83
+ metadata?: BotMessageMetadata;
84
+ }): BotServerMessageTypingEvent;
85
+ /** Payload type `webchat_client_settings` for Hubtype `send_messages` (v2 bots). */
86
+ static createWebchatClientSettings({ settings, metadata, }: {
87
+ settings: Partial<WebchatClientSettings> | WebchatClientSettings;
88
+ metadata?: BotMessageMetadata;
89
+ }): BotServerMessageWebchatClientSettings;
90
+ /**
91
+ * Creates a postback button that sends a payload when clicked
92
+ */
93
+ static createPostbackButton({ title, payload, }: {
94
+ title: string;
95
+ payload: string;
96
+ }): BotonicButtonContent;
97
+ /**
98
+ * Creates a URL button that opens a link in the browser
99
+ */
100
+ static createUrlButton({ title, url, }: {
101
+ title: string;
102
+ url: string;
103
+ }): BotonicButtonContent;
104
+ /**
105
+ * Creates a webview button that opens a URL in a webview.
106
+ * Uses `settings.STATIC_URL` (Lambda settings), not `process.env`.
107
+ */
108
+ static createWebviewButton(webviewButtonParams: WebviewButtonParams, botonicContext: BotonicContext): BotonicButtonContent;
109
+ /**
110
+ * Helper method to create a carousel element
111
+ * This simplifies carousel element creation
112
+ */
113
+ static createCarouselElement({ title, subtitle, image, buttons, }: {
114
+ title: string;
115
+ subtitle: string;
116
+ image: string;
117
+ buttons: BotonicButtonContent[];
118
+ }): BotonicCarouselElement;
119
+ static createWhatsappButtonList({ header, body, footer, button, sections, metadata, }: {
120
+ header?: string;
121
+ body: string;
122
+ footer?: string;
123
+ button: string;
124
+ sections: WhatsappButtonListSection[];
125
+ metadata?: BotMessageMetadata;
126
+ }): BotServerMessageWhatsappButtonList;
127
+ static createWhatsappCTAUrlButton({ headerType, header, headerImage, headerDocument, headerVideo, body, url, displayText, footer, metadata, }: {
128
+ headerType?: WhatsappHeaderType;
129
+ header?: string;
130
+ headerImage?: string;
131
+ headerDocument?: string;
132
+ headerVideo?: string;
133
+ body: string;
134
+ url: string;
135
+ displayText: string;
136
+ footer?: string;
137
+ metadata?: BotMessageMetadata;
138
+ }): BotServerMessageWhatsappCTAUrlButton;
139
+ static createWhatsappCatalog({ body, footer, thumbnailProductId, metadata, }: {
140
+ body: string;
141
+ footer?: string;
142
+ thumbnailProductId?: string;
143
+ metadata?: BotMessageMetadata;
144
+ }): BotServerMessageWhatsappCatalog;
145
+ static createWhatsappProduct({ body, catalogId, productId, footer, metadata, }: {
146
+ body: string;
147
+ catalogId: string;
148
+ productId: string;
149
+ footer?: string;
150
+ metadata?: BotMessageMetadata;
151
+ }): BotServerMessageWhatsappProduct;
152
+ static createWhatsappProductList({ header, body, footer, catalogId, sections, metadata, }: {
153
+ body: string;
154
+ catalogId: string;
155
+ header: string;
156
+ sections: WhatsappProductListSection[];
157
+ footer?: string;
158
+ metadata?: BotMessageMetadata;
159
+ }): BotServerMessageWhatsappProductList;
160
+ static createWhatsappProductCarousel({ templateName, templateLanguage, cards, bodyParameters, metadata, }: {
161
+ templateName: string;
162
+ templateLanguage: string;
163
+ cards: WhatsappProductCarouselCard[];
164
+ bodyParameters?: Record<string, any>[];
165
+ metadata?: BotMessageMetadata;
166
+ }): BotServerMessageWhatsappProductCarousel;
167
+ static createWhatsappMediaCarousel({ templateName, templateLanguage, cards, bodyParameters, metadata, }: {
168
+ templateName: string;
169
+ templateLanguage: string;
170
+ cards: WhatsappMediaCarouselCard[];
171
+ bodyParameters?: Record<string, any>[];
172
+ metadata?: BotMessageMetadata;
173
+ }): BotServerMessageWhatsappMediaCarousel;
174
+ static createWhatsappTemplate({ name, namespace, languageCode, components, metadata, }: {
175
+ name: string;
176
+ namespace: string;
177
+ languageCode: string;
178
+ components: WhatsappTemplateComponent[];
179
+ metadata?: BotMessageMetadata;
180
+ }): BotServerMessageWhatsappTemplate;
181
+ }
182
+ export {};