# How to automatically Parse Invoices in Flow Builder

In this guide, you’ll learn how to automatically extract information from incoming photos of invoices using the **Analyze Image** step in [Flow Builder](https://dashboard.messagebird.com/en/flow-builder).

#### What you'll need

* A [MessageBird account](https://dashboard.messagebird.com/en/sign-up)
* A [WhatsApp for Business account](https://www.messagebird.com/whatsapp/) or any other channel from [MessageBird's offering](https://dashboard.messagebird.com/en/channels)
* A workflow to handle the messages - [Flow Builder](https://dashboard.messagebird.com/en/flow-builder)
* An [Inbox account](https://inbox.messagebird.com/) (optional)

### Image quality best practices

When working with text recognition (OCR), it’s a good idea to provide your customers with tips on how to upload quality images that will allow for correct text extraction. If you’ve ever had to sign up for an online banking service and uploaded a photo of your ID, you’ll probably be familiar with some of these guidelines!

Recommendations:

* **Placement**: Make sure that the whole document is visible within the image. Don’t cut off any corners.
* **Orientation**: Position the document with its original orientation. Avoid tilted images.
* **Supported file types**: JPEG, PNG, and PDF.

### Input and output examples

When the Analyze Image step is configured for parsing invoice documents, the output will be a JSON object containing all detected properties. You can choose to make use of the whole object, or a certain property. Take a look at the example below.

| **Example input**                                                                                                                                                                                                                                 | **Example output**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-52d5f3fd6084d84109fdf0ef6ffaa4f47bb561bc%2FInvoice_example.jpeg?alt=media" alt="" data-size="original"> | <p>"<strong>invoice\_id</strong>": "US-001",<br>"<strong>total\_amount</strong>": 154.06,<br>"<strong>supplier\_name</strong>": "East Repair Inc.",<br>"<strong>supplier\_address</strong>": "1912 Harvest Lane\nNew York, NY 12210",<br>"<strong>total\_tax\_amount</strong>": 9.06,<br>"<strong>freight\_amount</strong>": 15,<br>"<strong>currency</strong>": "USD",<br>"<strong>purchase\_order</strong>": "2312/2019",<br>"<strong>payment\_terms</strong>": "Payment is due within 15 days",<br>"<strong>ship\_to\_address</strong>": "3787 Pineview Drive\nCambridge, MA 12210",<br>"<strong>receiver\_name</strong>": "John Smith",<br>"<strong>receiver\_address</strong>": "2 Court Square\nNew York, NY 12210",<br>"<strong>receiver\_tax\_id</strong>": "2312/2019",<br>"<strong>net\_amount</strong>": "145",<br>"<strong>remit\_to\_name</strong>": "East Repair Inc.",<br>"<strong>vat</strong>": "9.06"</p> |

&#x20;

### Step-by-step: Setting up an invoice parsing flow

In this quickstart, we'll set up a flow that demonstrates how to automatically extract data from a receipt image and send it back to the user is the receipt belongs to a certain company.

1. Log in to your [MessageBird Dashboard](https://dashboard.messagebird.com/en/login) and navigate to [Flow Builder](https://dashboard.messagebird.com/en/flow-builder).
2. Select an existing flow or create a new one. For this example, we're going to **create a new custom flow** with a **Telegram trigger**.
3. Add the **Analyze Image** step to your flow.
4. In the step's settings, under **Image content to recognize**, select **Document**.
5. Under **Document type**, select **Invoice**.
6. In the **Output variable** field, type **image\_content**\ <br>
7. Click **Save**.
8. Add a branch step and check if the value of **image\_content.supplier\_name** matches the company name you would expect with a custom condition. For this example, we only want to consider invoices from the “Messagebird” company, so we will match the **image\_content.supplier\_name** with “Messagebird”.<br>

   <figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-30f85d9dab51a0d2d4a2fb33ff05bd1cc87f3995%2Fbranching_match_messagebird.png?alt=media" alt=""><figcaption></figcaption></figure>

   <figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-20623c47bf63c96027bdce46790a20ec0c95e7de%2Fbranching.png?alt=media" alt=""><figcaption></figcaption></figure>
9. In the success branch, add a **Reply to channel message** step. Add the **image\_conten**t variable as the content. This will access the whole raw output instead of a single property.<br>

   <figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-52c7296c38417011c72484a4928eac6db301dc91%2Freply_to_channel_message.png?alt=media" alt=""><figcaption></figcaption></figure>
10. **Publish** your flow in the top-right corner of your screen, and you're good to go!<br>

    <figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-cdae2308c4fa3f294efadc1fa5a722c491f9566e%2Ffinal_flow_invoice_parsinf.png?alt=media" alt=""><figcaption></figcaption></figure>
11. Here's how it should look when you test it!<br>

    <figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-424754cb438b8604aec2f92d17604afe22002743%2Finvoice_parser_gif.gif?alt=media" alt=""><figcaption></figcaption></figure>
