@dev.smartpricing/message-composer-utils 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/api/aiIntegration.js +7 -0
- package/dist/types/api/aiIntegration.js.map +1 -0
- package/dist/types/api/apiMessages.js +2 -0
- package/dist/types/api/apiMessages.js.map +1 -0
- package/dist/types/api/index.js +3 -0
- package/dist/types/api/index.js.map +1 -0
- package/dist/types/app.js +23 -0
- package/dist/types/app.js.map +1 -0
- package/dist/types/brand.js +31 -0
- package/dist/types/brand.js.map +1 -0
- package/dist/types/dynamic-values.js +5 -0
- package/dist/types/dynamic-values.js.map +1 -0
- package/dist/types/emailblocks.v1.defaults.js +83 -0
- package/dist/types/emailblocks.v1.defaults.js.map +1 -0
- package/dist/types/emailblocks.v1.js +339 -0
- package/dist/types/emailblocks.v1.js.map +1 -0
- package/dist/types/index.js +16 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/kafka-events.js +2 -0
- package/dist/types/kafka-events.js.map +1 -0
- package/dist/types/language.js +2 -0
- package/dist/types/language.js.map +1 -0
- package/dist/types/media.js +6 -0
- package/dist/types/media.js.map +1 -0
- package/dist/types/message.js +41 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/meta-template.js +2 -0
- package/dist/types/meta-template.js.map +1 -0
- package/dist/types/meta-webhook.js +2 -0
- package/dist/types/meta-webhook.js.map +1 -0
- package/dist/types/submission-job.js +2 -0
- package/dist/types/submission-job.js.map +1 -0
- package/dist/types/tag.js +2 -0
- package/dist/types/tag.js.map +1 -0
- package/dist/types/utils.js +2 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/types/whatsappblocks.v1.js +24 -0
- package/dist/types/whatsappblocks.v1.js.map +1 -0
- package/dist/utils/array.js +26 -0
- package/dist/utils/array.js.map +1 -0
- package/dist/utils/async.js +22 -0
- package/dist/utils/async.js.map +1 -0
- package/dist/utils/date.js +37 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/index.js +34 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/intl.js +37 -0
- package/dist/utils/intl.js.map +1 -0
- package/dist/utils/meta-status.js +21 -0
- package/dist/utils/meta-status.js.map +1 -0
- package/dist/utils/number.js +24 -0
- package/dist/utils/number.js.map +1 -0
- package/dist/utils/object.js +87 -0
- package/dist/utils/object.js.map +1 -0
- package/dist/utils/string.js +22 -0
- package/dist/utils/string.js.map +1 -0
- package/dist/utils/templates/brand-cascade.js +116 -0
- package/dist/utils/templates/brand-cascade.js.map +1 -0
- package/dist/utils/templates/email-compiler.js +126 -0
- package/dist/utils/templates/email-compiler.js.map +1 -0
- package/dist/utils/templates/email-mjml.js +444 -0
- package/dist/utils/templates/email-mjml.js.map +1 -0
- package/dist/utils/templates/email.js +580 -0
- package/dist/utils/templates/email.js.map +1 -0
- package/dist/utils/templates/html-sanitizer.js +95 -0
- package/dist/utils/templates/html-sanitizer.js.map +1 -0
- package/dist/utils/templates/messages.js +33 -0
- package/dist/utils/templates/messages.js.map +1 -0
- package/dist/utils/templates/meta.js +246 -0
- package/dist/utils/templates/meta.js.map +1 -0
- package/dist/utils/templates/tiptap.js +167 -0
- package/dist/utils/templates/tiptap.js.map +1 -0
- package/dist/utils/templates/whatsapp-compiler.js +168 -0
- package/dist/utils/templates/whatsapp-compiler.js.map +1 -0
- package/dist/utils/templates/whatsapp.js +329 -0
- package/dist/utils/templates/whatsapp.js.map +1 -0
- package/dist/utils/validations.js +39 -0
- package/dist/utils/validations.js.map +1 -0
- package/package.json +43 -0
- package/src/types/api/aiIntegration.ts +59 -0
- package/src/types/api/apiMessages.ts +22 -0
- package/src/types/api/index.ts +2 -0
- package/src/types/app.ts +76 -0
- package/src/types/brand.ts +80 -0
- package/src/types/dynamic-values.ts +47 -0
- package/src/types/emailblocks.v1.defaults.ts +123 -0
- package/src/types/emailblocks.v1.ts +655 -0
- package/src/types/index.ts +15 -0
- package/src/types/kafka-events.ts +46 -0
- package/src/types/language.ts +9 -0
- package/src/types/media.ts +26 -0
- package/src/types/message.ts +635 -0
- package/src/types/meta-template.ts +50 -0
- package/src/types/meta-webhook.ts +32 -0
- package/src/types/submission-job.ts +30 -0
- package/src/types/tag.ts +8 -0
- package/src/types/utils.ts +14 -0
- package/src/types/whatsappblocks.v1.ts +102 -0
- package/src/utils/array.ts +33 -0
- package/src/utils/async.ts +30 -0
- package/src/utils/date.ts +39 -0
- package/src/utils/index.ts +44 -0
- package/src/utils/intl.ts +51 -0
- package/src/utils/meta-status.ts +24 -0
- package/src/utils/number.ts +36 -0
- package/src/utils/object.ts +101 -0
- package/src/utils/string.ts +24 -0
- package/src/utils/templates/brand-cascade.ts +156 -0
- package/src/utils/templates/email-compiler.ts +155 -0
- package/src/utils/templates/email-mjml.ts +602 -0
- package/src/utils/templates/email.ts +713 -0
- package/src/utils/templates/html-sanitizer.ts +121 -0
- package/src/utils/templates/messages.ts +44 -0
- package/src/utils/templates/meta.ts +336 -0
- package/src/utils/templates/tiptap.ts +247 -0
- package/src/utils/templates/whatsapp-compiler.ts +212 -0
- package/src/utils/templates/whatsapp.ts +408 -0
- package/src/utils/validations.ts +49 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DbEntity, WithDbTimestamps } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
export type MediaType = "image" | "video" | "document";
|
|
4
|
+
|
|
5
|
+
export const MEDIA_LIMITS = {
|
|
6
|
+
image: { maxSize: 5 * 1024 * 1024, accept: ["image/jpeg", "image/png"] },
|
|
7
|
+
video: { maxSize: 16 * 1024 * 1024, accept: ["video/mp4", "video/3gpp"] },
|
|
8
|
+
document: { maxSize: 20 * 1024 * 1024, accept: ["application/pdf"] },
|
|
9
|
+
} as const satisfies Record<
|
|
10
|
+
MediaType,
|
|
11
|
+
{ maxSize: number; accept: readonly string[] }
|
|
12
|
+
>;
|
|
13
|
+
|
|
14
|
+
export interface Media extends DbEntity {
|
|
15
|
+
id: string;
|
|
16
|
+
remote_url: string;
|
|
17
|
+
remote_name: string; // Sanitized filename stored in GCS (includes UUID prefix)
|
|
18
|
+
file_name: string; // Original filename from user
|
|
19
|
+
file_type: string;
|
|
20
|
+
meta_handle_id?: string;
|
|
21
|
+
smartchat_media_id?: string;
|
|
22
|
+
owner?: string;
|
|
23
|
+
user_id: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type MediaFromDb = WithDbTimestamps<Media>;
|
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { MetaTemplate } from "./meta-template.js";
|
|
3
|
+
import type { DbEntity, PostEntity, WithDbTimestamps } from "./utils.js";
|
|
4
|
+
import type {
|
|
5
|
+
BodyBlockV1,
|
|
6
|
+
FooterBlockV1,
|
|
7
|
+
HeaderBlockV1,
|
|
8
|
+
ButtonBlockV1,
|
|
9
|
+
} from "./whatsappblocks.v1.js";
|
|
10
|
+
import type { EmailBlock, EmailGlobalSettings } from "./emailblocks.v1.js";
|
|
11
|
+
import {
|
|
12
|
+
brandDefaultEmailSettingsSchema,
|
|
13
|
+
brandDefaultButtonSettingsSchema,
|
|
14
|
+
} from "./brand.js";
|
|
15
|
+
|
|
16
|
+
export const MESSAGE_RENDER_TYPES = ["whatsapp_v1", "email_v1"] as const;
|
|
17
|
+
export type RenderType = (typeof MESSAGE_RENDER_TYPES)[number];
|
|
18
|
+
export const MESSAGE_STATUS = [
|
|
19
|
+
"pending",
|
|
20
|
+
"draft",
|
|
21
|
+
"rejected",
|
|
22
|
+
"approved",
|
|
23
|
+
] as const;
|
|
24
|
+
export type MessageStatus = (typeof MESSAGE_STATUS)[number];
|
|
25
|
+
|
|
26
|
+
interface BaseMessage extends DbEntity {
|
|
27
|
+
id: string;
|
|
28
|
+
message_group_id: string;
|
|
29
|
+
language_id: string;
|
|
30
|
+
status: MessageStatus;
|
|
31
|
+
render_type: RenderType;
|
|
32
|
+
owner?: string;
|
|
33
|
+
user_id: string;
|
|
34
|
+
}
|
|
35
|
+
export interface WhatsappMessage extends BaseMessage {
|
|
36
|
+
render_type: "whatsapp_v1";
|
|
37
|
+
body: {
|
|
38
|
+
header: HeaderBlockV1;
|
|
39
|
+
body: BodyBlockV1;
|
|
40
|
+
footer: FooterBlockV1;
|
|
41
|
+
buttons: ButtonBlockV1;
|
|
42
|
+
};
|
|
43
|
+
metadata: {
|
|
44
|
+
meta?: {
|
|
45
|
+
template_id: string;
|
|
46
|
+
template_name: string;
|
|
47
|
+
submission_date: string;
|
|
48
|
+
approval_date?: string;
|
|
49
|
+
rejection_reason?: string;
|
|
50
|
+
translated_template: MetaTemplate;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export interface EmailMessage extends BaseMessage {
|
|
55
|
+
render_type: "email_v1";
|
|
56
|
+
body: {
|
|
57
|
+
subject: string;
|
|
58
|
+
blocks: EmailBlock[];
|
|
59
|
+
settings: EmailGlobalSettings;
|
|
60
|
+
};
|
|
61
|
+
metadata: {
|
|
62
|
+
preheader?: string;
|
|
63
|
+
email?: {
|
|
64
|
+
mjml: string;
|
|
65
|
+
compilation_date: string;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type Message = WhatsappMessage | EmailMessage;
|
|
71
|
+
|
|
72
|
+
export type MessageFromDb = WithDbTimestamps<Message>;
|
|
73
|
+
|
|
74
|
+
export const MESSAGE_GROUP_CATEGORIES = ["marketing", "utility"] as const;
|
|
75
|
+
export type MessageGroupCategory = (typeof MESSAGE_GROUP_CATEGORIES)[number];
|
|
76
|
+
|
|
77
|
+
export const MESSAGE_GROUP_VISIBILITY = ["public", "internal"] as const;
|
|
78
|
+
export type MessageGroupVisibility = (typeof MESSAGE_GROUP_VISIBILITY)[number];
|
|
79
|
+
|
|
80
|
+
export interface MessageGroup extends DbEntity {
|
|
81
|
+
id: string;
|
|
82
|
+
name: string;
|
|
83
|
+
category: MessageGroupCategory;
|
|
84
|
+
visibility?: MessageGroupVisibility;
|
|
85
|
+
brand_id?: string | null;
|
|
86
|
+
owner?: string;
|
|
87
|
+
user_id: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type MessageGroupFromDb = WithDbTimestamps<MessageGroup>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Message Group Validation Types
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
export interface MessageContentValidationEntry {
|
|
97
|
+
type: RenderType;
|
|
98
|
+
errors: string[];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface MessageGroupValidationErrors {
|
|
102
|
+
status: string[];
|
|
103
|
+
languages: string[];
|
|
104
|
+
content: Record<string, MessageContentValidationEntry>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface MessageGroupValidationResponse {
|
|
108
|
+
valid: boolean;
|
|
109
|
+
errors: MessageGroupValidationErrors;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Message Compilation Types
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Request body for compiling a message template
|
|
118
|
+
*/
|
|
119
|
+
export interface CompileMessageRequest {
|
|
120
|
+
/** Language code to compile (e.g., 'en', 'it', 'es') */
|
|
121
|
+
language: string;
|
|
122
|
+
|
|
123
|
+
/** Optional fallback language if primary language not found */
|
|
124
|
+
fallbackLanguage?: string;
|
|
125
|
+
|
|
126
|
+
/** Key-value pairs for parameter injection into template placeholders */
|
|
127
|
+
parameters: Record<string, unknown>;
|
|
128
|
+
|
|
129
|
+
/** When true, throws on missing parameters. When false (default), replaces missing params with empty string */
|
|
130
|
+
strict?: boolean;
|
|
131
|
+
|
|
132
|
+
/** Optional brand ID override — uses this brand instead of the message_group's brand */
|
|
133
|
+
brand_id?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Brand cascade data schema for preview validation.
|
|
138
|
+
* Subset of BrandFromDb used at compile time.
|
|
139
|
+
*/
|
|
140
|
+
export const brandCascadeDataSchema = z.object({
|
|
141
|
+
default_email_settings: brandDefaultEmailSettingsSchema,
|
|
142
|
+
default_button_settings: brandDefaultButtonSettingsSchema,
|
|
143
|
+
default_socials: z.record(z.string(), z.string()).nullable(),
|
|
144
|
+
logo_url: z.string().nullable(),
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Request body for previewing a message with inline data (no DB lookups).
|
|
149
|
+
*/
|
|
150
|
+
export const previewMessageRequestSchema = z.object({
|
|
151
|
+
message: z
|
|
152
|
+
.object({
|
|
153
|
+
render_type: z.literal("email_v1"),
|
|
154
|
+
language_id: z.string(),
|
|
155
|
+
body: z.object({
|
|
156
|
+
subject: z.string(),
|
|
157
|
+
blocks: z.array(z.record(z.string(), z.unknown())),
|
|
158
|
+
settings: z.record(z.string(), z.unknown()),
|
|
159
|
+
}),
|
|
160
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
161
|
+
})
|
|
162
|
+
.passthrough(),
|
|
163
|
+
parameters: z.record(z.string(), z.unknown()).optional().default({}),
|
|
164
|
+
brand: brandCascadeDataSchema.nullable().optional().default(null),
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
export type PreviewMessageRequest = z.infer<typeof previewMessageRequestSchema>;
|
|
168
|
+
|
|
169
|
+
export type EmailProvider = "SendGrid" | "AmazonSES";
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Request body for compiling and preparing message for sending
|
|
173
|
+
*/
|
|
174
|
+
export interface CompileAndSendRequest extends CompileMessageRequest {
|
|
175
|
+
/** Sender identifier (WhatsApp: phone number ID, Email: from address) */
|
|
176
|
+
from: string;
|
|
177
|
+
|
|
178
|
+
/** Recipient identifier (WhatsApp: phone number, Email: email address) */
|
|
179
|
+
to: string;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Message ID to be used for context
|
|
183
|
+
* @deprecated Use additionalInfo instead
|
|
184
|
+
*/
|
|
185
|
+
automationEngineMessageId?: string;
|
|
186
|
+
|
|
187
|
+
/** Additional parameters to be sent with the message */
|
|
188
|
+
additionalInfo?: Record<string, unknown>;
|
|
189
|
+
|
|
190
|
+
/** Email provider override (default: "SendGrid") */
|
|
191
|
+
provider?: EmailProvider;
|
|
192
|
+
|
|
193
|
+
/** Message kind — when "newsletter", sends via Queen queue instead of messageAPI */
|
|
194
|
+
kind?: string;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Request body for testing email rendering
|
|
199
|
+
*/
|
|
200
|
+
export interface TestEmailRequest {
|
|
201
|
+
/** Email message configuration */
|
|
202
|
+
message: PostEntity<EmailMessage>;
|
|
203
|
+
|
|
204
|
+
/** Recipient email address for testing */
|
|
205
|
+
to: string;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* WhatsApp Cloud API send message payloads
|
|
210
|
+
* Reference: https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
// Base properties common to all message types
|
|
214
|
+
interface WhatsAppMessageBase {
|
|
215
|
+
messaging_product: "whatsapp";
|
|
216
|
+
recipient_type?: "individual";
|
|
217
|
+
to: string;
|
|
218
|
+
biz_opaque_callback_data?: string;
|
|
219
|
+
context?: {
|
|
220
|
+
message_id: string;
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Template message type
|
|
225
|
+
|
|
226
|
+
type WhatsappHeaderParamText = {
|
|
227
|
+
type: "text";
|
|
228
|
+
text: string;
|
|
229
|
+
parameter_name: string;
|
|
230
|
+
};
|
|
231
|
+
type WhatsappHeaderParamImage = {
|
|
232
|
+
type: "image";
|
|
233
|
+
image: { link: string } | { id: string };
|
|
234
|
+
};
|
|
235
|
+
type WhatsappHeaderParamVideo = {
|
|
236
|
+
type: "video";
|
|
237
|
+
video: { link: string } | { id: string };
|
|
238
|
+
};
|
|
239
|
+
type WhatsappHeaderParamDocument = {
|
|
240
|
+
type: "document";
|
|
241
|
+
document:
|
|
242
|
+
| { link: string; filename?: string }
|
|
243
|
+
| { id: string; filename?: string };
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
export type WhatsappHeaderParam =
|
|
247
|
+
| WhatsappHeaderParamText
|
|
248
|
+
| WhatsappHeaderParamImage
|
|
249
|
+
| WhatsappHeaderParamVideo
|
|
250
|
+
| WhatsappHeaderParamDocument;
|
|
251
|
+
|
|
252
|
+
interface WhatsAppTemplateMessage extends WhatsAppMessageBase {
|
|
253
|
+
type: "template";
|
|
254
|
+
template: {
|
|
255
|
+
name: string;
|
|
256
|
+
language: {
|
|
257
|
+
code: string;
|
|
258
|
+
policy?: "deterministic";
|
|
259
|
+
};
|
|
260
|
+
components?: Array<
|
|
261
|
+
| {
|
|
262
|
+
type: "HEADER";
|
|
263
|
+
parameters: WhatsappHeaderParam[];
|
|
264
|
+
}
|
|
265
|
+
| {
|
|
266
|
+
type: "BODY";
|
|
267
|
+
parameters: Array<
|
|
268
|
+
| { type: "text"; text: string; parameter_name: string }
|
|
269
|
+
| {
|
|
270
|
+
type: "currency";
|
|
271
|
+
currency: {
|
|
272
|
+
fallback_value: string;
|
|
273
|
+
code: string;
|
|
274
|
+
amount_1000: number;
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
| { type: "date_time"; date_time: { fallback_value: string } }
|
|
278
|
+
>;
|
|
279
|
+
}
|
|
280
|
+
| {
|
|
281
|
+
type: "BUTTON";
|
|
282
|
+
sub_type: "url";
|
|
283
|
+
index: string; // "0", "1", "2" - string representation of button position
|
|
284
|
+
parameters: Array<{
|
|
285
|
+
type: "text";
|
|
286
|
+
parameter_name: string;
|
|
287
|
+
text: string; // Dynamic URL suffix for URL buttons
|
|
288
|
+
}>;
|
|
289
|
+
}
|
|
290
|
+
>;
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Union type for all WhatsApp message payloads
|
|
296
|
+
* NOTE: Only template messages implemented in v1
|
|
297
|
+
*/
|
|
298
|
+
export type WhatsAppSendPayload = WhatsAppTemplateMessage;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Response for compile endpoint (WhatsApp)
|
|
302
|
+
*/
|
|
303
|
+
export interface CompileWhatsAppResponse {
|
|
304
|
+
render_type: "whatsapp_v1";
|
|
305
|
+
language: string;
|
|
306
|
+
template_name: string;
|
|
307
|
+
payload: Omit<WhatsAppTemplateMessage, "to">;
|
|
308
|
+
parameters_used: string[];
|
|
309
|
+
missingParameters?: string[];
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Response for compile endpoint (Email)
|
|
314
|
+
*/
|
|
315
|
+
export interface CompileEmailResponse {
|
|
316
|
+
render_type: "email_v1";
|
|
317
|
+
language: string;
|
|
318
|
+
subject: string;
|
|
319
|
+
html: string;
|
|
320
|
+
parameters_used: string[];
|
|
321
|
+
missingParameters?: string[];
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export type CompileMessageResponse =
|
|
325
|
+
| CompileWhatsAppResponse
|
|
326
|
+
| CompileEmailResponse;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Response for compile-and-send endpoint
|
|
330
|
+
* Simple status response - actual sending happens via smartchat-sender service
|
|
331
|
+
*/
|
|
332
|
+
export interface CompileAndSendResponse {
|
|
333
|
+
sent: boolean;
|
|
334
|
+
template_id: string;
|
|
335
|
+
language: string;
|
|
336
|
+
missingParameters?: string[];
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Parameter validation result
|
|
341
|
+
* Keep it simple - just valid/invalid with list of required parameters
|
|
342
|
+
*/
|
|
343
|
+
export interface ParameterValidationResult {
|
|
344
|
+
valid: boolean;
|
|
345
|
+
required: string[];
|
|
346
|
+
missing: string[];
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Response for get-parameters endpoint
|
|
351
|
+
*/
|
|
352
|
+
export interface GetMessageParametersResponse {
|
|
353
|
+
render_type: RenderType;
|
|
354
|
+
language: string;
|
|
355
|
+
parameters: string[];
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Text message type (for future use, not in compile endpoints)
|
|
359
|
+
export interface WhatsAppTextMessage extends WhatsAppMessageBase {
|
|
360
|
+
type: "text";
|
|
361
|
+
text: {
|
|
362
|
+
body: string;
|
|
363
|
+
preview_url?: boolean;
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Media message types
|
|
368
|
+
export interface WhatsAppImageMessage extends WhatsAppMessageBase {
|
|
369
|
+
type: "image";
|
|
370
|
+
image: {
|
|
371
|
+
link?: string;
|
|
372
|
+
id?: string;
|
|
373
|
+
caption?: string;
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export interface WhatsAppVideoMessage extends WhatsAppMessageBase {
|
|
378
|
+
type: "video";
|
|
379
|
+
video: {
|
|
380
|
+
link?: string;
|
|
381
|
+
id?: string;
|
|
382
|
+
caption?: string;
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export interface WhatsAppAudioMessage extends WhatsAppMessageBase {
|
|
387
|
+
type: "audio";
|
|
388
|
+
audio: {
|
|
389
|
+
link?: string;
|
|
390
|
+
id?: string;
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export interface WhatsAppDocumentMessage extends WhatsAppMessageBase {
|
|
395
|
+
type: "document";
|
|
396
|
+
document: {
|
|
397
|
+
link?: string;
|
|
398
|
+
id?: string;
|
|
399
|
+
caption?: string;
|
|
400
|
+
filename?: string;
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// Location message type
|
|
405
|
+
export interface WhatsAppLocationMessage extends WhatsAppMessageBase {
|
|
406
|
+
type: "location";
|
|
407
|
+
location: {
|
|
408
|
+
latitude: string;
|
|
409
|
+
longitude: string;
|
|
410
|
+
name?: string;
|
|
411
|
+
address?: string;
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Contacts message type
|
|
416
|
+
export interface WhatsAppContactsMessage extends WhatsAppMessageBase {
|
|
417
|
+
type: "contacts";
|
|
418
|
+
contacts: Array<{
|
|
419
|
+
addresses?: Array<{
|
|
420
|
+
street?: string;
|
|
421
|
+
city?: string;
|
|
422
|
+
state?: string;
|
|
423
|
+
zip?: string;
|
|
424
|
+
country?: string;
|
|
425
|
+
country_code?: string;
|
|
426
|
+
type?: "HOME" | "WORK";
|
|
427
|
+
}>;
|
|
428
|
+
birthday?: string;
|
|
429
|
+
emails?: Array<{
|
|
430
|
+
email?: string;
|
|
431
|
+
type?: "HOME" | "WORK";
|
|
432
|
+
}>;
|
|
433
|
+
name: {
|
|
434
|
+
formatted_name: string;
|
|
435
|
+
first_name?: string;
|
|
436
|
+
last_name?: string;
|
|
437
|
+
middle_name?: string;
|
|
438
|
+
suffix?: string;
|
|
439
|
+
prefix?: string;
|
|
440
|
+
};
|
|
441
|
+
org?: {
|
|
442
|
+
company?: string;
|
|
443
|
+
department?: string;
|
|
444
|
+
title?: string;
|
|
445
|
+
};
|
|
446
|
+
phones?: Array<{
|
|
447
|
+
phone?: string;
|
|
448
|
+
type?: "HOME" | "WORK" | "CELL";
|
|
449
|
+
wa_id?: string;
|
|
450
|
+
}>;
|
|
451
|
+
urls?: Array<{
|
|
452
|
+
url?: string;
|
|
453
|
+
type?: "HOME" | "WORK";
|
|
454
|
+
}>;
|
|
455
|
+
}>;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// Interactive message types
|
|
459
|
+
export interface WhatsAppInteractiveButtonMessage extends WhatsAppMessageBase {
|
|
460
|
+
type: "interactive";
|
|
461
|
+
interactive: {
|
|
462
|
+
type: "button";
|
|
463
|
+
header?: {
|
|
464
|
+
type: "text" | "image" | "video" | "document";
|
|
465
|
+
text?: string;
|
|
466
|
+
image?: { link: string };
|
|
467
|
+
video?: { link: string };
|
|
468
|
+
document?: { link: string; filename?: string };
|
|
469
|
+
};
|
|
470
|
+
body: {
|
|
471
|
+
text: string;
|
|
472
|
+
};
|
|
473
|
+
footer?: {
|
|
474
|
+
text: string;
|
|
475
|
+
};
|
|
476
|
+
action: {
|
|
477
|
+
buttons: Array<{
|
|
478
|
+
type: "reply";
|
|
479
|
+
reply: {
|
|
480
|
+
id: string;
|
|
481
|
+
title: string;
|
|
482
|
+
};
|
|
483
|
+
}>;
|
|
484
|
+
};
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export interface WhatsAppInteractiveListMessage extends WhatsAppMessageBase {
|
|
489
|
+
type: "interactive";
|
|
490
|
+
interactive: {
|
|
491
|
+
type: "list";
|
|
492
|
+
header?: {
|
|
493
|
+
type: "text";
|
|
494
|
+
text: string;
|
|
495
|
+
};
|
|
496
|
+
body: {
|
|
497
|
+
text: string;
|
|
498
|
+
};
|
|
499
|
+
footer?: {
|
|
500
|
+
text: string;
|
|
501
|
+
};
|
|
502
|
+
action: {
|
|
503
|
+
button: string;
|
|
504
|
+
sections: Array<{
|
|
505
|
+
title?: string;
|
|
506
|
+
rows: Array<{
|
|
507
|
+
id: string;
|
|
508
|
+
title: string;
|
|
509
|
+
description?: string;
|
|
510
|
+
}>;
|
|
511
|
+
}>;
|
|
512
|
+
};
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
export interface WhatsAppInteractiveProductMessage extends WhatsAppMessageBase {
|
|
517
|
+
type: "interactive";
|
|
518
|
+
interactive: {
|
|
519
|
+
type: "product";
|
|
520
|
+
body?: {
|
|
521
|
+
text: string;
|
|
522
|
+
};
|
|
523
|
+
footer?: {
|
|
524
|
+
text: string;
|
|
525
|
+
};
|
|
526
|
+
action: {
|
|
527
|
+
catalog_id: string;
|
|
528
|
+
product_retailer_id: string;
|
|
529
|
+
};
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
export interface WhatsAppInteractiveProductListMessage extends WhatsAppMessageBase {
|
|
534
|
+
type: "interactive";
|
|
535
|
+
interactive: {
|
|
536
|
+
type: "product_list";
|
|
537
|
+
header: {
|
|
538
|
+
type: "text";
|
|
539
|
+
text: string;
|
|
540
|
+
};
|
|
541
|
+
body: {
|
|
542
|
+
text: string;
|
|
543
|
+
};
|
|
544
|
+
footer?: {
|
|
545
|
+
text: string;
|
|
546
|
+
};
|
|
547
|
+
action: {
|
|
548
|
+
catalog_id: string;
|
|
549
|
+
sections: Array<{
|
|
550
|
+
title: string;
|
|
551
|
+
product_items: Array<{
|
|
552
|
+
product_retailer_id: string;
|
|
553
|
+
}>;
|
|
554
|
+
}>;
|
|
555
|
+
};
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
export interface WhatsAppInteractiveCatalogMessage extends WhatsAppMessageBase {
|
|
560
|
+
type: "interactive";
|
|
561
|
+
interactive: {
|
|
562
|
+
type: "catalog_message";
|
|
563
|
+
body: {
|
|
564
|
+
text: string;
|
|
565
|
+
};
|
|
566
|
+
action: {
|
|
567
|
+
name: "catalog_message";
|
|
568
|
+
parameters: {
|
|
569
|
+
thumbnail_product_retailer_id: string;
|
|
570
|
+
};
|
|
571
|
+
};
|
|
572
|
+
footer?: {
|
|
573
|
+
text: string;
|
|
574
|
+
};
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
export interface WhatsAppInteractiveFlowMessage extends WhatsAppMessageBase {
|
|
579
|
+
type: "interactive";
|
|
580
|
+
interactive: {
|
|
581
|
+
type: "flow";
|
|
582
|
+
header?: {
|
|
583
|
+
type: "text";
|
|
584
|
+
text: string;
|
|
585
|
+
};
|
|
586
|
+
body: {
|
|
587
|
+
text: string;
|
|
588
|
+
};
|
|
589
|
+
footer?: {
|
|
590
|
+
text: string;
|
|
591
|
+
};
|
|
592
|
+
action: {
|
|
593
|
+
name: "flow";
|
|
594
|
+
parameters: {
|
|
595
|
+
flow_message_version: "3";
|
|
596
|
+
flow_id?: string;
|
|
597
|
+
flow_name?: string;
|
|
598
|
+
flow_cta: string;
|
|
599
|
+
flow_action?: "navigate" | "data_exchange";
|
|
600
|
+
flow_action_payload?: Record<string, unknown>;
|
|
601
|
+
};
|
|
602
|
+
};
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
export interface WhatsAppCallPermissionRequestMessage extends WhatsAppMessageBase {
|
|
607
|
+
type: "interactive";
|
|
608
|
+
interactive: {
|
|
609
|
+
type: "call_permission_request";
|
|
610
|
+
body: {
|
|
611
|
+
text: string;
|
|
612
|
+
};
|
|
613
|
+
action: {
|
|
614
|
+
name: "call_permission_request";
|
|
615
|
+
};
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// Union type for all WhatsApp message payloads (extended types for future)
|
|
620
|
+
export type WhatsAppSendPayloadExtended =
|
|
621
|
+
| WhatsAppTemplateMessage
|
|
622
|
+
| WhatsAppTextMessage
|
|
623
|
+
| WhatsAppImageMessage
|
|
624
|
+
| WhatsAppVideoMessage
|
|
625
|
+
| WhatsAppAudioMessage
|
|
626
|
+
| WhatsAppDocumentMessage
|
|
627
|
+
| WhatsAppLocationMessage
|
|
628
|
+
| WhatsAppContactsMessage
|
|
629
|
+
| WhatsAppInteractiveButtonMessage
|
|
630
|
+
| WhatsAppInteractiveListMessage
|
|
631
|
+
| WhatsAppInteractiveProductMessage
|
|
632
|
+
| WhatsAppInteractiveProductListMessage
|
|
633
|
+
| WhatsAppInteractiveCatalogMessage
|
|
634
|
+
| WhatsAppInteractiveFlowMessage
|
|
635
|
+
| WhatsAppCallPermissionRequestMessage;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export interface NamedParam {
|
|
2
|
+
param_name: string;
|
|
3
|
+
example: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// Meta template types
|
|
7
|
+
export interface MetaHeaderComponent {
|
|
8
|
+
type: "HEADER";
|
|
9
|
+
format: "TEXT" | "IMAGE" | "VIDEO" | "DOCUMENT";
|
|
10
|
+
text?: string;
|
|
11
|
+
example?:
|
|
12
|
+
| { header_text_named_params: NamedParam[] }
|
|
13
|
+
| { header_handle: string[] };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface MetaBodyComponent {
|
|
17
|
+
type: "BODY";
|
|
18
|
+
text: string;
|
|
19
|
+
example?: { body_text_named_params: NamedParam[] };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface MetaFooterComponent {
|
|
23
|
+
type: "FOOTER";
|
|
24
|
+
text: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface MetaButtonComponent {
|
|
28
|
+
type: "BUTTONS";
|
|
29
|
+
buttons: Array<{
|
|
30
|
+
type: "QUICK_REPLY" | "PHONE_NUMBER" | "URL";
|
|
31
|
+
text: string;
|
|
32
|
+
url?: string;
|
|
33
|
+
phone_number?: string;
|
|
34
|
+
example?: string[];
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface MetaTemplate {
|
|
39
|
+
name: string;
|
|
40
|
+
language: string;
|
|
41
|
+
category: "MARKETING" | "UTILITY";
|
|
42
|
+
parameter_format: "NAMED";
|
|
43
|
+
allow_category_change: boolean;
|
|
44
|
+
components: Array<
|
|
45
|
+
| MetaHeaderComponent
|
|
46
|
+
| MetaBodyComponent
|
|
47
|
+
| MetaFooterComponent
|
|
48
|
+
| MetaButtonComponent
|
|
49
|
+
>;
|
|
50
|
+
}
|