@wats/graph 0.3.2 → 0.3.3

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 (38) hide show
  1. package/dist/endpoints/businessManagement.d.ts +144 -0
  2. package/dist/endpoints/businessManagement.js +273 -1
  3. package/dist/endpoints/messages/builders-basic.d.ts +11 -0
  4. package/dist/endpoints/messages/builders-basic.js +272 -0
  5. package/dist/endpoints/messages/builders-interactive.d.ts +11 -0
  6. package/dist/endpoints/messages/builders-interactive.js +156 -0
  7. package/dist/endpoints/messages/builders-template.d.ts +3 -0
  8. package/dist/endpoints/messages/builders-template.js +121 -0
  9. package/dist/endpoints/messages/callables.d.ts +31 -0
  10. package/dist/endpoints/messages/callables.js +57 -0
  11. package/dist/endpoints/messages/index.d.ts +6 -0
  12. package/dist/endpoints/messages/index.js +56 -0
  13. package/dist/endpoints/messages/types.d.ts +363 -0
  14. package/dist/endpoints/messages/types.js +0 -0
  15. package/dist/endpoints/messages/validation.d.ts +43 -0
  16. package/dist/endpoints/messages/validation.js +277 -0
  17. package/dist/endpoints/messages.d.ts +1 -375
  18. package/dist/endpoints/messages.js +1 -675
  19. package/dist/endpoints/templates/builders.js +23 -0
  20. package/dist/endpoints/templates/callables.d.ts +1 -0
  21. package/dist/endpoints/templates/callables.js +4 -2
  22. package/dist/endpoints/templates/groups.d.ts +126 -0
  23. package/dist/endpoints/templates/groups.js +156 -0
  24. package/dist/endpoints/templates/index.d.ts +3 -1
  25. package/dist/endpoints/templates/index.js +8 -0
  26. package/dist/endpoints/templates/types.d.ts +14 -1
  27. package/dist/endpoints/templates.d.ts +2 -2
  28. package/dist/endpoints/templates.js +6 -0
  29. package/dist/endpoints/waba/phoneNumbers.d.ts +2 -0
  30. package/dist/endpoints/wabaEndpoints.d.ts +2 -2
  31. package/dist/endpoints/wabaEndpoints.js +6 -0
  32. package/dist/errorSubclasses.d.ts +28 -0
  33. package/dist/errorSubclasses.js +63 -0
  34. package/dist/subclients/phoneNumberClient.d.ts +18 -2
  35. package/dist/subclients/phoneNumberClient.js +72 -1
  36. package/dist/subclients/wabaClient.d.ts +15 -1
  37. package/dist/subclients/wabaClient.js +33 -0
  38. package/package.json +10 -1
@@ -0,0 +1,277 @@
1
+ import { GraphRequestValidationError } from "../../errors.js";
2
+ export const GRAPH_MESSAGES_TEXT_BODY_MAX_LENGTH = 4096;
3
+ export const GRAPH_MESSAGES_RECIPIENT_MAX_DIGITS = 15;
4
+ export const GRAPH_MESSAGES_REPLY_TO_MESSAGE_ID_MAX_LENGTH = 256;
5
+ export const GRAPH_MESSAGES_MEDIA_ID_MAX_LENGTH = 2048;
6
+ export const GRAPH_MESSAGES_MEDIA_LINK_MAX_LENGTH = 2048;
7
+ export const GRAPH_MESSAGES_MEDIA_CAPTION_MAX_LENGTH = 1024;
8
+ export const GRAPH_MESSAGES_DOCUMENT_FILENAME_MAX_LENGTH = 256;
9
+ export const GRAPH_MESSAGES_GENERAL_TEXT_MAX_LENGTH = 1024;
10
+ export const GRAPH_MESSAGES_SHORT_LABEL_MAX_LENGTH = 60;
11
+ export const GRAPH_MESSAGES_BUTTON_TITLE_MAX_LENGTH = 20;
12
+ export const GRAPH_MESSAGES_BUTTON_ID_MAX_LENGTH = 256;
13
+ export const GRAPH_MESSAGES_SECTION_TITLE_MAX_LENGTH = 24;
14
+ export const GRAPH_MESSAGES_ROW_TITLE_MAX_LENGTH = 24;
15
+ export const GRAPH_MESSAGES_ROW_DESCRIPTION_MAX_LENGTH = 72;
16
+ export const GRAPH_MESSAGES_MAX_REPLY_BUTTONS = 3;
17
+ export const GRAPH_MESSAGES_MAX_LIST_SECTIONS = 10;
18
+ export const GRAPH_MESSAGES_MAX_LIST_ROWS = 10;
19
+ export const GRAPH_MESSAGES_MAX_CONTACTS = 257;
20
+ export const GRAPH_MESSAGES_MAX_PRODUCT_ITEMS = 30;
21
+ export function isPlainOptionsObject(value) {
22
+ return typeof value === "object" && value !== null && !Array.isArray(value);
23
+ }
24
+ export function hasControlChar(value) {
25
+ for (let i = 0;i < value.length; i += 1) {
26
+ const code = value.charCodeAt(i);
27
+ if (code < 32 || code === 127)
28
+ return true;
29
+ }
30
+ return false;
31
+ }
32
+ export function assertValidRecipient(to, helperName = "sendText") {
33
+ if (typeof to !== "string") {
34
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: to must be a phone-number string.`);
35
+ }
36
+ if (to.length === 0 || to.trim().length === 0) {
37
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: to must be a non-empty phone-number string.`);
38
+ }
39
+ if (hasControlChar(to)) {
40
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: to must not contain control characters (CR/LF/NUL/etc.).`);
41
+ }
42
+ if (to.includes("/") || to.includes("\\") || to.includes("?") || to.includes("#") || to.includes(":") || to.includes("@")) {
43
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: to must be a phone-number string, not a path, URL, or address.`);
44
+ }
45
+ if (!/^\+?\d{1,15}$/.test(to)) {
46
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: to must be E.164-ish digits with optional leading + and at most ${GRAPH_MESSAGES_RECIPIENT_MAX_DIGITS} digits.`);
47
+ }
48
+ return to;
49
+ }
50
+ export function assertValidText(text) {
51
+ if (typeof text !== "string") {
52
+ throw new GraphRequestValidationError("Invalid sendText input: text must be a string.");
53
+ }
54
+ if (text.length === 0 || text.trim().length === 0) {
55
+ throw new GraphRequestValidationError("Invalid sendText input: text must be a non-empty string.");
56
+ }
57
+ if (text.length > GRAPH_MESSAGES_TEXT_BODY_MAX_LENGTH) {
58
+ throw new GraphRequestValidationError(`Invalid sendText input: text exceeds ${GRAPH_MESSAGES_TEXT_BODY_MAX_LENGTH}-character limit.`);
59
+ }
60
+ return text;
61
+ }
62
+ export function assertValidReplyToMessageId(value) {
63
+ if (typeof value !== "string") {
64
+ throw new GraphRequestValidationError("Invalid sendText input: replyToMessageId must be a string when provided.");
65
+ }
66
+ if (value.length === 0 || value.trim().length === 0) {
67
+ throw new GraphRequestValidationError("Invalid sendText input: replyToMessageId must be non-empty when provided.");
68
+ }
69
+ if (hasControlChar(value)) {
70
+ throw new GraphRequestValidationError("Invalid sendText input: replyToMessageId must not contain control characters (CR/LF/NUL/etc.).");
71
+ }
72
+ if (value.length > GRAPH_MESSAGES_REPLY_TO_MESSAGE_ID_MAX_LENGTH) {
73
+ throw new GraphRequestValidationError(`Invalid sendText input: replyToMessageId exceeds ${GRAPH_MESSAGES_REPLY_TO_MESSAGE_ID_MAX_LENGTH}-character limit.`);
74
+ }
75
+ return value;
76
+ }
77
+ export function assertNonEmptyControlFreeString(value, fieldName, maxLength, helperName) {
78
+ if (typeof value !== "string") {
79
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must be a string when provided.`);
80
+ }
81
+ if (value.length === 0 || value.trim().length === 0) {
82
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must be non-empty when provided.`);
83
+ }
84
+ if (hasControlChar(value)) {
85
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must not contain control characters (CR/LF/NUL/etc.).`);
86
+ }
87
+ if (value.length > maxLength) {
88
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} exceeds ${maxLength}-character limit.`);
89
+ }
90
+ return value;
91
+ }
92
+ export function assertNoUnsupportedMediaFields(input, helperName, options) {
93
+ if (!options.caption && input.caption !== undefined) {
94
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: caption is not supported for this media type.`);
95
+ }
96
+ if (!options.filename && input.filename !== undefined) {
97
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: filename is only supported for document messages.`);
98
+ }
99
+ }
100
+ export function assertValidMediaLink(value, helperName) {
101
+ const link = assertNonEmptyControlFreeString(value, "link", GRAPH_MESSAGES_MEDIA_LINK_MAX_LENGTH, helperName);
102
+ if (/\s/.test(link)) {
103
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: link must not contain whitespace.`);
104
+ }
105
+ let url;
106
+ try {
107
+ url = new URL(link);
108
+ } catch {
109
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: link must be a valid http(s) URL.`);
110
+ }
111
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
112
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: link must use http or https.`);
113
+ }
114
+ return link;
115
+ }
116
+ export function assertValidNumberInRange(value, fieldName, min, max, helperName) {
117
+ if (typeof value !== "number" || !Number.isFinite(value) || value < min || value > max) {
118
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must be a finite number between ${min} and ${max}.`);
119
+ }
120
+ return value;
121
+ }
122
+ export function maybeText(value, fieldName, maxLength, helperName) {
123
+ if (value === undefined)
124
+ return;
125
+ return assertNonEmptyControlFreeString(value, fieldName, maxLength, helperName);
126
+ }
127
+ export function withReplyContext(payload, input) {
128
+ if (input.replyToMessageId === undefined)
129
+ return payload;
130
+ return {
131
+ ...payload,
132
+ context: { message_id: assertValidReplyToMessageId(input.replyToMessageId) }
133
+ };
134
+ }
135
+ export function asRecordInput(input, helperName) {
136
+ if (!isPlainOptionsObject(input)) {
137
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: expected an options object.`);
138
+ }
139
+ return input;
140
+ }
141
+ function assertArray(value, fieldName, helperName) {
142
+ const isArray = inspectTemplateValue(helperName, fieldName, () => Array.isArray(value));
143
+ if (!isArray) {
144
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must be an array.`);
145
+ }
146
+ return value;
147
+ }
148
+ export function assertBoundedArray(value, fieldName, min, max, helperName) {
149
+ const arr = assertArray(value, fieldName, helperName);
150
+ const length = inspectTemplateValue(helperName, fieldName, () => arr.length);
151
+ if (!Number.isInteger(length) || length < min || length > max) {
152
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} length must be between ${min} and ${max}.`);
153
+ }
154
+ for (let i = 0;i < length; i += 1) {
155
+ const hasIndex = inspectTemplateValue(helperName, fieldName, () => (i in arr));
156
+ if (!hasIndex) {
157
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must not contain sparse array holes.`);
158
+ }
159
+ }
160
+ const proto = inspectTemplateValue(helperName, fieldName, () => Object.getPrototypeOf(arr));
161
+ if (proto !== Array.prototype) {
162
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must use Array.prototype.`);
163
+ }
164
+ const descriptors = inspectTemplateValue(helperName, fieldName, () => Object.getOwnPropertyDescriptors(arr));
165
+ if (descriptors.map !== undefined || Object.prototype.hasOwnProperty.call(descriptors, Symbol.iterator)) {
166
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must not override Array.prototype methods.`);
167
+ }
168
+ const copy = [];
169
+ for (let i = 0;i < length; i += 1) {
170
+ const descriptor = descriptors[String(i)];
171
+ if (descriptor === undefined) {
172
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must not contain inherited elements.`);
173
+ }
174
+ if (typeof descriptor.get === "function" || typeof descriptor.set === "function") {
175
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} must not use accessors.`);
176
+ }
177
+ copy.push(descriptor.value);
178
+ }
179
+ return copy;
180
+ }
181
+ export function mapValidatedArray(values, mapper) {
182
+ const out = [];
183
+ for (let i = 0;i < values.length; i += 1) {
184
+ out.push(mapper(values[i], i));
185
+ }
186
+ return out;
187
+ }
188
+ export function assertOnlyKnownKeys(record, allowed, helperName) {
189
+ const allowedSet = new Set(allowed);
190
+ for (const key of Object.keys(record)) {
191
+ if (!allowedSet.has(key)) {
192
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: unknown field ${key}.`);
193
+ }
194
+ }
195
+ }
196
+ export function inspectTemplateValue(helperName, path, inspector) {
197
+ try {
198
+ return inspector();
199
+ } catch (error) {
200
+ if (error instanceof GraphRequestValidationError)
201
+ throw error;
202
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} could not be inspected.`);
203
+ }
204
+ }
205
+ export function sanitizeTemplateParameter(value, helperName, path, seen, depth = 0) {
206
+ if (depth > 6) {
207
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} exceeds maximum nesting depth.`);
208
+ }
209
+ if (typeof value === "string") {
210
+ if (value.length === 0 || value.length > GRAPH_MESSAGES_MEDIA_ID_MAX_LENGTH || hasControlChar(value)) {
211
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} contains an invalid string.`);
212
+ }
213
+ return value;
214
+ }
215
+ if (typeof value === "number") {
216
+ if (!Number.isFinite(value)) {
217
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} contains a non-finite number.`);
218
+ }
219
+ return value;
220
+ }
221
+ if (value === null || typeof value === "boolean")
222
+ return value;
223
+ if (value === undefined)
224
+ return;
225
+ const maybeObject = value;
226
+ const isArrayValue = inspectTemplateValue(helperName, path, () => Array.isArray(maybeObject));
227
+ if (isArrayValue) {
228
+ const own = inspectTemplateValue(helperName, path, () => Object.getOwnPropertyDescriptors(maybeObject));
229
+ if (Object.prototype.hasOwnProperty.call(own, "toJSON") || inspectTemplateValue(helperName, path, () => ("toJSON" in maybeObject))) {
230
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} must not define toJSON.`);
231
+ }
232
+ for (const [key, descriptor] of Object.entries(own)) {
233
+ if (typeof descriptor.get === "function" || typeof descriptor.set === "function") {
234
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path}.${key} must not use accessors.`);
235
+ }
236
+ }
237
+ return mapValidatedArray(assertBoundedArray(value, path, 0, 100, helperName), (entry, index) => sanitizeTemplateParameter(entry, helperName, `${path}[${index}]`, seen, depth + 1));
238
+ }
239
+ if (!isPlainOptionsObject(value)) {
240
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} must be JSON-serializable.`);
241
+ }
242
+ const record = value;
243
+ const proto = inspectTemplateValue(helperName, path, () => Object.getPrototypeOf(record));
244
+ if (proto !== Object.prototype && proto !== null) {
245
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} must be a plain object.`);
246
+ }
247
+ const descriptors = inspectTemplateValue(helperName, path, () => Object.getOwnPropertyDescriptors(record));
248
+ if (Object.prototype.hasOwnProperty.call(descriptors, "toJSON") || inspectTemplateValue(helperName, path, () => ("toJSON" in record))) {
249
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} must not define toJSON.`);
250
+ }
251
+ for (const [key, descriptor] of Object.entries(descriptors)) {
252
+ if (typeof descriptor.get === "function" || typeof descriptor.set === "function") {
253
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path}.${key} must not use accessors.`);
254
+ }
255
+ if (typeof descriptor.value === "function" || typeof descriptor.value === "symbol") {
256
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path}.${key} must be JSON-serializable.`);
257
+ }
258
+ }
259
+ if (seen.has(record)) {
260
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} must not contain cycles.`);
261
+ }
262
+ seen.add(record);
263
+ const out = {};
264
+ try {
265
+ for (const [key, descriptor] of Object.entries(descriptors)) {
266
+ if (key.length === 0 || key.length > GRAPH_MESSAGES_SHORT_LABEL_MAX_LENGTH || hasControlChar(key)) {
267
+ throw new GraphRequestValidationError(`Invalid ${helperName} input: ${path} contains an invalid key.`);
268
+ }
269
+ const sanitized = sanitizeTemplateParameter(descriptor.value, helperName, `${path}.${key}`, seen, depth + 1);
270
+ if (sanitized !== undefined)
271
+ out[key] = sanitized;
272
+ }
273
+ } finally {
274
+ seen.delete(record);
275
+ }
276
+ return out;
277
+ }
@@ -1,375 +1 @@
1
- import type { GraphRequestOptions } from "../client.js";
2
- interface GraphRequestExecutor {
3
- request<TResponse>(options: GraphRequestOptions): Promise<TResponse>;
4
- }
5
- export interface GraphMessagesSendMessageInput {
6
- phoneNumberId: string;
7
- to: string;
8
- text: string;
9
- previewUrl?: boolean;
10
- }
11
- export interface GraphMessagesSendTextInput {
12
- readonly to: string;
13
- readonly text: string;
14
- readonly previewUrl?: boolean;
15
- readonly replyToMessageId?: string;
16
- }
17
- export interface GraphMessagesSendMediaInput {
18
- readonly to: string;
19
- readonly mediaId?: string;
20
- readonly link?: string;
21
- readonly replyToMessageId?: string;
22
- }
23
- export interface GraphMessagesSendCaptionedMediaInput extends GraphMessagesSendMediaInput {
24
- readonly caption?: string;
25
- }
26
- export interface GraphMessagesSendDocumentInput extends GraphMessagesSendCaptionedMediaInput {
27
- readonly filename?: string;
28
- }
29
- export type GraphMessagesSendImageInput = GraphMessagesSendCaptionedMediaInput;
30
- export type GraphMessagesSendVideoInput = GraphMessagesSendCaptionedMediaInput;
31
- export type GraphMessagesSendAudioInput = GraphMessagesSendMediaInput;
32
- export type GraphMessagesSendStickerInput = GraphMessagesSendMediaInput;
33
- export interface GraphMessagesSendLocationInput {
34
- readonly to: string;
35
- readonly latitude: number;
36
- readonly longitude: number;
37
- readonly name?: string;
38
- readonly address?: string;
39
- readonly replyToMessageId?: string;
40
- }
41
- export interface GraphMessagesContactNameInput {
42
- readonly formattedName?: string;
43
- readonly firstName?: string;
44
- readonly lastName?: string;
45
- readonly middleName?: string;
46
- readonly suffix?: string;
47
- readonly prefix?: string;
48
- }
49
- export interface GraphMessagesContactPhoneInput {
50
- readonly phone?: string;
51
- readonly type?: string;
52
- readonly waId?: string;
53
- }
54
- export interface GraphMessagesContactEmailInput {
55
- readonly email: string;
56
- readonly type?: string;
57
- }
58
- export interface GraphMessagesContactUrlInput {
59
- readonly url: string;
60
- readonly type?: string;
61
- }
62
- export interface GraphMessagesContactAddressInput {
63
- readonly street?: string;
64
- readonly city?: string;
65
- readonly state?: string;
66
- readonly zip?: string;
67
- readonly country?: string;
68
- readonly countryCode?: string;
69
- readonly type?: string;
70
- }
71
- export interface GraphMessagesContactOrgInput {
72
- readonly company?: string;
73
- readonly department?: string;
74
- readonly title?: string;
75
- }
76
- export interface GraphMessagesContactInput {
77
- readonly name: GraphMessagesContactNameInput;
78
- readonly phones?: readonly GraphMessagesContactPhoneInput[];
79
- readonly emails?: readonly GraphMessagesContactEmailInput[];
80
- readonly urls?: readonly GraphMessagesContactUrlInput[];
81
- readonly addresses?: readonly GraphMessagesContactAddressInput[];
82
- readonly org?: GraphMessagesContactOrgInput;
83
- readonly birthday?: string;
84
- }
85
- export interface GraphMessagesSendContactsInput {
86
- readonly to: string;
87
- readonly contacts: readonly GraphMessagesContactInput[];
88
- readonly replyToMessageId?: string;
89
- }
90
- export interface GraphMessagesSendReactionInput {
91
- readonly to: string;
92
- readonly messageId: string;
93
- readonly emoji: string;
94
- }
95
- export interface GraphMessagesRemoveReactionInput {
96
- readonly to: string;
97
- readonly messageId: string;
98
- }
99
- export interface GraphMessagesSendButtonsInput {
100
- readonly to: string;
101
- readonly bodyText: string;
102
- readonly buttons: readonly {
103
- readonly id: string;
104
- readonly title: string;
105
- }[];
106
- readonly headerText?: string;
107
- readonly footerText?: string;
108
- readonly replyToMessageId?: string;
109
- }
110
- export interface GraphMessagesSendListInput {
111
- readonly to: string;
112
- readonly bodyText: string;
113
- readonly buttonText: string;
114
- readonly sections: readonly {
115
- readonly title?: string;
116
- readonly rows: readonly {
117
- readonly id: string;
118
- readonly title: string;
119
- readonly description?: string;
120
- }[];
121
- }[];
122
- readonly headerText?: string;
123
- readonly footerText?: string;
124
- readonly replyToMessageId?: string;
125
- }
126
- export interface GraphMessagesSendCtaUrlInput {
127
- readonly to: string;
128
- readonly bodyText: string;
129
- readonly displayText: string;
130
- readonly url: string;
131
- readonly footerText?: string;
132
- readonly replyToMessageId?: string;
133
- }
134
- export interface GraphMessagesSendProductInput {
135
- readonly to: string;
136
- readonly catalogId: string;
137
- readonly productRetailerId: string;
138
- readonly bodyText?: string;
139
- readonly footerText?: string;
140
- readonly replyToMessageId?: string;
141
- }
142
- export interface GraphMessagesSendProductsInput {
143
- readonly to: string;
144
- readonly catalogId: string;
145
- readonly headerText: string;
146
- readonly bodyText: string;
147
- readonly sections: readonly {
148
- readonly title: string;
149
- readonly productItems: readonly {
150
- readonly productRetailerId: string;
151
- }[];
152
- }[];
153
- readonly footerText?: string;
154
- readonly replyToMessageId?: string;
155
- }
156
- export interface GraphMessagesSendCatalogInput {
157
- readonly to: string;
158
- readonly bodyText: string;
159
- readonly footerText?: string;
160
- readonly thumbnailProductRetailerId?: string;
161
- readonly replyToMessageId?: string;
162
- }
163
- export interface GraphMessagesRequestLocationInput {
164
- readonly to: string;
165
- readonly bodyText: string;
166
- readonly replyToMessageId?: string;
167
- }
168
- export interface GraphMessagesMarkMessageAsReadInput {
169
- readonly messageId: string;
170
- }
171
- export type GraphMessagesTypingIndicatorInput = GraphMessagesMarkMessageAsReadInput;
172
- export interface GraphMessagesTemplateComponentInput {
173
- readonly type: string;
174
- readonly parameters?: readonly Record<string, unknown>[];
175
- readonly subType?: string;
176
- readonly index?: string;
177
- }
178
- export interface GraphMessagesSendTemplateInput {
179
- readonly to: string;
180
- readonly name: string;
181
- readonly languageCode: string;
182
- readonly components?: readonly GraphMessagesTemplateComponentInput[];
183
- readonly replyToMessageId?: string;
184
- }
185
- export interface GraphMessagesSendResponse {
186
- messaging_product?: string;
187
- contacts?: Array<{
188
- input?: string;
189
- wa_id?: string;
190
- }>;
191
- messages?: Array<{
192
- id: string;
193
- }>;
194
- }
195
- export interface GraphMessagesTextPayload {
196
- messaging_product: "whatsapp";
197
- to: string;
198
- type: "text";
199
- text: {
200
- body: string;
201
- preview_url?: boolean;
202
- };
203
- context?: {
204
- message_id: string;
205
- };
206
- }
207
- export type GraphMessagesMediaType = "image" | "video" | "audio" | "document" | "sticker";
208
- interface GraphMessagesMediaReferencePayload {
209
- id?: string;
210
- link?: string;
211
- caption?: string;
212
- filename?: string;
213
- }
214
- export type GraphMessagesImagePayload = {
215
- messaging_product: "whatsapp";
216
- to: string;
217
- type: "image";
218
- image: GraphMessagesMediaReferencePayload;
219
- context?: {
220
- message_id: string;
221
- };
222
- };
223
- export type GraphMessagesVideoPayload = {
224
- messaging_product: "whatsapp";
225
- to: string;
226
- type: "video";
227
- video: GraphMessagesMediaReferencePayload;
228
- context?: {
229
- message_id: string;
230
- };
231
- };
232
- export type GraphMessagesAudioPayload = {
233
- messaging_product: "whatsapp";
234
- to: string;
235
- type: "audio";
236
- audio: GraphMessagesMediaReferencePayload;
237
- context?: {
238
- message_id: string;
239
- };
240
- };
241
- export type GraphMessagesDocumentPayload = {
242
- messaging_product: "whatsapp";
243
- to: string;
244
- type: "document";
245
- document: GraphMessagesMediaReferencePayload;
246
- context?: {
247
- message_id: string;
248
- };
249
- };
250
- export type GraphMessagesStickerPayload = {
251
- messaging_product: "whatsapp";
252
- to: string;
253
- type: "sticker";
254
- sticker: GraphMessagesMediaReferencePayload;
255
- context?: {
256
- message_id: string;
257
- };
258
- };
259
- export type GraphMessagesMediaPayload = GraphMessagesImagePayload | GraphMessagesVideoPayload | GraphMessagesAudioPayload | GraphMessagesDocumentPayload | GraphMessagesStickerPayload;
260
- export type GraphMessagesLocationPayload = {
261
- messaging_product: "whatsapp";
262
- to: string;
263
- type: "location";
264
- location: {
265
- latitude: number;
266
- longitude: number;
267
- name?: string;
268
- address?: string;
269
- };
270
- context?: {
271
- message_id: string;
272
- };
273
- };
274
- export type GraphMessagesContactsPayload = {
275
- messaging_product: "whatsapp";
276
- to: string;
277
- type: "contacts";
278
- contacts: readonly Record<string, unknown>[];
279
- context?: {
280
- message_id: string;
281
- };
282
- };
283
- export type GraphMessagesReactionPayload = {
284
- messaging_product: "whatsapp";
285
- to: string;
286
- type: "reaction";
287
- reaction: {
288
- message_id: string;
289
- emoji: string;
290
- };
291
- };
292
- export type GraphMessagesInteractivePayload = {
293
- messaging_product: "whatsapp";
294
- to: string;
295
- type: "interactive";
296
- interactive: Record<string, unknown>;
297
- context?: {
298
- message_id: string;
299
- };
300
- };
301
- export type GraphMessagesTemplatePayload = {
302
- messaging_product: "whatsapp";
303
- to: string;
304
- type: "template";
305
- template: Record<string, unknown>;
306
- context?: {
307
- message_id: string;
308
- };
309
- };
310
- export type GraphMessagesStatusPayload = {
311
- messaging_product: "whatsapp";
312
- status: "read";
313
- message_id: string;
314
- typing_indicator?: {
315
- type: "text";
316
- };
317
- };
318
- export type GraphMessagesRemainingPayload = GraphMessagesLocationPayload | GraphMessagesContactsPayload | GraphMessagesReactionPayload | GraphMessagesInteractivePayload | GraphMessagesTemplatePayload | GraphMessagesStatusPayload;
319
- export type GraphMessagesSendBody = GraphMessagesTextPayload | GraphMessagesMediaPayload | GraphMessagesRemainingPayload;
320
- export declare const GRAPH_MESSAGES_TEXT_BODY_MAX_LENGTH = 4096;
321
- export declare const GRAPH_MESSAGES_RECIPIENT_MAX_DIGITS = 15;
322
- export declare const GRAPH_MESSAGES_REPLY_TO_MESSAGE_ID_MAX_LENGTH = 256;
323
- export declare const GRAPH_MESSAGES_MEDIA_ID_MAX_LENGTH = 2048;
324
- export declare const GRAPH_MESSAGES_MEDIA_LINK_MAX_LENGTH = 2048;
325
- export declare const GRAPH_MESSAGES_MEDIA_CAPTION_MAX_LENGTH = 1024;
326
- export declare const GRAPH_MESSAGES_DOCUMENT_FILENAME_MAX_LENGTH = 256;
327
- export declare const GRAPH_MESSAGES_GENERAL_TEXT_MAX_LENGTH = 1024;
328
- export declare const GRAPH_MESSAGES_SHORT_LABEL_MAX_LENGTH = 60;
329
- export declare const GRAPH_MESSAGES_BUTTON_TITLE_MAX_LENGTH = 20;
330
- export declare const GRAPH_MESSAGES_BUTTON_ID_MAX_LENGTH = 256;
331
- export declare const GRAPH_MESSAGES_SECTION_TITLE_MAX_LENGTH = 24;
332
- export declare const GRAPH_MESSAGES_ROW_TITLE_MAX_LENGTH = 24;
333
- export declare const GRAPH_MESSAGES_ROW_DESCRIPTION_MAX_LENGTH = 72;
334
- export declare const GRAPH_MESSAGES_MAX_REPLY_BUTTONS = 3;
335
- export declare const GRAPH_MESSAGES_MAX_LIST_SECTIONS = 10;
336
- export declare const GRAPH_MESSAGES_MAX_LIST_ROWS = 10;
337
- export declare const GRAPH_MESSAGES_MAX_CONTACTS = 257;
338
- export declare const GRAPH_MESSAGES_MAX_PRODUCT_ITEMS = 30;
339
- export declare function buildSendTextPayload(input: GraphMessagesSendTextInput): GraphMessagesTextPayload;
340
- export declare function buildSendImagePayload(input: GraphMessagesSendImageInput): GraphMessagesImagePayload;
341
- export declare function buildSendVideoPayload(input: GraphMessagesSendVideoInput): GraphMessagesVideoPayload;
342
- export declare function buildSendAudioPayload(input: GraphMessagesSendAudioInput): GraphMessagesAudioPayload;
343
- export declare function buildSendDocumentPayload(input: GraphMessagesSendDocumentInput): GraphMessagesDocumentPayload;
344
- export declare function buildSendStickerPayload(input: GraphMessagesSendStickerInput): GraphMessagesStickerPayload;
345
- export declare function buildSendLocationPayload(input: GraphMessagesSendLocationInput): GraphMessagesLocationPayload;
346
- export declare function buildSendContactsPayload(input: GraphMessagesSendContactsInput): GraphMessagesContactsPayload;
347
- export declare function buildSendReactionPayload(input: GraphMessagesSendReactionInput): GraphMessagesReactionPayload;
348
- export declare function buildRemoveReactionPayload(input: GraphMessagesRemoveReactionInput): GraphMessagesReactionPayload;
349
- export declare function buildSendButtonsPayload(input: GraphMessagesSendButtonsInput): GraphMessagesInteractivePayload;
350
- export declare function buildSendListPayload(input: GraphMessagesSendListInput): GraphMessagesInteractivePayload;
351
- export declare function buildSendCtaUrlPayload(input: GraphMessagesSendCtaUrlInput): GraphMessagesInteractivePayload;
352
- export declare function buildSendProductPayload(input: GraphMessagesSendProductInput): GraphMessagesInteractivePayload;
353
- export declare function buildSendProductsPayload(input: GraphMessagesSendProductsInput): GraphMessagesInteractivePayload;
354
- export declare function buildSendCatalogPayload(input: GraphMessagesSendCatalogInput): GraphMessagesInteractivePayload;
355
- export declare function buildRequestLocationPayload(input: GraphMessagesRequestLocationInput): GraphMessagesInteractivePayload;
356
- export declare function buildMarkMessageAsReadPayload(input: GraphMessagesMarkMessageAsReadInput): GraphMessagesStatusPayload;
357
- export declare function buildTypingIndicatorPayload(input: GraphMessagesTypingIndicatorInput): GraphMessagesStatusPayload;
358
- export declare function buildSendTemplatePayload(input: GraphMessagesSendTemplateInput): GraphMessagesTemplatePayload;
359
- export declare function buildSendMessagePayload(input: GraphMessagesSendMessageInput): GraphMessagesTextPayload;
360
- /**
361
- * `sendMessage` — Graph `POST /{phoneNumberId}/messages`.
362
- *
363
- * Built via `defineEndpoint`, so path-template parsing, param validation,
364
- * control-char rejection, body passthrough, and F-5 error registry
365
- * routing are handled uniformly.
366
- */
367
- export declare const sendMessage: import("../endpoint.js").EndpointCallable<{
368
- phoneNumberId: string;
369
- }, GraphMessagesSendBody, GraphMessagesSendResponse>;
370
- export declare class GraphMessagesEndpoint {
371
- private readonly requestExecutor;
372
- constructor(requestExecutor: GraphRequestExecutor);
373
- sendMessage(input: GraphMessagesSendMessageInput): Promise<GraphMessagesSendResponse>;
374
- }
375
- export {};
1
+ export * from "./messages/index.js";