open-wa / wa-automate-nodejs

💬 🤖 The most reliable tool for chatbots with advanced features. Be sure to 🌟 this repository for updates!
https://docs.openwa.dev/
Other
3.14k stars 601 forks source link

How do I send VCard #272

Closed mrbarnk closed 4 years ago

mrbarnk commented 4 years ago

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

Thanks :).

smashah commented 4 years ago

@github-actions run

âš¡ Release! âš¡ ```js (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); })(); ```
smashah commented 4 years ago

Changelog

🚀 Release 1.8.39 (2020-04-06)

smashah commented 4 years ago

@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('4477777777777@c.us',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

joaomirandas commented 4 years ago

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' }

smashah commented 4 years ago

@github-actions run

âš¡ Release! âš¡ ```js (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); })(); ```
smashah commented 4 years ago

Changelog

🚀 Release 1.8.40 (2020-04-06)

mrbarnk commented 4 years ago

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

mrbarnk commented 4 years ago

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'
}

mrbarnk commented 4 years ago

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

smashah commented 4 years ago

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

mrbarnk commented 4 years ago

@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('4477777777777@c.us',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?

smashah commented 4 years ago

@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

mrbarnk commented 4 years ago

NOOOOOOOOOOOOOOOOOOO, it's not working.

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

Thanks so much.

mrbarnk commented 4 years ago

image

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

image

FYI, the two numbers are on whatsapp.

smashah commented 4 years ago

@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?

mrbarnk commented 4 years ago

Anyway to do that with vcard-js

smashah commented 4 years ago

Not unless there was a special version of it

mrbarnk commented 4 years ago

oh!, I will use the string then.

Thanks!

smashah commented 4 years ago

@github-actions run

âš¡ Release! âš¡ ```js (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); })(); ```
smashah commented 4 years ago

Changelog

🚀 Release 1.8.51 (2020-04-11)

smashah commented 4 years ago

@mrbarnk

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

dgomp commented 2 years ago

Hi,

I was able to make the contact appear, as you guided. Thanks! My only question is: Is there a way to define the name on the sticker? Here for me, it is "contact".

Currently, my code is like this: await client.sendVCard(message.from, "BEGIN:VCARD\r\nVERSION: 3.0\r\nN:LastName;FirstName;;;\r\nFN:FistName LastName\r\nORG:Business;\r\nTEL;waid=551111111111:+55 11 1111-1111\r\nEND:VCARD", 'New Contact');

Does anyone know how to proceed?