@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 CHANGED
@@ -143,6 +143,54 @@ await client.messages.sendInteractive({
143
143
  },
144
144
  },
145
145
  });
146
+
147
+ // Sticker message
148
+ await client.messages.sendSticker({
149
+ phoneNumberId: '123456789',
150
+ to: '+6281234567890',
151
+ sticker: {
152
+ link: 'https://example.com/sticker.webp',
153
+ },
154
+ });
155
+
156
+ // Location message
157
+ await client.messages.sendLocation({
158
+ phoneNumberId: '123456789',
159
+ to: '+6281234567890',
160
+ location: {
161
+ latitude: -6.2088,
162
+ longitude: 106.8456,
163
+ name: 'Monas',
164
+ address: 'Gambir, Central Jakarta, Indonesia',
165
+ },
166
+ });
167
+
168
+ // Contact card
169
+ await client.messages.sendContacts({
170
+ phoneNumberId: '123456789',
171
+ to: '+6281234567890',
172
+ contacts: [
173
+ {
174
+ name: {
175
+ formatted_name: 'John Doe',
176
+ first_name: 'John',
177
+ last_name: 'Doe',
178
+ },
179
+ phones: [
180
+ { phone: '+6281234567890', type: 'CELL' },
181
+ ],
182
+ emails: [
183
+ { email: 'john@example.com', type: 'WORK' },
184
+ ],
185
+ },
186
+ ],
187
+ });
188
+
189
+ // Mark message as read
190
+ await client.messages.markAsRead({
191
+ phoneNumberId: '123456789',
192
+ messageId: 'wamid.xxx',
193
+ });
146
194
  ```
147
195
 
148
196
  ### Templates
@@ -274,8 +322,12 @@ try {
274
322
  | `sendVideo(options)` | Send a video |
275
323
  | `sendAudio(options)` | Send an audio file |
276
324
  | `sendDocument(options)` | Send a document |
325
+ | `sendSticker(options)` | Send a sticker (WebP) |
326
+ | `sendLocation(options)` | Send a location |
327
+ | `sendContacts(options)` | Send contact cards |
277
328
  | `sendReaction(options)` | Send a reaction |
278
329
  | `sendInteractive(options)` | Send interactive message |
330
+ | `markAsRead(options)` | Mark a message as read |
279
331
 
280
332
  ### Error Classes
281
333
 
package/dist/index.d.mts 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 };