@zapyapi/sdk 1.0.0-beta.2 → 1.0.0-beta.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.
- package/index.cjs +265 -1
- package/index.js +265 -1
- package/package.json +1 -1
- package/src/generated/Api.d.ts +554 -0
- package/src/generated/Api.d.ts.map +1 -1
- package/src/index.d.ts +1 -1
- package/src/index.d.ts.map +1 -1
- package/src/resources/instances.resource.d.ts +106 -1
- package/src/resources/instances.resource.d.ts.map +1 -1
- package/src/resources/messages.resource.d.ts +70 -1
- package/src/resources/messages.resource.d.ts.map +1 -1
- package/src/types/index.d.ts +2 -2
- package/src/types/index.d.ts.map +1 -1
- package/src/types/instances.types.d.ts +99 -0
- package/src/types/instances.types.d.ts.map +1 -1
- package/src/types/messages.types.d.ts +67 -0
- package/src/types/messages.types.d.ts.map +1 -1
- package/src/version.d.ts +1 -1
package/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var axios = require('axios');
|
|
4
4
|
|
|
5
5
|
/** SDK version - auto-generated from package.json */
|
|
6
|
-
const SDK_VERSION = '1.0.0-beta.
|
|
6
|
+
const SDK_VERSION = '1.0.0-beta.3';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Custom error classes for @zapyapi/sdk
|
|
@@ -428,6 +428,121 @@ class MessagesResource extends BaseResource {
|
|
|
428
428
|
this.handleError(error);
|
|
429
429
|
}
|
|
430
430
|
}
|
|
431
|
+
/**
|
|
432
|
+
* Send a location message
|
|
433
|
+
*
|
|
434
|
+
* @param instanceId - Instance ID
|
|
435
|
+
* @param options - Location message options
|
|
436
|
+
* @returns Message response with ID and status
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* await client.messages.sendLocation('my-instance', {
|
|
440
|
+
* to: '5511999999999',
|
|
441
|
+
* latitude: -23.5505,
|
|
442
|
+
* longitude: -46.6333,
|
|
443
|
+
* name: 'São Paulo',
|
|
444
|
+
* address: 'São Paulo, Brazil'
|
|
445
|
+
* });
|
|
446
|
+
*/
|
|
447
|
+
async sendLocation(instanceId, options) {
|
|
448
|
+
try {
|
|
449
|
+
const response = await this.http.post(`/message/${instanceId}/location`, {
|
|
450
|
+
to: options.to,
|
|
451
|
+
latitude: options.latitude,
|
|
452
|
+
longitude: options.longitude,
|
|
453
|
+
name: options.name,
|
|
454
|
+
address: options.address,
|
|
455
|
+
quoteMessageId: options.quotedMessageId
|
|
456
|
+
});
|
|
457
|
+
return response.data;
|
|
458
|
+
} catch (error) {
|
|
459
|
+
this.handleError(error);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Send a contact card message
|
|
464
|
+
*
|
|
465
|
+
* @param instanceId - Instance ID
|
|
466
|
+
* @param options - Contact message options
|
|
467
|
+
* @returns Message response with ID and status
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* await client.messages.sendContact('my-instance', {
|
|
471
|
+
* to: '5511999999999',
|
|
472
|
+
* contact: {
|
|
473
|
+
* fullName: 'John Doe',
|
|
474
|
+
* phoneNumber: '+5511988887777',
|
|
475
|
+
* organization: 'Acme Inc'
|
|
476
|
+
* }
|
|
477
|
+
* });
|
|
478
|
+
*/
|
|
479
|
+
async sendContact(instanceId, options) {
|
|
480
|
+
try {
|
|
481
|
+
const response = await this.http.post(`/message/${instanceId}/contact`, {
|
|
482
|
+
to: options.to,
|
|
483
|
+
contact: options.contact,
|
|
484
|
+
quoteMessageId: options.quotedMessageId
|
|
485
|
+
});
|
|
486
|
+
return response.data;
|
|
487
|
+
} catch (error) {
|
|
488
|
+
this.handleError(error);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Send a sticker message
|
|
493
|
+
*
|
|
494
|
+
* @param instanceId - Instance ID
|
|
495
|
+
* @param options - Sticker message options
|
|
496
|
+
* @returns Message response with ID and status
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* await client.messages.sendSticker('my-instance', {
|
|
500
|
+
* to: '5511999999999',
|
|
501
|
+
* url: 'https://example.com/sticker.webp'
|
|
502
|
+
* });
|
|
503
|
+
*/
|
|
504
|
+
async sendSticker(instanceId, options) {
|
|
505
|
+
try {
|
|
506
|
+
const response = await this.http.post(`/message/${instanceId}/sticker`, {
|
|
507
|
+
to: options.to,
|
|
508
|
+
url: options.url,
|
|
509
|
+
base64: options.base64,
|
|
510
|
+
quoteMessageId: options.quotedMessageId
|
|
511
|
+
});
|
|
512
|
+
return response.data;
|
|
513
|
+
} catch (error) {
|
|
514
|
+
this.handleError(error);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Send a reaction to a message
|
|
519
|
+
*
|
|
520
|
+
* @param instanceId - Instance ID
|
|
521
|
+
* @param options - Reaction options
|
|
522
|
+
*
|
|
523
|
+
* @example
|
|
524
|
+
* // Add a reaction
|
|
525
|
+
* await client.messages.sendReaction('my-instance', {
|
|
526
|
+
* messageId: 'ABC123...',
|
|
527
|
+
* reaction: '👍'
|
|
528
|
+
* });
|
|
529
|
+
*
|
|
530
|
+
* // Remove a reaction
|
|
531
|
+
* await client.messages.sendReaction('my-instance', {
|
|
532
|
+
* messageId: 'ABC123...',
|
|
533
|
+
* reaction: ''
|
|
534
|
+
* });
|
|
535
|
+
*/
|
|
536
|
+
async sendReaction(instanceId, options) {
|
|
537
|
+
try {
|
|
538
|
+
await this.http.post(`/message/${instanceId}/reaction`, {
|
|
539
|
+
messageId: options.messageId,
|
|
540
|
+
reaction: options.reaction
|
|
541
|
+
});
|
|
542
|
+
} catch (error) {
|
|
543
|
+
this.handleError(error);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
431
546
|
}
|
|
432
547
|
|
|
433
548
|
/**
|
|
@@ -691,6 +806,155 @@ class InstancesResource extends BaseResource {
|
|
|
691
806
|
this.handleError(error);
|
|
692
807
|
}
|
|
693
808
|
}
|
|
809
|
+
/**
|
|
810
|
+
* Check if phone numbers are registered on WhatsApp
|
|
811
|
+
*
|
|
812
|
+
* This method verifies if the provided phone numbers are registered on WhatsApp.
|
|
813
|
+
* Useful for validating contacts before sending messages.
|
|
814
|
+
*
|
|
815
|
+
* @param instanceId - Instance ID (must be connected)
|
|
816
|
+
* @param numbers - Array of phone numbers to check (with country code, e.g., "5511999999999")
|
|
817
|
+
* @returns Results indicating which numbers are registered on WhatsApp
|
|
818
|
+
*
|
|
819
|
+
* @example
|
|
820
|
+
* const result = await client.instances.checkNumbers('my-instance', [
|
|
821
|
+
* '5511999999999',
|
|
822
|
+
* '5521888888888'
|
|
823
|
+
* ]);
|
|
824
|
+
*
|
|
825
|
+
* for (const check of result.results) {
|
|
826
|
+
* if (check.exists) {
|
|
827
|
+
* console.log(`${check.number} is on WhatsApp (JID: ${check.jid})`);
|
|
828
|
+
* } else {
|
|
829
|
+
* console.log(`${check.number} is NOT on WhatsApp`);
|
|
830
|
+
* }
|
|
831
|
+
* }
|
|
832
|
+
*/
|
|
833
|
+
async checkNumbers(instanceId, numbers) {
|
|
834
|
+
try {
|
|
835
|
+
const response = await this.http.post(`/instances/${instanceId}/check-numbers`, {
|
|
836
|
+
numbers
|
|
837
|
+
});
|
|
838
|
+
return response.data;
|
|
839
|
+
} catch (error) {
|
|
840
|
+
this.handleError(error);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Send a presence update (typing indicator, online status, etc.)
|
|
845
|
+
*
|
|
846
|
+
* Use this to show typing indicators or update online status for a contact.
|
|
847
|
+
*
|
|
848
|
+
* @param instanceId - Instance ID (must be connected)
|
|
849
|
+
* @param options - Presence options
|
|
850
|
+
*
|
|
851
|
+
* @example
|
|
852
|
+
* // Show typing indicator
|
|
853
|
+
* await client.instances.sendPresence('my-instance', {
|
|
854
|
+
* to: '5511999999999',
|
|
855
|
+
* presence: 'composing'
|
|
856
|
+
* });
|
|
857
|
+
*
|
|
858
|
+
* // Show recording audio indicator
|
|
859
|
+
* await client.instances.sendPresence('my-instance', {
|
|
860
|
+
* to: '5511999999999',
|
|
861
|
+
* presence: 'recording'
|
|
862
|
+
* });
|
|
863
|
+
*
|
|
864
|
+
* // Stop typing indicator
|
|
865
|
+
* await client.instances.sendPresence('my-instance', {
|
|
866
|
+
* to: '5511999999999',
|
|
867
|
+
* presence: 'paused'
|
|
868
|
+
* });
|
|
869
|
+
*/
|
|
870
|
+
async sendPresence(instanceId, options) {
|
|
871
|
+
try {
|
|
872
|
+
await this.http.post(`/instances/${instanceId}/presence`, {
|
|
873
|
+
to: options.to,
|
|
874
|
+
presence: options.presence
|
|
875
|
+
});
|
|
876
|
+
} catch (error) {
|
|
877
|
+
this.handleError(error);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Get profile picture URL for a contact
|
|
882
|
+
*
|
|
883
|
+
* @param instanceId - Instance ID (must be connected)
|
|
884
|
+
* @param phone - Phone number or JID of the contact
|
|
885
|
+
* @returns Profile picture response with URL (null if not available)
|
|
886
|
+
*
|
|
887
|
+
* @example
|
|
888
|
+
* const result = await client.instances.getProfilePicture('my-instance', '5511999999999');
|
|
889
|
+
* if (result.url) {
|
|
890
|
+
* console.log('Profile picture:', result.url);
|
|
891
|
+
* } else {
|
|
892
|
+
* console.log('No profile picture available');
|
|
893
|
+
* }
|
|
894
|
+
*/
|
|
895
|
+
async getProfilePicture(instanceId, phone) {
|
|
896
|
+
try {
|
|
897
|
+
const response = await this.http.get(`/instances/${instanceId}/contacts/${phone}/profile-picture`);
|
|
898
|
+
return response.data;
|
|
899
|
+
} catch (error) {
|
|
900
|
+
this.handleError(error);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Block a contact
|
|
905
|
+
*
|
|
906
|
+
* @param instanceId - Instance ID (must be connected)
|
|
907
|
+
* @param phone - Phone number or JID of the contact to block
|
|
908
|
+
*
|
|
909
|
+
* @example
|
|
910
|
+
* await client.instances.blockContact('my-instance', '5511999999999');
|
|
911
|
+
*/
|
|
912
|
+
async blockContact(instanceId, phone) {
|
|
913
|
+
try {
|
|
914
|
+
await this.http.post(`/instances/${instanceId}/contacts/${phone}/block`);
|
|
915
|
+
} catch (error) {
|
|
916
|
+
this.handleError(error);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Unblock a contact
|
|
921
|
+
*
|
|
922
|
+
* @param instanceId - Instance ID (must be connected)
|
|
923
|
+
* @param phone - Phone number or JID of the contact to unblock
|
|
924
|
+
*
|
|
925
|
+
* @example
|
|
926
|
+
* await client.instances.unblockContact('my-instance', '5511999999999');
|
|
927
|
+
*/
|
|
928
|
+
async unblockContact(instanceId, phone) {
|
|
929
|
+
try {
|
|
930
|
+
await this.http.delete(`/instances/${instanceId}/contacts/${phone}/block`);
|
|
931
|
+
} catch (error) {
|
|
932
|
+
this.handleError(error);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Get group metadata
|
|
937
|
+
*
|
|
938
|
+
* @param instanceId - Instance ID (must be connected)
|
|
939
|
+
* @param groupId - Group JID (e.g., "120363123456789012@g.us")
|
|
940
|
+
* @returns Group metadata including participants
|
|
941
|
+
*
|
|
942
|
+
* @example
|
|
943
|
+
* const metadata = await client.instances.getGroupMetadata('my-instance', '120363123456789012@g.us');
|
|
944
|
+
* console.log(`Group: ${metadata.subject}`);
|
|
945
|
+
* console.log(`Participants: ${metadata.participants.length}`);
|
|
946
|
+
* for (const p of metadata.participants) {
|
|
947
|
+
* console.log(` - ${p.id} (${p.admin || 'member'})`);
|
|
948
|
+
* }
|
|
949
|
+
*/
|
|
950
|
+
async getGroupMetadata(instanceId, groupId) {
|
|
951
|
+
try {
|
|
952
|
+
const response = await this.http.get(`/instances/${instanceId}/groups/${groupId}`);
|
|
953
|
+
return response.data;
|
|
954
|
+
} catch (error) {
|
|
955
|
+
this.handleError(error);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
694
958
|
}
|
|
695
959
|
|
|
696
960
|
/**
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
|
|
3
3
|
/** SDK version - auto-generated from package.json */
|
|
4
|
-
const SDK_VERSION = '1.0.0-beta.
|
|
4
|
+
const SDK_VERSION = '1.0.0-beta.3';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Custom error classes for @zapyapi/sdk
|
|
@@ -426,6 +426,121 @@ class MessagesResource extends BaseResource {
|
|
|
426
426
|
this.handleError(error);
|
|
427
427
|
}
|
|
428
428
|
}
|
|
429
|
+
/**
|
|
430
|
+
* Send a location message
|
|
431
|
+
*
|
|
432
|
+
* @param instanceId - Instance ID
|
|
433
|
+
* @param options - Location message options
|
|
434
|
+
* @returns Message response with ID and status
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* await client.messages.sendLocation('my-instance', {
|
|
438
|
+
* to: '5511999999999',
|
|
439
|
+
* latitude: -23.5505,
|
|
440
|
+
* longitude: -46.6333,
|
|
441
|
+
* name: 'São Paulo',
|
|
442
|
+
* address: 'São Paulo, Brazil'
|
|
443
|
+
* });
|
|
444
|
+
*/
|
|
445
|
+
async sendLocation(instanceId, options) {
|
|
446
|
+
try {
|
|
447
|
+
const response = await this.http.post(`/message/${instanceId}/location`, {
|
|
448
|
+
to: options.to,
|
|
449
|
+
latitude: options.latitude,
|
|
450
|
+
longitude: options.longitude,
|
|
451
|
+
name: options.name,
|
|
452
|
+
address: options.address,
|
|
453
|
+
quoteMessageId: options.quotedMessageId
|
|
454
|
+
});
|
|
455
|
+
return response.data;
|
|
456
|
+
} catch (error) {
|
|
457
|
+
this.handleError(error);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Send a contact card message
|
|
462
|
+
*
|
|
463
|
+
* @param instanceId - Instance ID
|
|
464
|
+
* @param options - Contact message options
|
|
465
|
+
* @returns Message response with ID and status
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
* await client.messages.sendContact('my-instance', {
|
|
469
|
+
* to: '5511999999999',
|
|
470
|
+
* contact: {
|
|
471
|
+
* fullName: 'John Doe',
|
|
472
|
+
* phoneNumber: '+5511988887777',
|
|
473
|
+
* organization: 'Acme Inc'
|
|
474
|
+
* }
|
|
475
|
+
* });
|
|
476
|
+
*/
|
|
477
|
+
async sendContact(instanceId, options) {
|
|
478
|
+
try {
|
|
479
|
+
const response = await this.http.post(`/message/${instanceId}/contact`, {
|
|
480
|
+
to: options.to,
|
|
481
|
+
contact: options.contact,
|
|
482
|
+
quoteMessageId: options.quotedMessageId
|
|
483
|
+
});
|
|
484
|
+
return response.data;
|
|
485
|
+
} catch (error) {
|
|
486
|
+
this.handleError(error);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Send a sticker message
|
|
491
|
+
*
|
|
492
|
+
* @param instanceId - Instance ID
|
|
493
|
+
* @param options - Sticker message options
|
|
494
|
+
* @returns Message response with ID and status
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* await client.messages.sendSticker('my-instance', {
|
|
498
|
+
* to: '5511999999999',
|
|
499
|
+
* url: 'https://example.com/sticker.webp'
|
|
500
|
+
* });
|
|
501
|
+
*/
|
|
502
|
+
async sendSticker(instanceId, options) {
|
|
503
|
+
try {
|
|
504
|
+
const response = await this.http.post(`/message/${instanceId}/sticker`, {
|
|
505
|
+
to: options.to,
|
|
506
|
+
url: options.url,
|
|
507
|
+
base64: options.base64,
|
|
508
|
+
quoteMessageId: options.quotedMessageId
|
|
509
|
+
});
|
|
510
|
+
return response.data;
|
|
511
|
+
} catch (error) {
|
|
512
|
+
this.handleError(error);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Send a reaction to a message
|
|
517
|
+
*
|
|
518
|
+
* @param instanceId - Instance ID
|
|
519
|
+
* @param options - Reaction options
|
|
520
|
+
*
|
|
521
|
+
* @example
|
|
522
|
+
* // Add a reaction
|
|
523
|
+
* await client.messages.sendReaction('my-instance', {
|
|
524
|
+
* messageId: 'ABC123...',
|
|
525
|
+
* reaction: '👍'
|
|
526
|
+
* });
|
|
527
|
+
*
|
|
528
|
+
* // Remove a reaction
|
|
529
|
+
* await client.messages.sendReaction('my-instance', {
|
|
530
|
+
* messageId: 'ABC123...',
|
|
531
|
+
* reaction: ''
|
|
532
|
+
* });
|
|
533
|
+
*/
|
|
534
|
+
async sendReaction(instanceId, options) {
|
|
535
|
+
try {
|
|
536
|
+
await this.http.post(`/message/${instanceId}/reaction`, {
|
|
537
|
+
messageId: options.messageId,
|
|
538
|
+
reaction: options.reaction
|
|
539
|
+
});
|
|
540
|
+
} catch (error) {
|
|
541
|
+
this.handleError(error);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
429
544
|
}
|
|
430
545
|
|
|
431
546
|
/**
|
|
@@ -689,6 +804,155 @@ class InstancesResource extends BaseResource {
|
|
|
689
804
|
this.handleError(error);
|
|
690
805
|
}
|
|
691
806
|
}
|
|
807
|
+
/**
|
|
808
|
+
* Check if phone numbers are registered on WhatsApp
|
|
809
|
+
*
|
|
810
|
+
* This method verifies if the provided phone numbers are registered on WhatsApp.
|
|
811
|
+
* Useful for validating contacts before sending messages.
|
|
812
|
+
*
|
|
813
|
+
* @param instanceId - Instance ID (must be connected)
|
|
814
|
+
* @param numbers - Array of phone numbers to check (with country code, e.g., "5511999999999")
|
|
815
|
+
* @returns Results indicating which numbers are registered on WhatsApp
|
|
816
|
+
*
|
|
817
|
+
* @example
|
|
818
|
+
* const result = await client.instances.checkNumbers('my-instance', [
|
|
819
|
+
* '5511999999999',
|
|
820
|
+
* '5521888888888'
|
|
821
|
+
* ]);
|
|
822
|
+
*
|
|
823
|
+
* for (const check of result.results) {
|
|
824
|
+
* if (check.exists) {
|
|
825
|
+
* console.log(`${check.number} is on WhatsApp (JID: ${check.jid})`);
|
|
826
|
+
* } else {
|
|
827
|
+
* console.log(`${check.number} is NOT on WhatsApp`);
|
|
828
|
+
* }
|
|
829
|
+
* }
|
|
830
|
+
*/
|
|
831
|
+
async checkNumbers(instanceId, numbers) {
|
|
832
|
+
try {
|
|
833
|
+
const response = await this.http.post(`/instances/${instanceId}/check-numbers`, {
|
|
834
|
+
numbers
|
|
835
|
+
});
|
|
836
|
+
return response.data;
|
|
837
|
+
} catch (error) {
|
|
838
|
+
this.handleError(error);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Send a presence update (typing indicator, online status, etc.)
|
|
843
|
+
*
|
|
844
|
+
* Use this to show typing indicators or update online status for a contact.
|
|
845
|
+
*
|
|
846
|
+
* @param instanceId - Instance ID (must be connected)
|
|
847
|
+
* @param options - Presence options
|
|
848
|
+
*
|
|
849
|
+
* @example
|
|
850
|
+
* // Show typing indicator
|
|
851
|
+
* await client.instances.sendPresence('my-instance', {
|
|
852
|
+
* to: '5511999999999',
|
|
853
|
+
* presence: 'composing'
|
|
854
|
+
* });
|
|
855
|
+
*
|
|
856
|
+
* // Show recording audio indicator
|
|
857
|
+
* await client.instances.sendPresence('my-instance', {
|
|
858
|
+
* to: '5511999999999',
|
|
859
|
+
* presence: 'recording'
|
|
860
|
+
* });
|
|
861
|
+
*
|
|
862
|
+
* // Stop typing indicator
|
|
863
|
+
* await client.instances.sendPresence('my-instance', {
|
|
864
|
+
* to: '5511999999999',
|
|
865
|
+
* presence: 'paused'
|
|
866
|
+
* });
|
|
867
|
+
*/
|
|
868
|
+
async sendPresence(instanceId, options) {
|
|
869
|
+
try {
|
|
870
|
+
await this.http.post(`/instances/${instanceId}/presence`, {
|
|
871
|
+
to: options.to,
|
|
872
|
+
presence: options.presence
|
|
873
|
+
});
|
|
874
|
+
} catch (error) {
|
|
875
|
+
this.handleError(error);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Get profile picture URL for a contact
|
|
880
|
+
*
|
|
881
|
+
* @param instanceId - Instance ID (must be connected)
|
|
882
|
+
* @param phone - Phone number or JID of the contact
|
|
883
|
+
* @returns Profile picture response with URL (null if not available)
|
|
884
|
+
*
|
|
885
|
+
* @example
|
|
886
|
+
* const result = await client.instances.getProfilePicture('my-instance', '5511999999999');
|
|
887
|
+
* if (result.url) {
|
|
888
|
+
* console.log('Profile picture:', result.url);
|
|
889
|
+
* } else {
|
|
890
|
+
* console.log('No profile picture available');
|
|
891
|
+
* }
|
|
892
|
+
*/
|
|
893
|
+
async getProfilePicture(instanceId, phone) {
|
|
894
|
+
try {
|
|
895
|
+
const response = await this.http.get(`/instances/${instanceId}/contacts/${phone}/profile-picture`);
|
|
896
|
+
return response.data;
|
|
897
|
+
} catch (error) {
|
|
898
|
+
this.handleError(error);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Block a contact
|
|
903
|
+
*
|
|
904
|
+
* @param instanceId - Instance ID (must be connected)
|
|
905
|
+
* @param phone - Phone number or JID of the contact to block
|
|
906
|
+
*
|
|
907
|
+
* @example
|
|
908
|
+
* await client.instances.blockContact('my-instance', '5511999999999');
|
|
909
|
+
*/
|
|
910
|
+
async blockContact(instanceId, phone) {
|
|
911
|
+
try {
|
|
912
|
+
await this.http.post(`/instances/${instanceId}/contacts/${phone}/block`);
|
|
913
|
+
} catch (error) {
|
|
914
|
+
this.handleError(error);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Unblock a contact
|
|
919
|
+
*
|
|
920
|
+
* @param instanceId - Instance ID (must be connected)
|
|
921
|
+
* @param phone - Phone number or JID of the contact to unblock
|
|
922
|
+
*
|
|
923
|
+
* @example
|
|
924
|
+
* await client.instances.unblockContact('my-instance', '5511999999999');
|
|
925
|
+
*/
|
|
926
|
+
async unblockContact(instanceId, phone) {
|
|
927
|
+
try {
|
|
928
|
+
await this.http.delete(`/instances/${instanceId}/contacts/${phone}/block`);
|
|
929
|
+
} catch (error) {
|
|
930
|
+
this.handleError(error);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* Get group metadata
|
|
935
|
+
*
|
|
936
|
+
* @param instanceId - Instance ID (must be connected)
|
|
937
|
+
* @param groupId - Group JID (e.g., "120363123456789012@g.us")
|
|
938
|
+
* @returns Group metadata including participants
|
|
939
|
+
*
|
|
940
|
+
* @example
|
|
941
|
+
* const metadata = await client.instances.getGroupMetadata('my-instance', '120363123456789012@g.us');
|
|
942
|
+
* console.log(`Group: ${metadata.subject}`);
|
|
943
|
+
* console.log(`Participants: ${metadata.participants.length}`);
|
|
944
|
+
* for (const p of metadata.participants) {
|
|
945
|
+
* console.log(` - ${p.id} (${p.admin || 'member'})`);
|
|
946
|
+
* }
|
|
947
|
+
*/
|
|
948
|
+
async getGroupMetadata(instanceId, groupId) {
|
|
949
|
+
try {
|
|
950
|
+
const response = await this.http.get(`/instances/${instanceId}/groups/${groupId}`);
|
|
951
|
+
return response.data;
|
|
952
|
+
} catch (error) {
|
|
953
|
+
this.handleError(error);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
692
956
|
}
|
|
693
957
|
|
|
694
958
|
/**
|