@semboja/connect 0.1.1 → 0.2.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/README.md +52 -0
- package/dist/index.d.mts +314 -2
- package/dist/index.d.ts +314 -2
- package/dist/index.js +196 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +196 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,18 @@ declare class HttpClient {
|
|
|
35
35
|
* POST request
|
|
36
36
|
*/
|
|
37
37
|
post<T>(path: string, body?: unknown): Promise<T>;
|
|
38
|
+
/**
|
|
39
|
+
* PUT request
|
|
40
|
+
*/
|
|
41
|
+
put<T>(path: string, body?: unknown): Promise<T>;
|
|
42
|
+
/**
|
|
43
|
+
* PATCH request
|
|
44
|
+
*/
|
|
45
|
+
patch<T>(path: string, body?: unknown): Promise<T>;
|
|
46
|
+
/**
|
|
47
|
+
* DELETE request
|
|
48
|
+
*/
|
|
49
|
+
delete<T>(path: string): Promise<T>;
|
|
38
50
|
}
|
|
39
51
|
|
|
40
52
|
/**
|
|
@@ -74,7 +86,7 @@ interface ApiErrorResponse {
|
|
|
74
86
|
request_id: string;
|
|
75
87
|
};
|
|
76
88
|
}
|
|
77
|
-
type MessageType = 'text' | 'template' | 'image' | 'video' | 'audio' | 'document' | 'interactive' | 'reaction';
|
|
89
|
+
type MessageType = 'text' | 'template' | 'image' | 'video' | 'audio' | 'document' | 'sticker' | 'location' | 'contacts' | 'interactive' | 'reaction';
|
|
78
90
|
interface SendMessageOptions {
|
|
79
91
|
/** Meta Phone Number ID */
|
|
80
92
|
phoneNumberId: string;
|
|
@@ -165,6 +177,123 @@ interface SendReactionOptions extends SendMessageOptions {
|
|
|
165
177
|
emoji: string;
|
|
166
178
|
};
|
|
167
179
|
}
|
|
180
|
+
interface StickerObject {
|
|
181
|
+
/** URL of the sticker file (WebP format) */
|
|
182
|
+
link?: string;
|
|
183
|
+
/** Media ID (if uploaded to WhatsApp) */
|
|
184
|
+
id?: string;
|
|
185
|
+
}
|
|
186
|
+
interface SendStickerOptions extends SendMessageOptions {
|
|
187
|
+
/** Sticker configuration */
|
|
188
|
+
sticker: StickerObject;
|
|
189
|
+
/** Message ID to reply to */
|
|
190
|
+
replyTo?: string;
|
|
191
|
+
}
|
|
192
|
+
interface LocationObject {
|
|
193
|
+
/** Longitude of the location */
|
|
194
|
+
longitude: number;
|
|
195
|
+
/** Latitude of the location */
|
|
196
|
+
latitude: number;
|
|
197
|
+
/** Name of the location */
|
|
198
|
+
name?: string;
|
|
199
|
+
/** Address of the location */
|
|
200
|
+
address?: string;
|
|
201
|
+
}
|
|
202
|
+
interface SendLocationOptions extends SendMessageOptions {
|
|
203
|
+
/** Location configuration */
|
|
204
|
+
location: LocationObject;
|
|
205
|
+
/** Message ID to reply to */
|
|
206
|
+
replyTo?: string;
|
|
207
|
+
}
|
|
208
|
+
interface ContactName {
|
|
209
|
+
/** Full formatted name */
|
|
210
|
+
formatted_name: string;
|
|
211
|
+
/** First name */
|
|
212
|
+
first_name?: string;
|
|
213
|
+
/** Last name */
|
|
214
|
+
last_name?: string;
|
|
215
|
+
/** Middle name */
|
|
216
|
+
middle_name?: string;
|
|
217
|
+
/** Suffix (e.g., Jr., Sr.) */
|
|
218
|
+
suffix?: string;
|
|
219
|
+
/** Prefix (e.g., Mr., Mrs., Dr.) */
|
|
220
|
+
prefix?: string;
|
|
221
|
+
}
|
|
222
|
+
interface ContactPhone {
|
|
223
|
+
/** Phone number */
|
|
224
|
+
phone: string;
|
|
225
|
+
/** Type of phone number */
|
|
226
|
+
type?: 'CELL' | 'MAIN' | 'IPHONE' | 'HOME' | 'WORK';
|
|
227
|
+
/** WhatsApp ID (optional) */
|
|
228
|
+
wa_id?: string;
|
|
229
|
+
}
|
|
230
|
+
interface ContactEmail {
|
|
231
|
+
/** Email address */
|
|
232
|
+
email: string;
|
|
233
|
+
/** Type of email */
|
|
234
|
+
type?: 'HOME' | 'WORK';
|
|
235
|
+
}
|
|
236
|
+
interface ContactAddress {
|
|
237
|
+
/** Street address */
|
|
238
|
+
street?: string;
|
|
239
|
+
/** City */
|
|
240
|
+
city?: string;
|
|
241
|
+
/** State or province */
|
|
242
|
+
state?: string;
|
|
243
|
+
/** ZIP or postal code */
|
|
244
|
+
zip?: string;
|
|
245
|
+
/** Country */
|
|
246
|
+
country?: string;
|
|
247
|
+
/** Country code (ISO 3166-1 alpha-2) */
|
|
248
|
+
country_code?: string;
|
|
249
|
+
/** Type of address */
|
|
250
|
+
type?: 'HOME' | 'WORK';
|
|
251
|
+
}
|
|
252
|
+
interface ContactUrl {
|
|
253
|
+
/** URL */
|
|
254
|
+
url: string;
|
|
255
|
+
/** Type of URL */
|
|
256
|
+
type?: 'HOME' | 'WORK';
|
|
257
|
+
}
|
|
258
|
+
interface ContactOrg {
|
|
259
|
+
/** Company name */
|
|
260
|
+
company?: string;
|
|
261
|
+
/** Department */
|
|
262
|
+
department?: string;
|
|
263
|
+
/** Job title */
|
|
264
|
+
title?: string;
|
|
265
|
+
}
|
|
266
|
+
interface Contact {
|
|
267
|
+
/** Contact's name (required) */
|
|
268
|
+
name: ContactName;
|
|
269
|
+
/** Phone numbers */
|
|
270
|
+
phones?: ContactPhone[];
|
|
271
|
+
/** Email addresses */
|
|
272
|
+
emails?: ContactEmail[];
|
|
273
|
+
/** Addresses */
|
|
274
|
+
addresses?: ContactAddress[];
|
|
275
|
+
/** URLs */
|
|
276
|
+
urls?: ContactUrl[];
|
|
277
|
+
/** Organization information */
|
|
278
|
+
org?: ContactOrg;
|
|
279
|
+
/** Birthday in YYYY-MM-DD format */
|
|
280
|
+
birthday?: string;
|
|
281
|
+
}
|
|
282
|
+
interface SendContactsOptions extends SendMessageOptions {
|
|
283
|
+
/** Array of contacts to send */
|
|
284
|
+
contacts: Contact[];
|
|
285
|
+
/** Message ID to reply to */
|
|
286
|
+
replyTo?: string;
|
|
287
|
+
}
|
|
288
|
+
interface MarkAsReadOptions {
|
|
289
|
+
/** Meta Phone Number ID */
|
|
290
|
+
phoneNumberId: string;
|
|
291
|
+
/** Message ID to mark as read */
|
|
292
|
+
messageId: string;
|
|
293
|
+
}
|
|
294
|
+
interface MarkAsReadResponseData {
|
|
295
|
+
success: boolean;
|
|
296
|
+
}
|
|
168
297
|
interface InteractiveButton {
|
|
169
298
|
type: 'reply';
|
|
170
299
|
reply: {
|
|
@@ -236,6 +365,40 @@ interface PhoneNumber {
|
|
|
236
365
|
verified_name: string;
|
|
237
366
|
quality_rating?: string;
|
|
238
367
|
}
|
|
368
|
+
/** Phone number profile from Meta Graph API */
|
|
369
|
+
interface MetaPhoneNumberInfo {
|
|
370
|
+
id: string;
|
|
371
|
+
verified_name: string;
|
|
372
|
+
display_phone_number: string;
|
|
373
|
+
quality_rating: "GREEN" | "YELLOW" | "RED" | "UNKNOWN";
|
|
374
|
+
code_verification_status: "VERIFIED" | "NOT_VERIFIED" | "EXPIRED";
|
|
375
|
+
is_official_business_account: boolean;
|
|
376
|
+
is_pin_enabled: boolean;
|
|
377
|
+
name_status: "APPROVED" | "PENDING" | "DECLINED" | "NONE";
|
|
378
|
+
new_name_status?: "APPROVED" | "PENDING" | "DECLINED" | "NONE";
|
|
379
|
+
messaging_limit_tier?: string;
|
|
380
|
+
platform_type?: string;
|
|
381
|
+
throughput?: {
|
|
382
|
+
level: string;
|
|
383
|
+
};
|
|
384
|
+
account_mode?: "LIVE" | "SANDBOX";
|
|
385
|
+
}
|
|
386
|
+
/** Business profile from Meta Graph API */
|
|
387
|
+
interface MetaBusinessProfile {
|
|
388
|
+
about?: string;
|
|
389
|
+
address?: string;
|
|
390
|
+
description?: string;
|
|
391
|
+
email?: string;
|
|
392
|
+
messaging_product: string;
|
|
393
|
+
profile_picture_url?: string;
|
|
394
|
+
vertical?: string;
|
|
395
|
+
websites?: string[];
|
|
396
|
+
}
|
|
397
|
+
/** Combined phone number profile response */
|
|
398
|
+
interface PhoneNumberProfile {
|
|
399
|
+
phone_number: MetaPhoneNumberInfo;
|
|
400
|
+
business_profile: MetaBusinessProfile;
|
|
401
|
+
}
|
|
239
402
|
interface UsagePeriod {
|
|
240
403
|
start: string;
|
|
241
404
|
end: string;
|
|
@@ -431,6 +594,100 @@ declare class Messages {
|
|
|
431
594
|
* ```
|
|
432
595
|
*/
|
|
433
596
|
sendInteractive(options: SendInteractiveOptions): Promise<ApiResponse<MessageResponseData>>;
|
|
597
|
+
/**
|
|
598
|
+
* Send a sticker message
|
|
599
|
+
*
|
|
600
|
+
* @param options - Sticker message options
|
|
601
|
+
* @returns Message response with message ID
|
|
602
|
+
*
|
|
603
|
+
* @example
|
|
604
|
+
* ```typescript
|
|
605
|
+
* // Send sticker by URL
|
|
606
|
+
* const result = await client.messages.sendSticker({
|
|
607
|
+
* phoneNumberId: '123456789',
|
|
608
|
+
* to: '+6281234567890',
|
|
609
|
+
* sticker: {
|
|
610
|
+
* link: 'https://example.com/sticker.webp',
|
|
611
|
+
* },
|
|
612
|
+
* });
|
|
613
|
+
*
|
|
614
|
+
* // Send sticker by media ID
|
|
615
|
+
* await client.messages.sendSticker({
|
|
616
|
+
* phoneNumberId: '123456789',
|
|
617
|
+
* to: '+6281234567890',
|
|
618
|
+
* sticker: {
|
|
619
|
+
* id: 'media_id_here',
|
|
620
|
+
* },
|
|
621
|
+
* });
|
|
622
|
+
* ```
|
|
623
|
+
*/
|
|
624
|
+
sendSticker(options: SendStickerOptions): Promise<ApiResponse<MessageResponseData>>;
|
|
625
|
+
/**
|
|
626
|
+
* Send a location message
|
|
627
|
+
*
|
|
628
|
+
* @param options - Location message options
|
|
629
|
+
* @returns Message response with message ID
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* ```typescript
|
|
633
|
+
* const result = await client.messages.sendLocation({
|
|
634
|
+
* phoneNumberId: '123456789',
|
|
635
|
+
* to: '+6281234567890',
|
|
636
|
+
* location: {
|
|
637
|
+
* latitude: -6.2088,
|
|
638
|
+
* longitude: 106.8456,
|
|
639
|
+
* name: 'Monas',
|
|
640
|
+
* address: 'Gambir, Central Jakarta, Indonesia',
|
|
641
|
+
* },
|
|
642
|
+
* });
|
|
643
|
+
* ```
|
|
644
|
+
*/
|
|
645
|
+
sendLocation(options: SendLocationOptions): Promise<ApiResponse<MessageResponseData>>;
|
|
646
|
+
/**
|
|
647
|
+
* Send contact cards
|
|
648
|
+
*
|
|
649
|
+
* @param options - Contact message options
|
|
650
|
+
* @returns Message response with message ID
|
|
651
|
+
*
|
|
652
|
+
* @example
|
|
653
|
+
* ```typescript
|
|
654
|
+
* const result = await client.messages.sendContacts({
|
|
655
|
+
* phoneNumberId: '123456789',
|
|
656
|
+
* to: '+6281234567890',
|
|
657
|
+
* contacts: [
|
|
658
|
+
* {
|
|
659
|
+
* name: {
|
|
660
|
+
* formatted_name: 'John Doe',
|
|
661
|
+
* first_name: 'John',
|
|
662
|
+
* last_name: 'Doe',
|
|
663
|
+
* },
|
|
664
|
+
* phones: [
|
|
665
|
+
* { phone: '+6281234567890', type: 'CELL' },
|
|
666
|
+
* ],
|
|
667
|
+
* emails: [
|
|
668
|
+
* { email: 'john@example.com', type: 'WORK' },
|
|
669
|
+
* ],
|
|
670
|
+
* },
|
|
671
|
+
* ],
|
|
672
|
+
* });
|
|
673
|
+
* ```
|
|
674
|
+
*/
|
|
675
|
+
sendContacts(options: SendContactsOptions): Promise<ApiResponse<MessageResponseData>>;
|
|
676
|
+
/**
|
|
677
|
+
* Mark a message as read
|
|
678
|
+
*
|
|
679
|
+
* @param options - Mark as read options
|
|
680
|
+
* @returns Success response
|
|
681
|
+
*
|
|
682
|
+
* @example
|
|
683
|
+
* ```typescript
|
|
684
|
+
* await client.messages.markAsRead({
|
|
685
|
+
* phoneNumberId: '123456789',
|
|
686
|
+
* messageId: 'wamid.xxx',
|
|
687
|
+
* });
|
|
688
|
+
* ```
|
|
689
|
+
*/
|
|
690
|
+
markAsRead(options: MarkAsReadOptions): Promise<ApiResponse<MarkAsReadResponseData>>;
|
|
434
691
|
}
|
|
435
692
|
|
|
436
693
|
/**
|
|
@@ -469,6 +726,7 @@ declare class Templates {
|
|
|
469
726
|
* @example
|
|
470
727
|
* ```typescript
|
|
471
728
|
* const phoneNumbers = await client.phoneNumbers.list();
|
|
729
|
+
* const profile = await client.phoneNumbers.getProfile('123456');
|
|
472
730
|
* ```
|
|
473
731
|
*/
|
|
474
732
|
declare class PhoneNumbers {
|
|
@@ -488,6 +746,60 @@ declare class PhoneNumbers {
|
|
|
488
746
|
* ```
|
|
489
747
|
*/
|
|
490
748
|
list(): Promise<ApiResponse<PhoneNumber[]>>;
|
|
749
|
+
/**
|
|
750
|
+
* Get a specific phone number by ID
|
|
751
|
+
*
|
|
752
|
+
* @param id - The phone number ID (from list response)
|
|
753
|
+
* @returns Phone number details
|
|
754
|
+
*
|
|
755
|
+
* @example
|
|
756
|
+
* ```typescript
|
|
757
|
+
* const phone = await client.phoneNumbers.get('phone-number-uuid');
|
|
758
|
+
* console.log(phone.data.display_phone_number);
|
|
759
|
+
* ```
|
|
760
|
+
*/
|
|
761
|
+
get(id: string): Promise<ApiResponse<PhoneNumber>>;
|
|
762
|
+
/**
|
|
763
|
+
* Get phone number profile from Meta Graph API
|
|
764
|
+
*
|
|
765
|
+
* Returns detailed information including quality rating, verification status,
|
|
766
|
+
* messaging limits, and business profile.
|
|
767
|
+
*
|
|
768
|
+
* @param id - The phone number ID
|
|
769
|
+
* @returns Phone number profile with Meta API details
|
|
770
|
+
*
|
|
771
|
+
* @example
|
|
772
|
+
* ```typescript
|
|
773
|
+
* const profile = await client.phoneNumbers.getProfile('phone-number-uuid');
|
|
774
|
+
* console.log('Quality:', profile.data.phone_number.quality_rating);
|
|
775
|
+
* console.log('Name:', profile.data.business_profile.about);
|
|
776
|
+
* ```
|
|
777
|
+
*/
|
|
778
|
+
getProfile(id: string): Promise<ApiResponse<PhoneNumberProfile>>;
|
|
779
|
+
/**
|
|
780
|
+
* Update business profile for a phone number
|
|
781
|
+
*
|
|
782
|
+
* @param id - The phone number ID
|
|
783
|
+
* @param profile - Profile fields to update
|
|
784
|
+
* @returns Updated business profile
|
|
785
|
+
*
|
|
786
|
+
* @example
|
|
787
|
+
* ```typescript
|
|
788
|
+
* const updated = await client.phoneNumbers.updateProfile('phone-number-uuid', {
|
|
789
|
+
* about: 'We help businesses grow',
|
|
790
|
+
* description: 'Customer support',
|
|
791
|
+
* email: 'support@example.com',
|
|
792
|
+
* });
|
|
793
|
+
* ```
|
|
794
|
+
*/
|
|
795
|
+
updateProfile(id: string, profile: {
|
|
796
|
+
about?: string;
|
|
797
|
+
address?: string;
|
|
798
|
+
description?: string;
|
|
799
|
+
email?: string;
|
|
800
|
+
vertical?: string;
|
|
801
|
+
websites?: string[];
|
|
802
|
+
}): Promise<ApiResponse<PhoneNumberProfile['business_profile']>>;
|
|
491
803
|
}
|
|
492
804
|
|
|
493
805
|
/**
|
|
@@ -768,4 +1080,4 @@ declare class NetworkError extends SembojaError {
|
|
|
768
1080
|
* @packageDocumentation
|
|
769
1081
|
*/
|
|
770
1082
|
|
|
771
|
-
export { type ApiErrorResponse, type ApiResponse, AuthenticationError, type ClientOptions, type InteractiveButton, type InteractiveListSection, type InteractiveMessage, type ListTemplatesOptions, type MediaObject, type MessageContact, type MessageResponseData, type MessageResult, type MessageType, NetworkError, NotFoundError, type PhoneNumber, RateLimitError, SembojaClient, SembojaError, type SendAudioOptions, type SendDocumentOptions, type SendImageOptions, type SendInteractiveOptions, type SendMessageOptions, type SendReactionOptions, type SendTemplateOptions, type SendTextOptions, type SendVideoOptions, ServerError, type Template, type TemplateComponent, type TemplateInfo, type TemplateLanguage, type TemplateParameter, type TemplateStatus, type TriggerWebhookOptions, type UsageData, type UsageMessages, type UsagePeriod, ValidationError, type VerifyWebhookOptions, SembojaClient as default, parseWebhookPayload, verifyWebhookSignature };
|
|
1083
|
+
export { type ApiErrorResponse, type ApiResponse, AuthenticationError, type ClientOptions, type Contact, type ContactAddress, type ContactEmail, type ContactName, type ContactOrg, type ContactPhone, type ContactUrl, type InteractiveButton, type InteractiveListSection, type InteractiveMessage, type ListTemplatesOptions, type LocationObject, type MarkAsReadOptions, type MarkAsReadResponseData, type MediaObject, type MessageContact, type MessageResponseData, type MessageResult, type MessageType, type MetaBusinessProfile, type MetaPhoneNumberInfo, NetworkError, NotFoundError, type PhoneNumber, type PhoneNumberProfile, RateLimitError, SembojaClient, SembojaError, type SendAudioOptions, type SendContactsOptions, type SendDocumentOptions, type SendImageOptions, type SendInteractiveOptions, type SendLocationOptions, type SendMessageOptions, type SendReactionOptions, type SendStickerOptions, type SendTemplateOptions, type SendTextOptions, type SendVideoOptions, ServerError, type StickerObject, type Template, type TemplateComponent, type TemplateInfo, type TemplateLanguage, type TemplateParameter, type TemplateStatus, type TriggerWebhookOptions, type UsageData, type UsageMessages, type UsagePeriod, ValidationError, type VerifyWebhookOptions, SembojaClient as default, parseWebhookPayload, verifyWebhookSignature };
|
package/dist/index.js
CHANGED
|
@@ -200,6 +200,24 @@ var HttpClient = class {
|
|
|
200
200
|
async post(path, body) {
|
|
201
201
|
return this.request({ method: "POST", path, body });
|
|
202
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* PUT request
|
|
205
|
+
*/
|
|
206
|
+
async put(path, body) {
|
|
207
|
+
return this.request({ method: "PUT", path, body });
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* PATCH request
|
|
211
|
+
*/
|
|
212
|
+
async patch(path, body) {
|
|
213
|
+
return this.request({ method: "PATCH", path, body });
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* DELETE request
|
|
217
|
+
*/
|
|
218
|
+
async delete(path) {
|
|
219
|
+
return this.request({ method: "DELETE", path });
|
|
220
|
+
}
|
|
203
221
|
};
|
|
204
222
|
|
|
205
223
|
// src/resources/messages.ts
|
|
@@ -417,6 +435,131 @@ var Messages = class {
|
|
|
417
435
|
context: options.replyTo ? { message_id: options.replyTo } : void 0
|
|
418
436
|
});
|
|
419
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* Send a sticker message
|
|
440
|
+
*
|
|
441
|
+
* @param options - Sticker message options
|
|
442
|
+
* @returns Message response with message ID
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```typescript
|
|
446
|
+
* // Send sticker by URL
|
|
447
|
+
* const result = await client.messages.sendSticker({
|
|
448
|
+
* phoneNumberId: '123456789',
|
|
449
|
+
* to: '+6281234567890',
|
|
450
|
+
* sticker: {
|
|
451
|
+
* link: 'https://example.com/sticker.webp',
|
|
452
|
+
* },
|
|
453
|
+
* });
|
|
454
|
+
*
|
|
455
|
+
* // Send sticker by media ID
|
|
456
|
+
* await client.messages.sendSticker({
|
|
457
|
+
* phoneNumberId: '123456789',
|
|
458
|
+
* to: '+6281234567890',
|
|
459
|
+
* sticker: {
|
|
460
|
+
* id: 'media_id_here',
|
|
461
|
+
* },
|
|
462
|
+
* });
|
|
463
|
+
* ```
|
|
464
|
+
*/
|
|
465
|
+
async sendSticker(options) {
|
|
466
|
+
return this.http.post("/api/v1/messages", {
|
|
467
|
+
phone_number_id: options.phoneNumberId,
|
|
468
|
+
to: options.to,
|
|
469
|
+
type: "sticker",
|
|
470
|
+
sticker: options.sticker,
|
|
471
|
+
context: options.replyTo ? { message_id: options.replyTo } : void 0
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Send a location message
|
|
476
|
+
*
|
|
477
|
+
* @param options - Location message options
|
|
478
|
+
* @returns Message response with message ID
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```typescript
|
|
482
|
+
* const result = await client.messages.sendLocation({
|
|
483
|
+
* phoneNumberId: '123456789',
|
|
484
|
+
* to: '+6281234567890',
|
|
485
|
+
* location: {
|
|
486
|
+
* latitude: -6.2088,
|
|
487
|
+
* longitude: 106.8456,
|
|
488
|
+
* name: 'Monas',
|
|
489
|
+
* address: 'Gambir, Central Jakarta, Indonesia',
|
|
490
|
+
* },
|
|
491
|
+
* });
|
|
492
|
+
* ```
|
|
493
|
+
*/
|
|
494
|
+
async sendLocation(options) {
|
|
495
|
+
return this.http.post("/api/v1/messages", {
|
|
496
|
+
phone_number_id: options.phoneNumberId,
|
|
497
|
+
to: options.to,
|
|
498
|
+
type: "location",
|
|
499
|
+
location: options.location,
|
|
500
|
+
context: options.replyTo ? { message_id: options.replyTo } : void 0
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Send contact cards
|
|
505
|
+
*
|
|
506
|
+
* @param options - Contact message options
|
|
507
|
+
* @returns Message response with message ID
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* ```typescript
|
|
511
|
+
* const result = await client.messages.sendContacts({
|
|
512
|
+
* phoneNumberId: '123456789',
|
|
513
|
+
* to: '+6281234567890',
|
|
514
|
+
* contacts: [
|
|
515
|
+
* {
|
|
516
|
+
* name: {
|
|
517
|
+
* formatted_name: 'John Doe',
|
|
518
|
+
* first_name: 'John',
|
|
519
|
+
* last_name: 'Doe',
|
|
520
|
+
* },
|
|
521
|
+
* phones: [
|
|
522
|
+
* { phone: '+6281234567890', type: 'CELL' },
|
|
523
|
+
* ],
|
|
524
|
+
* emails: [
|
|
525
|
+
* { email: 'john@example.com', type: 'WORK' },
|
|
526
|
+
* ],
|
|
527
|
+
* },
|
|
528
|
+
* ],
|
|
529
|
+
* });
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
async sendContacts(options) {
|
|
533
|
+
return this.http.post("/api/v1/messages", {
|
|
534
|
+
phone_number_id: options.phoneNumberId,
|
|
535
|
+
to: options.to,
|
|
536
|
+
type: "contacts",
|
|
537
|
+
contacts: options.contacts,
|
|
538
|
+
context: options.replyTo ? { message_id: options.replyTo } : void 0
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Mark a message as read
|
|
543
|
+
*
|
|
544
|
+
* @param options - Mark as read options
|
|
545
|
+
* @returns Success response
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
* ```typescript
|
|
549
|
+
* await client.messages.markAsRead({
|
|
550
|
+
* phoneNumberId: '123456789',
|
|
551
|
+
* messageId: 'wamid.xxx',
|
|
552
|
+
* });
|
|
553
|
+
* ```
|
|
554
|
+
*/
|
|
555
|
+
async markAsRead(options) {
|
|
556
|
+
return this.http.post("/api/v1/messages", {
|
|
557
|
+
phone_number_id: options.phoneNumberId,
|
|
558
|
+
messaging_product: "whatsapp",
|
|
559
|
+
status: "read",
|
|
560
|
+
message_id: options.messageId
|
|
561
|
+
});
|
|
562
|
+
}
|
|
420
563
|
};
|
|
421
564
|
|
|
422
565
|
// src/resources/templates.ts
|
|
@@ -469,6 +612,59 @@ var PhoneNumbers = class {
|
|
|
469
612
|
async list() {
|
|
470
613
|
return this.http.get("/api/v1/phone-numbers");
|
|
471
614
|
}
|
|
615
|
+
/**
|
|
616
|
+
* Get a specific phone number by ID
|
|
617
|
+
*
|
|
618
|
+
* @param id - The phone number ID (from list response)
|
|
619
|
+
* @returns Phone number details
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* ```typescript
|
|
623
|
+
* const phone = await client.phoneNumbers.get('phone-number-uuid');
|
|
624
|
+
* console.log(phone.data.display_phone_number);
|
|
625
|
+
* ```
|
|
626
|
+
*/
|
|
627
|
+
async get(id) {
|
|
628
|
+
return this.http.get(`/api/v1/phone-numbers/${id}`);
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Get phone number profile from Meta Graph API
|
|
632
|
+
*
|
|
633
|
+
* Returns detailed information including quality rating, verification status,
|
|
634
|
+
* messaging limits, and business profile.
|
|
635
|
+
*
|
|
636
|
+
* @param id - The phone number ID
|
|
637
|
+
* @returns Phone number profile with Meta API details
|
|
638
|
+
*
|
|
639
|
+
* @example
|
|
640
|
+
* ```typescript
|
|
641
|
+
* const profile = await client.phoneNumbers.getProfile('phone-number-uuid');
|
|
642
|
+
* console.log('Quality:', profile.data.phone_number.quality_rating);
|
|
643
|
+
* console.log('Name:', profile.data.business_profile.about);
|
|
644
|
+
* ```
|
|
645
|
+
*/
|
|
646
|
+
async getProfile(id) {
|
|
647
|
+
return this.http.get(`/api/v1/phone-numbers/${id}/profile`);
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Update business profile for a phone number
|
|
651
|
+
*
|
|
652
|
+
* @param id - The phone number ID
|
|
653
|
+
* @param profile - Profile fields to update
|
|
654
|
+
* @returns Updated business profile
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* ```typescript
|
|
658
|
+
* const updated = await client.phoneNumbers.updateProfile('phone-number-uuid', {
|
|
659
|
+
* about: 'We help businesses grow',
|
|
660
|
+
* description: 'Customer support',
|
|
661
|
+
* email: 'support@example.com',
|
|
662
|
+
* });
|
|
663
|
+
* ```
|
|
664
|
+
*/
|
|
665
|
+
async updateProfile(id, profile) {
|
|
666
|
+
return this.http.patch(`/api/v1/phone-numbers/${id}/profile`, profile);
|
|
667
|
+
}
|
|
472
668
|
};
|
|
473
669
|
|
|
474
670
|
// src/resources/usage.ts
|