QR code and barcode: generation and recognition

QR-code generation

To generate a code, you need to use the function https://store.mavibot.ai/function/qrcode_generator

Parameters:

text_for_qr - text that needs to be coded api_key - API access key from the project’s settings

You can generate a code in the project’s settings
circle-info

Change #{api_key} to the token from settings

Example:

In the "URL request" field paste: https://store.mavibot.ai/function/qrcode_generator

In the "Stored values" field paste the variables you want to save (the required URL is in qr_image_url):

status->status;

qr_image_url->qr_image_url

In "JSON parameters" type

{"text_for_qr":"Text for coding","api_key":"8629fe13ba9efebefd27a7afd701767f"}

The function returns json with parameters status and qr_image_url

The QR-code you get

Barcode generation

To generate a code, you need to use the function https://store.mavibot.ai/function/barcode_generator

Parameters:

text_for_qr - text that needs to be coded api_key - API access key from the project’s settings

You can generate an API access key in the project's settings

class - the code class you need to generate. By default it’s ea13. Can take these values: 'code39', 'code128', 'ean', 'ean13', 'ean8', 'gs1', 'gtin', 'isbn', 'isbn10', 'isbn13', 'issn', 'jan', 'pzn', 'upc', 'upca'

without_text - (an optional parameter) if you provide it with any value, the barcode will be displayed without the text, as shown in the image below.

circle-info

Change #{api_key} to the token from settings

Example: {"text":"#{barcode}","api_key":"#{api_key}", "class": "ean13"}

The function returns json with parameters status and qr_image_url if successful and error_message if unsuccessful

circle-info

The example text is stored in the variable barcode, and the variable image_url is used to send it as an image.

An example of the request with no text

Barcode recognition from an image

You can use this for creating a bot that scans product codes. A useful feature is the fact that it can also scan QR-codes.

The address of the function that recognizes a barcode on an image is https://store.mavibot.ai/function/cv2barcode

To scan an image you need to send these parameters from the block:

{"photo":"the link to the barcode/QR-code or the variable with the link","api_key":"api access key from the settings"}

For example, to send an image for scanning you need to send these parameters:

In the arrow in the "User enters data" field enter the variable #{attachments}.

Code example:

{"photo":"#{attachments}","api_key":"8629fe13ba9efebefd27a7afd701767f"}

photo is the link to the barcode image; in our case, it’s the variable that holds the link to the image sent to the bot.

The next parameter is api_key - API access key from the project’s settings

The function works like this:

The client sends a picture of the barcode, the function scans it, and if successful, returns the barcode number with the operation status set to "ok."

barcode -> "4500000000567" status -> "ok"

The scanning status can be:

  • ok — the barcode was recognized

  • barcode not recognized — as the name suggests, the barcode couldn’t be recognized

  • error image reading — there was an error reading the image

  • error subscription — this feature isn’t available with your current subscription plan

The variable status can be used as a condition on an arrow to direct the client to the appropriate block.

For example, if an arrow’s condition checks whether status equals “barcode not recognized,” you can display the message "The code wasn’t recognized, please try again" and prompt the client to send the photo again.

Last updated