From c142c3bf9378bada1d9e27c77cb79c3c69d41f8e Mon Sep 17 00:00:00 2001 From: CyrilLacroix <48292410+CyrilLacroix@users.noreply.github.com> Date: Mon, 2 Jun 2025 21:08:45 +0200 Subject: [PATCH] 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> --- example.js | 24 ++++++++++++++++++++++++ src/util/Injected/Store.js | 6 +++++- src/util/Injected/Utils.js | 3 ++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/example.js b/example.js index f601b26..24fe7cc 100644 --- a/example.js +++ b/example.js @@ -470,6 +470,30 @@ client.on('message', async msg => { console.log(statuses); const chat = await statuses[0]?.getChat(); // Get user chat of a first status 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') { // NOTE: this action will take effect after you restart the client. const backgroundSync = await client.setBackgroundSync(true); diff --git a/src/util/Injected/Store.js b/src/util/Injected/Store.js index 0a3a5ff..536552d 100644 --- a/src/util/Injected/Store.js +++ b/src/util/Injected/Store.js @@ -67,7 +67,6 @@ exports.ExposeStore = () => { window.Store.ContactMethods = window.require('WAWebContactGetters'); window.Store.UserConstructor = window.require('WAWebWid'); window.Store.Validators = window.require('WALinkify'); - window.Store.VCard = window.require('WAWebFrontendVcardUtils'); window.Store.WidFactory = window.require('WAWebWidFactory'); window.Store.ProfilePic = window.require('WAWebContactProfilePicThumbBridge'); window.Store.PresenceUtils = window.require('WAWebPresenceChatAction'); @@ -112,6 +111,11 @@ exports.ExposeStore = () => { window.Store.ForwardUtils = { ...window.require('WAWebForwardMessagesToChat') }; + window.Store.VCard = { + ...window.require('WAWebFrontendVcardUtils'), + ...window.require('WAWebVcardParsingUtils'), + ...window.require('WAWebVcardGetNameFromParsed') + }; window.Store.StickerTools = { ...window.require('WAWebImageUtils'), ...window.require('WAWebAddWebpMetadata') diff --git a/src/util/Injected/Utils.js b/src/util/Injected/Utils.js index 5ef3bbc..abcd862 100644 --- a/src/util/Injected/Utils.js +++ b/src/util/Injected/Utils.js @@ -135,11 +135,12 @@ exports.LoadUtils = () => { vcardOptions = { type: 'multi_vcard', vcardList: vcards, - body: undefined + body: null }; delete options.contactCardList; } else if (options.parseVCards && typeof (content) === 'string' && content.startsWith('BEGIN:VCARD')) { delete options.parseVCards; + delete options.linkPreview; try { const parsed = window.Store.VCard.parseVcard(content); if (parsed) {