danielcardeenas / sulla

👩🏻‍🔬 Javascript Whatsapp api library for chatbots
MIT License
1.26k stars 273 forks source link

Get QR Code on a page #61

Closed CarlosEduR closed 4 years ago

CarlosEduR commented 4 years ago

Hello, Daniel! How are you? I'm really grateful about the project you've done. I appreciate it.

I have a question: I got a freelancer job, and client would like to use this tool over browser, so I'd need to send QRCode to frontend.

Could you help me out on this issue?

Mrjavaci commented 4 years ago

I am interested in this topic. I will return when I find a solution.

MuallimCh commented 4 years ago

Hello, Daniel! How are you? I'm really grateful about the project you've done. I appreciate it.

I have a question: I got a freelancer job, and client would like to use this tool over browser, so I'd need to send QRCode to frontend.

Could you help me out on this issue?

in src/controllers/auth.ts After const qrImage declaration, just create other const that coresponds to image itself, and show it to window.

Just my opinion.

NewZeek commented 4 years ago

Hi, to send qrcode to frontend import fs to auth.js and save qrcode to html file.

const fs = require('fs');
//After case 2:
qrImage = _a.sent();
fs.writeFile('qrcode.html', '<html><body><img src="https://api.qrserver.com/v1/create-qr-code/?data=' + encodeURIComponent(qrImage) + '"></body></html>', (err) => {
  if (err) throw err;
  console.log('QrCode saved to file.');
});

Boa sorte.

CarlosEduR commented 4 years ago

It really works, I'm feeling a noob 'cause didn't think about this way. Valeu, NewZeek.

But, as this 'create()' is an asynchronous function, I'd need to load it only when it has been already generated, and this function only finishes when QR Code from terminal was scanned. Do you have any simple idea to solve this?

NewZeek commented 4 years ago

The terminal and file QR are the same. When you read the html file in the browser, this terminal function automatically terminates. As sulla is a browser automation, it works as whatsapp web application and who informs that the qr has been read is the whatsapp app from smartphone.

In your application, create an ajax function that reads the qr file in time Interval e create a element tag < img /> when the server return the value.

Sorry my english

yodaheis commented 4 years ago

Ola pessoas, What will be really cool is if we could take a snapshot, export a pdf and email it. I will give a shot at adding this feature.

smashah commented 4 years ago

Hi @yodaheis @CarlosEduR @NewZeek @Mrjavaci @MuallimCh

I've implemented this feature in v 1.2.3 of sulla-hotfix.

It uses the event emitter to grab the qr code when it's ready as base64.

You can see it here: https://github.com/smashah/sulla#capturing-qr-code

Let me know if this works for you! Thanks

rfscheidt commented 4 years ago

does anyone has one sample?

danielcardeenas commented 4 years ago

When calling create() method you can attach a callback for it

const fs = require('fs');

// Second create() parameter is the QR callback
sulla.create('session-marketing', (qrCode) => {
  exportQR(qrCode, 'marketing-qr.png');
});

// Writes QR in specified path
function exportQR(qrCode, path) {
  qrCode = qrCode.replace('data:image/png;base64,', '');
  const imageBuffer = Buffer.from(qrCode, 'base64');

  // Creates 'marketing-qr.png' file
  fs.writeFileSync(path, imageBuffer);
}