fix(vcard): parse vcard module (#1995)
* fix(vcard): parse vcard module * fix(vcard): eslint * refactor: merge internal modules into VCardUtils * fix: use proper modules for parsing vcards * feat: add usage example * chore: eslint fix * fix: send vcard with email Co-authored-by: KH Soh <2169449+khsoh@users.noreply.github.com> * feat: add additional context to usage example * refactor: revert module rename --------- Co-authored-by: Codeboss <131376628+codebossdev@users.noreply.github.com> Co-authored-by: Shir Serlui <70711723+shirser121@users.noreply.github.com> Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com> Co-authored-by: KH Soh <2169449+khsoh@users.noreply.github.com>
This commit is contained in:
parent
94ce20b4a5
commit
c142c3bf93
3 changed files with 31 additions and 2 deletions
24
example.js
24
example.js
|
|
@ -470,6 +470,30 @@ client.on('message', async msg => {
|
||||||
console.log(statuses);
|
console.log(statuses);
|
||||||
const chat = await statuses[0]?.getChat(); // Get user chat of a first status
|
const chat = await statuses[0]?.getChat(); // Get user chat of a first status
|
||||||
console.log(chat);
|
console.log(chat);
|
||||||
|
} else if (msg.body === '!parseVCard') {
|
||||||
|
const vCard =
|
||||||
|
'BEGIN:VCARD\n' +
|
||||||
|
'VERSION:3.0\n' +
|
||||||
|
'FN:John Doe\n' +
|
||||||
|
'ORG:Microsoft;\n' +
|
||||||
|
'EMAIL;type=INTERNET:john.doe@gmail.com\n' +
|
||||||
|
'URL:www.johndoe.com\n' +
|
||||||
|
'TEL;type=CELL;type=VOICE;waid=18006427676:+1 (800) 642 7676\n' +
|
||||||
|
'END:VCARD';
|
||||||
|
const vCardExtended =
|
||||||
|
'BEGIN:VCARD\n' +
|
||||||
|
'VERSION:3.0\n' +
|
||||||
|
'FN:John Doe\n' +
|
||||||
|
'ORG:Microsoft;\n' +
|
||||||
|
'item1.TEL:+1 (800) 642 7676\n' +
|
||||||
|
'item1.X-ABLabel:USA Customer Service\n' +
|
||||||
|
'item2.TEL:+55 11 4706 0900\n' +
|
||||||
|
'item2.X-ABLabel:Brazil Customer Service\n' +
|
||||||
|
'PHOTO;BASE64:here you can paste a binary data of a contact photo in Base64 encoding\n' +
|
||||||
|
'END:VCARD';
|
||||||
|
const userId = 'XXXXXXXXXX@c.us';
|
||||||
|
await client.sendMessage(userId, vCard);
|
||||||
|
await client.sendMessage(userId, vCardExtended);
|
||||||
} else if (msg.body === '!changeSync') {
|
} else if (msg.body === '!changeSync') {
|
||||||
// NOTE: this action will take effect after you restart the client.
|
// NOTE: this action will take effect after you restart the client.
|
||||||
const backgroundSync = await client.setBackgroundSync(true);
|
const backgroundSync = await client.setBackgroundSync(true);
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,6 @@ exports.ExposeStore = () => {
|
||||||
window.Store.ContactMethods = window.require('WAWebContactGetters');
|
window.Store.ContactMethods = window.require('WAWebContactGetters');
|
||||||
window.Store.UserConstructor = window.require('WAWebWid');
|
window.Store.UserConstructor = window.require('WAWebWid');
|
||||||
window.Store.Validators = window.require('WALinkify');
|
window.Store.Validators = window.require('WALinkify');
|
||||||
window.Store.VCard = window.require('WAWebFrontendVcardUtils');
|
|
||||||
window.Store.WidFactory = window.require('WAWebWidFactory');
|
window.Store.WidFactory = window.require('WAWebWidFactory');
|
||||||
window.Store.ProfilePic = window.require('WAWebContactProfilePicThumbBridge');
|
window.Store.ProfilePic = window.require('WAWebContactProfilePicThumbBridge');
|
||||||
window.Store.PresenceUtils = window.require('WAWebPresenceChatAction');
|
window.Store.PresenceUtils = window.require('WAWebPresenceChatAction');
|
||||||
|
|
@ -112,6 +111,11 @@ exports.ExposeStore = () => {
|
||||||
window.Store.ForwardUtils = {
|
window.Store.ForwardUtils = {
|
||||||
...window.require('WAWebForwardMessagesToChat')
|
...window.require('WAWebForwardMessagesToChat')
|
||||||
};
|
};
|
||||||
|
window.Store.VCard = {
|
||||||
|
...window.require('WAWebFrontendVcardUtils'),
|
||||||
|
...window.require('WAWebVcardParsingUtils'),
|
||||||
|
...window.require('WAWebVcardGetNameFromParsed')
|
||||||
|
};
|
||||||
window.Store.StickerTools = {
|
window.Store.StickerTools = {
|
||||||
...window.require('WAWebImageUtils'),
|
...window.require('WAWebImageUtils'),
|
||||||
...window.require('WAWebAddWebpMetadata')
|
...window.require('WAWebAddWebpMetadata')
|
||||||
|
|
|
||||||
|
|
@ -135,11 +135,12 @@ exports.LoadUtils = () => {
|
||||||
vcardOptions = {
|
vcardOptions = {
|
||||||
type: 'multi_vcard',
|
type: 'multi_vcard',
|
||||||
vcardList: vcards,
|
vcardList: vcards,
|
||||||
body: undefined
|
body: null
|
||||||
};
|
};
|
||||||
delete options.contactCardList;
|
delete options.contactCardList;
|
||||||
} else if (options.parseVCards && typeof (content) === 'string' && content.startsWith('BEGIN:VCARD')) {
|
} else if (options.parseVCards && typeof (content) === 'string' && content.startsWith('BEGIN:VCARD')) {
|
||||||
delete options.parseVCards;
|
delete options.parseVCards;
|
||||||
|
delete options.linkPreview;
|
||||||
try {
|
try {
|
||||||
const parsed = window.Store.VCard.parseVcard(content);
|
const parsed = window.Store.VCard.parseVcard(content);
|
||||||
if (parsed) {
|
if (parsed) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue