Configure your flows to perform API requests

After configuring a custom integration with an external service, it can be used in a flow to perform API requests during users’ WhatsApp processes. In this guide, we will learn how to use the custom integration block inside our flow builder via a practical example.

Before beginning

If this is the first time you read about our customs integration feature, you will need to set up an integration for your external service before continuing with this guide. We strongly recommend reading our custom integration configuration guide to better understand how these integrations work and also because we will use the integration configured there in our example.

To summarize, the mentioned integration contains an action that, receiving an order ID as an input, requests the data of thar order and returns its status. It also uses the API key authentication scheme. We already have a credential containing that key.

Flow structure

For this guide, we will configure a flow that follows a simple process:

  1. The bot asks the user for the ID of their order. The user provides it

  2. The bot requests the status of the order with that ID using custom integrations

  3. The bot responds with the obtained status

Creating the flow

We will start by logging in to Dashboard. We will be directly shown the flow list view:

Flow list view

Clicking on “Create new flow” will open a modal to set our new flow’s name and type. In this step, please remember that currently custom integrations are only supported for WhatsApp flows. We will also select a blank template to build our flow from zero.

Setting flow name and type
Using a blank template

After setting these details and clicking “continue”, the flow builder will appear.

Empty flow builder

Now, we will organize the next steps into sections that follow the flow structure mentioned before.

Asking for the order ID

Since we need the user to provide the order ID in a message, the first block in our flow will be an open question.

Adding an open question block

After setting a title and message, the block should look like this:

Our question asking the order ID

Now, let’s check the property bar for the block. At the end, there is a “variables” section which, for our open question, shows the value variable. This references the response the user will send after this question, and we will use it in the next step.

Our open question's variables

Requesting the order status via custom integration

Now, we need to send a request to our external service to obtain the order status. To do this, we will add a custom integration block. Please note that if your account has no custom integrations, it won’t be possible to select the block.

Adding a custom integration block

After selecting the integration we want to use and an optional message to send to the user before communicating with the external service, the block should look like this:

Our custom integration block

However, to complete the block configuration, we need to use the property bar. The first step is selecting the credential and action to use in the block. In this example, we only have 1 credential and 1 action, so it’s pretty straightforward.

Setting the credential and action

It’s time to configure the inputs of the action. As we explained at the start, in this example the action receives the order ID as an input, so now we need to set a value for it. Clicking “Add inputs” in the “Inputs” section will open a modal to set their values.

Action inputs modal

Here, we could set a fixed ID to always request the status of a certain order, but in this case we want to use the ID provided by the user. We can use our open question’s variable for that. After copying the variable reference in the open question’s property bar, we need to paste it in this modal.

Using the variable as an input

After that, the block’s configuration is complete.

Showing the order status to the user

You may have already noticed that the custom integration block’s prop bar has an “Outputs” section. This shows the outputs configured for the selected action in a fashion similar to variables. In this example the only output available is the order’s status.

Order status output

Let’s say that our external service returns 3 possible statuses for an order (the actual texts are the ones between parenthesis):

  • Completed (“completed”)
  • In progress (“in_progress”)
  • Not found (“not_found”)

For this example, we want to send a different message to the user for each status. This is done to give a better experience to the user since API outputs are not usually human-friendly names. To do this, we can use a condition block.

Adding a condition block

Now, we will set a condition for each posible status using the order status output. To do this we need to copy the output reference in the previous block’s property bar and paste it for each condition.

Setting a condition for the status

After setting a condition for each status, the block should look like this:

Completed condition block

With the conditions set, we will now add a “finish chat” block for each condition with a message for the corresponding status.

Adding a finish chat block
Completed messages

Note that we added a finish block for when we receive an unexpected status from the external service (or not receive a response at all due to an error). We strongly recommend to always take these scenarios into account so that the user does not receive unexpected errors or messages during their WhatsApp conversation.

Testing the completed flow

All that’s left is testing the flow. Click the “Test Conversation” button on the top right of the screen.

Test conversation button

After clicking it, a modal will appear asking for the WhatsApp number the bot will use and a message to trigger the flow.

Test conversation modal

Finally, clicking “continue” will show us the generated message to trigger the flow and a URL to send that message to the bot via WhatsApp.

Generated Whatsapp test URL

Here are some of the conversations we had with the bot:

Order completed
Order in progress test URL
Order not found
System error

Conclusion

After reading this guide, you have learned how to use custom integrations in our flow builder to have your users interact with your or someone else’s services via WhatsApp. Stay tuned for improvements and new features for custom integrations in the future!