devlikeapro / waha

WAHA - WhatsApp HTTP API (REST API) that you can configure in a click! Two engines: chromium-based WEBJS and pure-websocket NOWEB
https://waha.devlike.pro/
Apache License 2.0
878 stars 273 forks source link

Get QR code as text #177

Closed gr8tushar closed 9 months ago

gr8tushar commented 1 year ago

Hi, I was wondering if we can get the QR as text, something that is available in whatsapp-web.js. This helps in transferring the data to the client via the API. The client can use any library to convert this code to QR code.

Thanks, Tushar

allburov commented 1 year ago

Sure, it's possible! For now you can scan that image using client libraries and get the data

gr8tushar commented 1 year ago

Hi, Any plans of implementing it in the near future?

allburov commented 9 months ago

The idea is to add a flag with expected format to /api/default/auth/qr

  1. Get binary ?format=image and header Accept: image/png - it's value by default, returns the binary image

  2. Get image in base64 encoding ?format=image and header Accept: application/json - base64 encoding of the JPEG QR image

    {
    "mimetype": "image/png",
    "data": "base64-encoded-data"
    }
  3. Get raw data that QR contains - you need to render it on your side

?format=raw - the raw value of the QR, so you can generate your own custom QR code without parsing the existed one.

{
  "value": "value-of-qr-code-that-you-need-to-render-on-your-side"
}

~?format=url - save the QR in files and return URL back~ - decided to skip that for now, above cases covers like 99% cases

allburov commented 9 months ago

Hi! In 2023.12.1 release there'll be a way to get QR code in different formats.

https://waha.devlike.pro/docs/how-to/sessions/#get-screenshot


QR formats

You can get QR in different formats:

  1. binary image - GET /api/{session}/auth/qr
  2. base64 image - GET /api/{session}/auth/qr and set Accept: application/json header
  3. raw - GET /api/{session}/auth/qr?format=raw

Here's detailed information about each format:

  1. binary image, binary image - default format, you'll get image in response
    
    # Get image - binary
    GET /api/{session}/auth/qr

OR

GET /api/{session}/auth/qr?format=image

OR specify Accept header as well

GET /api/{session}/auth/qr?format=image Accept: image/png


2. **base64 image** - you'll get image in base64 format in response if you set `Accept: application/json` header.
```bash
GET /api/{session}/auth/qr?format=image
Accept: application/json
{
  "mimetype": "image/png",
  "data": "base64-encoded-data"
}

You can change it in Swagger by clicking on Media Type dropdown and selecting application/json:

  1. raw - you'll get raw data in response, you can use it to generate QR code on your side
    GET /api/{session}/auth/qr?format=raw
{
  "value": "value-that-you-need-to-use-to-generate-qr-code"
}