Wa-automate-nodejs: How do I send VCard

Created on 4 Apr 2020  Â·  21Comments  Â·  Source: open-wa/wa-automate-nodejs

Hello @smashah, I want to be able to send VCard that will appear like the sendContact function.

Thanks :).

enhancement

Most helpful comment

NOOOOOOOOOOOOOOOOOOO, it's not working.

APRIL FL :), you are a genius. It working after upgrading to @open-wa/wa-automate

Thanks so much.

All 21 comments

@github-actions run


âš¡ Release! âš¡

(async () => {
function exec(cmd) {
  console.log(execSync(cmd).toString());
}

// Config
const gitUserEmail = "github-actions[bot]@users.noreply.github.com";
const gitUserName = "github-actions[bot]";

exec(`echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc`);
exec(`git config --global user.email "${gitUserEmail}"`);
exec(`git config --global user.name "${gitUserName}"`);
exec(`npm i`);
exec(`npm run release-ci`);

var result = execSync(`npx auto-changelog -o ./tempchangelog.txt --commit-limit false --template ./compact-keepachangelog.hbs --stdout`).toString();

    await postComment(result);
  })();

Changelog

🚀 Release 1.8.39 (2020-04-06)

  • Bump typedoc from 0.17.3 to 0.17.4 #282
  • Bump ts-node from 8.8.1 to 8.8.2 #281
  • Bump prettier from 2.0.2 to 2.0.3 #280
  • Release 1.8.39 c470e72
  • added sendVCard #272 094b111

@mrbarnk you can try:

var vCardsJS = require('vcards-js');
...
//create a new vCard
var vCard = vCardsJS();

//set properties
vCard.firstName = 'Eric';
vCard.middleName = 'J';
vCard.lastName = 'Nesser';
vCard.organization = 'ACME Corporation';
vCard.photo.attachFromUrl('https://avatars2.githubusercontent.com/u/5659221?v=3&s=460', 'JPEG');
vCard.workPhone = '+13125551212';
vCard.birthday = new Date(1985, 0, 1);
vCard.title = 'Software Developer';
vCard.url = 'https://github.com/enesser';
vCard.note = 'Notes on Eric';

//get as formatted string
const vcard = vCard.getFormattedString();

//make sure you add the name as the third parameter!!!
client.sendVCard('[email protected]',vcard,'Eric Nesser')

If you don't put the name at the end then it will send it as some random contact in your contact list.

Report back if working.

Thanks

I didn't have success to use, @smashah - When i tried to send, using exactly your exemple above, nothing is received on destination, infinite clock on message queue sender.. probably something with encoding of vCard or something like that,not worked for me, :(

Debug Info {
WA_VERSION: '0.4.2088',
PAGE_UA: 'WhatsApp/0.4.613 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36',
SULLA_HOTFIX_VERSION: '1.8.39',
BROWSER_VERSION: 'Chrome/80.0.3987.0'
}

@github-actions run


âš¡ Release! âš¡

(async () => {
function exec(cmd) {
  console.log(execSync(cmd).toString());
}

// Config
const gitUserEmail = "github-actions[bot]@users.noreply.github.com";
const gitUserName = "github-actions[bot]";

exec(`echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc`);
exec(`git config --global user.email "${gitUserEmail}"`);
exec(`git config --global user.name "${gitUserName}"`);
exec(`npm i`);
exec(`npm run release-ci`);

var result = execSync(`npx auto-changelog -o ./tempchangelog.txt --commit-limit false --template ./compact-keepachangelog.hbs --stdout`).toString();

    await postComment(result);
  })();

Changelog

🚀 Release 1.8.40 (2020-04-06)

It's not sending @smashah
This is the vcard after printing it.
BEGIN:VCARD
0|index | VERSION:3.0
0|index | FN;CHARSET=UTF-8:
0|index | N;CHARSET=UTF-8:;;;;
0|index | TEL;TYPE=WORK,VOICE:2341234567890
0|index | REV:2020-04-06T19:54:52.653Z
0|index | END:VCARD

Debug Info {
WA_VERSION: '0.4.2088',
PAGE_UA: 'WhatsApp/0.4.613 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, li
hrome/79.0.3945.88 Safari/537.36',
SULLA_HOTFIX_VERSION: '1.8.41',
BROWSER_VERSION: 'HeadlessChrome/80.0.3987.0'
}

Here is my code.

//set properties
vCard.firstName = fname;
vCard.middleName = middleName;
vCard.lastName = lname;
vCard.workPhone = res.contact[0];

//get as a formatted string
const vcard = vCard.getFormattedString();

@mrbarnk please share the actual code used to send the vcard.

@mrbarnk you can try:

var vCardsJS = require('vcards-js');
...
//create a new vCard
var vCard = vCardsJS();

//set properties
vCard.firstName = 'Eric';
vCard.middleName = 'J';
vCard.lastName = 'Nesser';
vCard.organization = 'ACME Corporation';
vCard.photo.attachFromUrl('https://avatars2.githubusercontent.com/u/5659221?v=3&s=460', 'JPEG');
vCard.workPhone = '+13125551212';
vCard.birthday = new Date(1985, 0, 1);
vCard.title = 'Software Developer';
vCard.url = 'https://github.com/enesser';
vCard.note = 'Notes on Eric';

//get as formatted string
const vcard = vCard.getFormattedString();

//make sure you add the name as the third parameter!!!
client.sendVCard('[email protected]',vcard,'Eric Nesser')

If you don't put the name at the end then it will send it as some random contact in your contact list.

Report back if working.

Thanks

I'm on phone now, but I sent it as it were from here. Does it work from your side?

@mrbarnk I've tested this again. It's working as expected

      await client.sendVCard(message.from,"BEGIN:VCARD\r\nVERSION:3.0\r\nFN;CHARSET=UTF-8:Eric J Nesser\r\nN;CHARSET=UTF-8:Nesser;Eric;J;;\r\nBDAY:19850101\r\nPHOTO;TYPE=JPEG:https:\/\/avatars2.githubusercontent.com\/u\/5659221?v=3&s=460\r\nTEL;TYPE=WORK,VOICE:312-555-1212\r\nTITLE;CHARSET=UTF-8:Software Developer\r\nORG;CHARSET=UTF-8:ACME Corporation\r\nURL;CHARSET=UTF-8:https:\/\/github.com\/enesser\r\nNOTE;CHARSET=UTF-8:Notes on Eric\r\nREV:2020-04-10T15:58:21.810Z\r\nEND:VCARD",'TEST CONTACT');

If you have more problems please make an issue. This one is resolved now. Thanks

NOOOOOOOOOOOOOOOOOOO, it's not working.

APRIL FL :), you are a genius. It working after upgrading to @open-wa/wa-automate

Thanks so much.

image

This is how it's sending, can it be like this?

image

FYI, the two numbers are on whatsapp.

@mrbarnk That's a good question. After analyzing a manual vcard message there is something different in the vcard text. It has a little waid section injected in the number.

So, using the above example

changing:

...5659221?v=3&s=460\r\nTEL;TYPE=WORK,VOICE:312-555-1212\r\nTITLE;CHARSET=UTF-8:Softwa

into

...5659221?v=3&s=460\r\nTEL;TYPE=WORK,VOICE;waid=4477777777777:312-555-1212\r\nTITLE;CHARSET=UTF-8:Softwa

results in the buttons showing up.

So ;waid=4477777777777 is injected before the : and after TEL:TYPE=.

Can you do me a favour and work on a regex function that injects the string into the middle?

Anyway to do that with vcard-js

Not unless there was a special version of it

oh!, I will use the string then.

Thanks!

@github-actions run


âš¡ Release! âš¡

(async () => {
function exec(cmd) {
  console.log(execSync(cmd).toString());
}

// Config
const gitUserEmail = "github-actions[bot]@users.noreply.github.com";
const gitUserName = "github-actions[bot]";

exec(`echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc`);
exec(`git config --global user.email "${gitUserEmail}"`);
exec(`git config --global user.name "${gitUserName}"`);
exec(`npm i`);
exec(`npm run release-ci`);

var result = execSync(`npx auto-changelog -o ./tempchangelog.txt --commit-limit false --template ./compact-keepachangelog.hbs --stdout`).toString();

    await postComment(result);
  })();

Changelog

🚀 Release 1.8.51 (2020-04-11)

  • typo fix #272 #272
  • Release 1.8.51 1551a91
  • automatically inject waid in sendvcard #272 528ed5f

@mrbarnk

Try this update. It now takes an extra param:
https://open-wa.github.io/wa-automate-nodejs/classes/whatsapp.html#sendvcard

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sandro-salles picture sandro-salles  Â·  4Comments

sandro-salles picture sandro-salles  Â·  4Comments

jazZcarabazZ picture jazZcarabazZ  Â·  5Comments

phantom-limb picture phantom-limb  Â·  5Comments

sandro-salles picture sandro-salles  Â·  4Comments