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:
CyrilLacroix 2025-06-02 21:08:45 +02:00 • committed by GitHub
commit c142c3bf93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);