
WhatsApp is a trusted platform by millions of users worldwide, making it a valuable channel for customer communication. It's a channel where you can get closer to your customers by forming personalized communication with them, building a stronger bond with your brand, and increasing loyalty. Thanks to Synerise's integration with WhatsApp, you have unlimited possibilities to customize your communication with customers. You can take advantage of all the insights you collect in Synerise and use them effectively to deliver the greatest value to your customers.

This use case shows a scenario with a replenishment campaign. You will learn how to perform a simple integration with WhatsApp to send a personalized message to customers encouraging them to reorder a product from a specific category, additionally incentivizing the reorder by giving them a discount code for that purchase. 

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/coffee-replenishment.png" alt="WhatsApp replenishment campaign"  class="full no-frame">
</figure>

## Prerequisites 
---
- Make sure you meet all [prerequisites](/docs/automation/integration/whats-app/send-template-message#prerequisites) to work with the **Send Template Message** node.
- Implement transaction events either through [SDK](/developers/web/transactions-sdk) or [API](https://developers.synerise.com/DataManagement/DataManagement.html#operation/CreateATransaction).
- Create [item feed](/docs/ai-hub/recommendations-v2/item-feed-requirements)  
- Create a [voucher pool](/docs/assets/code-pools). The ID of this voucher pool will be used as a dynamic value during the message creation process, allowing discount codes to be assigned to each customer participating in this scenario.

## Process
---
1. [Create an aggregate](/use-cases/send-replenishment-message-on-whats-app#create-an-aggregate) which returns the SKU of the last purchased product from the specified category.
2. [Create a message template in the Meta portal](/use-cases/send-replenishment-message-on-whats-app#create-a-message-template-in-the-meta-portal)
3. [Create a workflow to send a message to customers on WhatsApp](/use-cases/send-replenishment-message-on-whats-app#create-a-workflow-to-send-message-to-customers-on-whatsapp)

## Create an aggregate
---
In this part of the process, create an aggregate that returns the SKU of the last purchased product from the `Coffee` category.

1. Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/behavioral-data-hub-icon.svg" alt="Behavioral Data Hub icon" class="icon"> **Behavioral Data Hub > Live Aggregates > Create aggregate**.
2. As the aggregate type, select **Profile**.  
2. Enter the name of the aggregate.
3. Click **Analyze profiles by** and select **Last**.
4. From the **Choose event** dropdown list, select the `product.buy` event.
4. As the event parameter, select **$sku**.
5. Next to the **$sku**, click **+where**. 
6. From the dropdown list, select **$category**.
7. As the operator, choose **Equal**.
9. In the text field, enter the value of the category you want to use in replenishment campaign - in this use case, it will be `Coffee`.
8. Define the period analyzed in the aggregate.
9. Save the aggregate.
    <figure>
    <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/replenishment-product-sku.png" class="full" alt="Configuration of the aggregate">
    <figcaption>Configuration of the aggregate</figcaption>
    </figure>

## Create a message template in the Meta portal
---
Create a message template in the Meta portal that you will use in the next part of the process. In the body of the message, mark places where the dynamic elements will be added.  

In addition, if you would like to add a CTA at the end of the message, you can add a button and define its copy. The page to which the customer will be redirected after clicking the button can be defined in Synerise.

The example message used in this use case:  
`Hello {{1}}, it looks like you’re almost out of Coffee! Make an order for {{2}} now before it’s too late. Use the {{3}} code to get your 20% discount on your next purchase.` 

Where `{{1}}, {{2}}` and `{{3}}` are markers that will be replaced with the dynamic values. This step will be done in Synerise.

The screen below shows an example of creating a template message in the Meta portal:
    <figure>
    <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/meta-platform-copy-replenishment.png" class="full" alt="An example of body section configuration in Meta platform">
    <figcaption>An example of body section configuration in Meta platform</figcaption>
    </figure>

In the following screen, you can see how a button can be defined in the Meta portal:
    <figure>
    <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/whatsapp_meta_ac.png" class="full" alt="An example of button section configuration in Meta platform">
    <figcaption>An example of button section configuration in Meta platform</figcaption>
    </figure>

## Create a workflow to send message to customers on WhatsApp
---
The workflow will be triggered by the `product.buy` event from the selected product category. The delay is defined up to 30 days. If a customer does not make another purchase from the defined category after that period, we will send a WhatsApp message with the recommended products from the defined category.

1. In Synerise, go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/automation-hub-icon.svg" alt="Automation Hub icon" class="icon" > **Automation Hub > Workflows > New workflow**.
2. Enter the name of the workflow.

### Define the trigger node
3. As the trigger node, add **Profile Event**. In the configuration of the node, select the event that triggers the workflow. In this use case, it's a `product.buy` event.
4. Click **+ where** and choose **$category**.
5. As the logical operator, select **Equal**.  
6. In the text field, enter `Coffee`.
4. Confirm by clicking **Apply**.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/product.buy-Coffee-new.png" alt="Configuration of the Profile Event node"  class="full">
<figcaption>Configuration of the Profile Event node</figcaption>
</figure> 

### Configure the Delay node
1. Add the **Delay** node. In the node settings:
    1. In the **Delay** field, type `30`.
    2. From the dropdown list, choose **Day**.
2. Click **Apply**.

### Define the profile filter node
As the next node, choose **Profile Filter** to check if customers have bought a product from the Coffee category during last 30 days. To do this:
1. Choose the `product.buy` event.
2. As the parameter, choose **$category**.
5. As the logical operator, select **Equal**.  
6. In the text field, enter `Coffee`.
3. Set the time range to last 30 days.
4. Click **Apply**.
7. To the **Matched** path, add the **End** node.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/profile.filter-Coffee-new.png" alt="Configuration of the Profile Filter node"  class="largel">
<figcaption>Configuration of the Profile Filter node</figcaption>
</figure> 

### Define the Send Template Mesage node
8. To the **Not matched** path, add the WhatsApp **Send Template Message** node.
1. Click **Select connection**.
2. From the dropdown list, select the connection.
    - If no connections are available or you want to create a new one, see [Create a connection](/docs/automation/integration/whats-app/send-template-message#create-a-connection).
    - If you selected an existing connection, proceed to defining the integration settings.
3. In the **Sender ID** field, enter the phone number ID from which the message will be sent.  
    [You can find more information about phone number ID here](https://developers.facebook.com/docs/whatsapp/cloud-api/get-started/add-a-phone-number).
4. In the **Receiver** field, enter the phone number of the customer who will receive this message.  
We recommend using the `{% customer phone %}` insert, which inserts the phone number of an individual customer who goes through this node.
5. In the **Message template** field, enter the name of the [message template](/use-cases/send-replenishment-message-on-whats-app#create-a-message-template-in-the-meta-portal) you created earlier in the Meta portal.
6. From the **Language code** dropdown list, select the language used in the message.
7. In the **Message components** field, insert the object that contains the dynamic values in the order defined in the message template.  
    The example of object used in this use case:

   <div class="admonition admonition-note"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

   The aggregate and voucher pool IDs are used as examples for the purpose of this use case.

   </div></div></div>


        
   <pre><code class="language-json">[
     {
            "type": "body",
            "parameters": [
            {
                "type": "text",
                "text": "{% customer firstname %}"
            },
            {
                "type": "text",
                "text": "{% aggregate c37acfe7-08a1-345c-a3e7-da795bb6a326 %}{% for item in aggregate_result %}{% catalog.store-1(item).name %}{% endfor %}{% endaggregate %}"
            },
            {
                "type": "text",
                "text": "{% voucher %} 8c3c8fd3-e7e9-487d-ba89-0b7824f65f33 {% endvoucher %}"
            }
        ]
    }, 
    { 
        "type": "button", 
        "parameters":
        "index": "0",
        "sub_type": "url", [
            {
                "type": "url",
                "text": "{% aggregate c37acfe7-08a1-345c-a3e7-da795bb6a326 %}{% for item in aggregate_result %}{% catalogvar.store-1(item).url %}{{ catalog_result|replace('https://yourshop.com', '') }}{% endcatalogvar %}{% endfor %}{% endaggregate %}" 
            }
        ]
    },
    { 
        "type": "header",
        "parameters": [ 
            {
                 "type": "image",
                 "image": {
                      "link": "{% aggregate c37acfe7-08a1-345c-a3e7-da795bb6a326 %}{% for item in aggregate_result %}{% catalogvar.store-1(item).image %}{{ catalog_result }}{% endcatalogvar %}{% endfor %}{% endaggregate %}"
                 }
             }
         ]
     }
   ]</code></pre>


9. Click **Apply**.

The following table explains all the inserts used in the body, button and header sections shown above.

| Section | Insert value                                                                                                                                                                                                                         | Insert explanation                                                                                                                                                                                                                                                                                                       |
|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| body    | `{% customer firstname %}`                                                                                                                                                                                                           | The value of this insert is used as the value of `{{1}}`, so the name of a customer can be displayed in the message.                                                                                                                                                                                                     |
| body    | `{% aggregate c37acfe7-08a1-345c-a3e7-da795bb6a326 %} {% for item in aggregate_result %}  {% catalog.store-1(item).name %} {% endfor %} {% endaggregate %}`                                                                          | The value of this insert is used as the value of `{{2}}` to return a product that the customer bought the last time and did not purchase again within the estimated time period.                                                                                                                                         |
| body    | `{% voucher %} 8c3c8fd3-e7e9-487d-ba89-0b7824f65f33 {% endvoucher %}`                                                                                                                                                                | The value of this insert is used as the value of `{{3}}`. In this example, we assign a voucher code from the voucher pool to an individual customer.                                                                                                                                                                     |
| button  | `{% aggregate c37acfe7-08a1-345c-a3e7-da795bb6a326 %}{% for item in aggregate_result %}{% catalogvar.store-1(item).url %}{{ catalog_result\|replace('https://yourshop.com', '') }}{% endcatalogvar %}{% endfor %}{% endaggregate %}` | The value of this insert is used to return product url. Here we specify the URL omitting the domain, because we define the domain in the Meta platform, as you can see in the screenshot with the  [button creation](/use-cases/send-replenishment-message-on-whats-app#create-a-message-template-in-the-meta-portal). |
| header  | `{% aggregate c37acfe7-08a1-345c-a3e7-da795bb6a326 %}{% for item in aggregate_result %}{% catalogvar.store-1(item).image %}{{ catalog_result }}{% endcatalogvar %}{% endfor %}{% endaggregate %}`                                    | This value of insert is used to return the url to the product image in header.                                                                                                                                                                                                                                           |
 

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/send-a-template-message-replenishment.png" alt="Workflow configuration"  class="large">
<figcaption>Workflow configuration</figcaption>
</figure>  

## Check the use case set up on the Synerise Demo workspace 
---
You can check the configuration of the [aggregate](https://app.synerise.com/analytics/aggregates/c37acfe7-08a1-345c-a3e7-da795bb6a326) and the [workflow](https://app.synerise.com/automations/automation-diagram/998f1dc1-932d-4636-bb98-d1d823b00af6) directly in our Synerise Demo workspace. 

If you’re our partner or client, you already have automatic access to the **Synerise Demo workspace (1590)**, where you can explore all the configured elements of this use case and copy them to your workspace.  

If you’re not a partner or client yet, we encourage you to fill out the contact [form](https://demo.synerise.com/request) to schedule a meeting with our representatives. They’ll be happy to show you how our demo works and discuss how you can apply this use case in your business.

## Read more
---
- [Aggregates](/docs/analytics/aggregates)
- [Automation Hub](/docs/automation)
- [Jinjava inserts](/developers/inserts)
- [Recommendations](/docs/ai-hub/recommendations-v2)
- [WhatsApp **Send Template Message** node](/docs/automation/integration/whats-app/send-template-message)

