From 3c9985ad0c3ce427c6ad4fe408070897935c06df Mon Sep 17 00:00:00 2001 From: CyrilLacroix Date: Sun, 12 Feb 2023 15:32:22 +0100 Subject: [PATCH 1/8] fix(vcard): parse vcard module --- src/util/Injected.js | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/util/Injected.js b/src/util/Injected.js index 28cc069a66..2c81830efe 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -37,6 +37,7 @@ exports.ExposeStore = (moduleRaidStr) => { window.Store.UserConstructor = window.mR.findModule((module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null)[0].default; window.Store.Validators = window.mR.findModule('findLinks')[0]; window.Store.VCard = window.mR.findModule('vcardFromContactModel')[0]; + window.Store.VCardParse = window.mR.findModule('WA_BIZ_NAME')[0]; window.Store.WidFactory = window.mR.findModule('createWid')[0]; window.Store.ProfilePic = window.mR.findModule('profilePicResync')[0]; window.Store.PresenceUtils = window.mR.findModule('sendPresenceAvailable')[0]; @@ -58,7 +59,7 @@ exports.ExposeStore = (moduleRaidStr) => { ...window.mR.findModule('toWebpSticker')[0], ...window.mR.findModule('addWebpMetadata')[0] }; - + window.Store.GroupUtils = { ...window.mR.findModule('createGroup')[0], ...window.mR.findModule('setGroupDescription')[0], @@ -127,8 +128,8 @@ exports.LoadUtils = () => { let quotedMessage = window.Store.Msg.get(options.quotedMessageId); // TODO remove .canReply() once all clients are updated to >= v2.2241.6 - const canReply = window.Store.ReplyUtils ? - window.Store.ReplyUtils.canReplyMsg(quotedMessage.unsafe()) : + const canReply = window.Store.ReplyUtils ? + window.Store.ReplyUtils.canReplyMsg(quotedMessage.unsafe()) : quotedMessage.canReply(); if (canReply) { @@ -173,11 +174,11 @@ exports.LoadUtils = () => { } else if (options.parseVCards && typeof (content) === 'string' && content.startsWith('BEGIN:VCARD')) { delete options.parseVCards; try { - const parsed = window.Store.VCard.parseVcard(content); + const parsed = window.Store.VCardParse.parseVcard(content); if (parsed) { vcardOptions = { type: 'vcard', - vcardFormattedName: window.Store.VCard.vcardGetNameFromParsed(parsed) + vcardFormattedName: window.Store.VCardParse.vcardGetNameFromParsed(parsed) }; } } catch (_) { @@ -199,7 +200,7 @@ exports.LoadUtils = () => { } } } - + let buttonOptions = {}; if(options.buttons){ let caption; @@ -556,17 +557,17 @@ exports.LoadUtils = () => { chatId = window.Store.WidFactory.createWid(chatId); } switch (state) { - case 'typing': - await window.Store.ChatState.sendChatStateComposing(chatId); - break; - case 'recording': - await window.Store.ChatState.sendChatStateRecording(chatId); - break; - case 'stop': - await window.Store.ChatState.sendChatStatePaused(chatId); - break; - default: - throw 'Invalid chatstate'; + case 'typing': + await window.Store.ChatState.sendChatStateComposing(chatId); + break; + case 'recording': + await window.Store.ChatState.sendChatStateRecording(chatId); + break; + case 'stop': + await window.Store.ChatState.sendChatStatePaused(chatId); + break; + default: + throw 'Invalid chatstate'; } return true; From 242dec232d245154e5dc3e9fcc25483c98702395 Mon Sep 17 00:00:00 2001 From: Cyril Date: Sat, 10 Jun 2023 15:06:41 +0200 Subject: [PATCH 2/8] fix(vcard): eslint --- src/util/Injected.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/util/Injected.js b/src/util/Injected.js index 2c81830efe..4f1fafd954 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -557,17 +557,17 @@ exports.LoadUtils = () => { chatId = window.Store.WidFactory.createWid(chatId); } switch (state) { - case 'typing': - await window.Store.ChatState.sendChatStateComposing(chatId); - break; - case 'recording': - await window.Store.ChatState.sendChatStateRecording(chatId); - break; - case 'stop': - await window.Store.ChatState.sendChatStatePaused(chatId); - break; - default: - throw 'Invalid chatstate'; + case 'typing': + await window.Store.ChatState.sendChatStateComposing(chatId); + break; + case 'recording': + await window.Store.ChatState.sendChatStateRecording(chatId); + break; + case 'stop': + await window.Store.ChatState.sendChatStatePaused(chatId); + break; + default: + throw 'Invalid chatstate'; } return true; From 2dea193a7ec7b4cfae94999768961d121152ba35 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Wed, 2 Oct 2024 02:21:50 +0300 Subject: [PATCH 3/8] refactor: merge internal modules into VCardUtils --- src/util/Injected/Store.js | 5 +++-- src/util/Injected/Utils.js | 7 +++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/util/Injected/Store.js b/src/util/Injected/Store.js index 2da5871d9f..3d91f35f62 100644 --- a/src/util/Injected/Store.js +++ b/src/util/Injected/Store.js @@ -69,7 +69,6 @@ exports.ExposeStore = () => { window.Store.UploadUtils = window.require('WAWebUploadManager'); 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'); @@ -105,7 +104,9 @@ exports.ExposeStore = () => { window.Store.ForwardUtils = { ...window.require('WAWebForwardMessagesToChat') }; - + window.Store.VCardUtils = { + ...window.require('WAWebFrontendVcardUtils'), + }; window.Store.StickerTools = { ...window.require('WAWebImageUtils'), ...window.require('WAWebAddWebpMetadata') diff --git a/src/util/Injected/Utils.js b/src/util/Injected/Utils.js index 28c6094484..58d591b718 100644 --- a/src/util/Injected/Utils.js +++ b/src/util/Injected/Utils.js @@ -118,18 +118,17 @@ exports.LoadUtils = () => { if (options.contactCard) { let contact = window.Store.Contact.get(options.contactCard); vcardOptions = { - body: window.Store.VCard.vcardFromContactModel(contact).vcard, + body: window.Store.VCardUtils.vcardFromContactModel(contact).vcard, type: 'vcard', vcardFormattedName: contact.formattedName }; delete options.contactCard; } else if (options.contactCardList) { let contacts = options.contactCardList.map(c => window.Store.Contact.get(c)); - let vcards = contacts.map(c => window.Store.VCard.vcardFromContactModel(c)); + let vcards = contacts.map(c => window.Store.VCardUtils.vcardFromContactModel(c)); vcardOptions = { type: 'multi_vcard', - vcardList: vcards, - body: undefined + vcardList: vcards }; delete options.contactCardList; } else if (options.parseVCards && typeof (content) === 'string' && content.startsWith('BEGIN:VCARD')) { From 605522171e5520a656d48ea053e9d4c09edfa366 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Wed, 2 Oct 2024 02:24:34 +0300 Subject: [PATCH 4/8] fix: use proper modules for parsing vcards --- src/util/Injected/Store.js | 2 ++ src/util/Injected/Utils.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/util/Injected/Store.js b/src/util/Injected/Store.js index 3d91f35f62..c17a2cb87b 100644 --- a/src/util/Injected/Store.js +++ b/src/util/Injected/Store.js @@ -106,6 +106,8 @@ exports.ExposeStore = () => { }; window.Store.VCardUtils = { ...window.require('WAWebFrontendVcardUtils'), + ...window.require('WAWebVcardParsingUtils'), + ...window.require('WAWebVcardGetNameFromParsed') }; window.Store.StickerTools = { ...window.require('WAWebImageUtils'), diff --git a/src/util/Injected/Utils.js b/src/util/Injected/Utils.js index 58d591b718..1248cb91d4 100644 --- a/src/util/Injected/Utils.js +++ b/src/util/Injected/Utils.js @@ -134,11 +134,11 @@ exports.LoadUtils = () => { } else if (options.parseVCards && typeof (content) === 'string' && content.startsWith('BEGIN:VCARD')) { delete options.parseVCards; try { - const parsed = window.Store.VCardParse.parseVcard(content); + const parsed = window.Store.VCardUtils.parseVcard(content); if (parsed) { vcardOptions = { type: 'vcard', - vcardFormattedName: window.Store.VCardParse.vcardGetNameFromParsed(parsed) + vcardFormattedName: window.Store.VCardUtils.vcardGetNameFromParsed(parsed) }; } } catch (_) { From 687876763f36683bc166897a8dc5171039c707d8 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Wed, 2 Oct 2024 05:08:11 +0300 Subject: [PATCH 5/8] feat: add usage example --- example.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/example.js b/example.js index 3334e5b6a2..280b03f9c4 100644 --- a/example.js +++ b/example.js @@ -470,6 +470,27 @@ 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' + + '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 /** OR vCardExtended */); } }); From 4e437c0fd442b2eb7ab58843db6c5809f48551f5 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Wed, 2 Oct 2024 05:21:38 +0300 Subject: [PATCH 6/8] chore: eslint fix --- example.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/example.js b/example.js index 280b03f9c4..a9de693dfe 100644 --- a/example.js +++ b/example.js @@ -490,7 +490,8 @@ client.on('message', async msg => { '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 /** OR vCardExtended */); + await client.sendMessage(userId, vCard); + await client.sendMessage(userId, vCardExtended); } }); From 710ee333c52ec170665bb103634963fe360db03f Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Thu, 3 Oct 2024 21:02:42 +0300 Subject: [PATCH 7/8] fix: send vcard with email Co-authored-by: KH Soh <2169449+khsoh@users.noreply.github.com> --- src/util/Injected/Utils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/Injected/Utils.js b/src/util/Injected/Utils.js index 1248cb91d4..df09252620 100644 --- a/src/util/Injected/Utils.js +++ b/src/util/Injected/Utils.js @@ -128,11 +128,13 @@ exports.LoadUtils = () => { let vcards = contacts.map(c => window.Store.VCardUtils.vcardFromContactModel(c)); vcardOptions = { type: 'multi_vcard', - vcardList: vcards + vcardList: vcards, + 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.VCardUtils.parseVcard(content); if (parsed) { From 7d069b4e58c35cfbcd318d87d2afe7ac95cf5d97 Mon Sep 17 00:00:00 2001 From: alechkos <93551621+alechkos@users.noreply.github.com> Date: Thu, 3 Oct 2024 21:04:05 +0300 Subject: [PATCH 8/8] feat: add additional context to usage example --- example.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/example.js b/example.js index a9de693dfe..6280bc75c9 100644 --- a/example.js +++ b/example.js @@ -476,6 +476,8 @@ client.on('message', async msg => { '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 =