# Build an inbound flow

Inbound flows are the most commonly used flows. They handle incoming customer inquiries.

Before you start, make sure you've familiarized yourself with the [capabilities and limitations of flows](https://docs.bird.com/applications/automation/flows/concepts/capabilities-and-limitations).

### Getting started video

{% embed url="<https://app.arcade.software/share/JMvNoGR0QcxkEWJtpxNu>" %}

### What you'll need

* Access to Flows.
* At least one installed channel (we're going to be using WhatsApp).
* Two [teams](https://docs.bird.com/applications/inbox/inbox/admin-guide/teams) in Inbox, one for 'Support' and one for 'Sales'.

### Step one: Access Flows

{% hint style="info" %}
**Context**

Flows is available in the **Process Automation** section of your workspace.
{% endhint %}

1. Click your workspace name in the top left-hand corner of your screen.&#x20;
2. Click **Process Automation**, then select **Flows** from the sidebar.
3. Click **New flow** in the top right-hand side of your screen, then select **Create from scratch**.

### Step two: Add and set up a trigger

{% hint style="info" %}
**Context**

* All flows start with a *trigger*—an event that makes the flow run.
* A *conversation* is created automatically in Inbox when a customer messages you.
* When a customer messages you for the first time, they automatically become a *contact* in Bird.&#x20;
  {% endhint %}

In this example, we're going to trigger our flow when a new conversation is started on a specific channel.

1. In the **Trigger** section, select **Conversation**.
2. In the **Select a channel** section, select your installed channel. We're going to choose **WhatsApp**.
3. If you have multiple versions of the channel installed, such as more than one WhatsApp number, they will be listed in the drop-down in the **Select an instance** section. Select the one that you want to use to trigger this flow.
4. In the **Select a trigger event** section, select **Conversation created**.
5. The **Select participant type** section will be prefilled with **Contact**. Leave this as it is.
6. Click **Save** to complete the trigger setup.

### Step three: Reply with a list message

{% hint style="info" %}
**Context**

* Once triggered, flows perform tasks, known as *actions*.
* List messages have clickable buttons, known as *items*. You can add up to 10 items to a single list message.
  {% endhint %}

Now that our trigger has been set up to recognize when our WhatsApp number is used by a customer to start a new conversation, we need to ask the flow to send an automated reply to the customer.

In this example, we're going to reply with a list message.

1. Click **Add new action**.
2. Use the search bar to find the **Send list message to conversation** flow action.
3. \[Optional] In the **Title** field, enter a headline for your message. This can be something that describes the content that you're about to share.
4. In the **Message content** field, enter the body text of your content.
5. \[Optional] In the **Footer** field, enter a footer for your message.
6. In the **Items** section, click **+ Add new item**.
7. In the **Title** field, enter the text to want to display on the button. We're going to use 'Talk to sales'. You can leave the **Description** field blank.
8. Click **+ Add new item** again.
9. In the **Title** field, enter the text to want to display on the button. We're going to use 'Talk to support'. You can leave the **Description** field blank.

### Step four: Wait for a response

{% hint style="info" %}
**Context**

* *Wait* actions pause a flow until it receives a response.
* Because a flow can't wait indefinitely, wait actions will *fail* after a certain amount of time has passed. By default, they fail after five minutes.
* You can change how long the flow waits before it fails. For example, if you're using email, you might want to extend the wait time from five minutes to three hours.
  {% endhint %}

Once our list message has been sent, the flow needs to listen for a reply to that list message. We'll use a **Wait for conversation message** to tell the flow to wait.

1. Click **Add new action**.
2. Use the search bar to find the **Wait for conversation message** flow action.
3. \[Optional] Change the duration of the **Fail after** field.
4. Click **Next**.

### Step five: Send some test data to your flow

{% hint style="info" %}
**Context**

* While creating a flow, you'll often need to send some test data so that you can complete the setup.
* This data will appear in Bird as a *payload*.
* *Payloads* are structured packets of data that flows can read and pass between triggers and actions.
  {% endhint %}

Our flow is now waiting for a reply to the list message we sent. To configure this step correctly, we need to simulate a reply to that message.

1. Save the WhatsApp number that you used to set up the flow trigger to your mobile device.
2. Open WhatsApp on your mobile, and send a message to that number.
3. In your flow, click the trigger to expand the configuration.
4. In the **Test** section, click **Update test data**.
5. The payload will be updated, and will now contain information about the message you sent to your WhatsApp number.
6. Scroll down to the **Wait for conversation message** step and click **Update test**.

{% hint style="success" %}
**Good to know**: Tests conducted before [publishing the flow](#step-ten-polish-and-publish-the-flow) are free of charge.
{% endhint %}

### Step six: Use a conditional action

{% hint style="info" %}
**Context**

* A conditional action always starts with two branches. You can add more branches as required.
* Conditionals determine what actions happens next based on whether specific criteria are met.
  {% endhint %}

Now that we've simulated a reply, the flow needs to check the content of the reply. Most customers will use the reply buttons to select either 'Support' or 'Sales'.

1. Scroll to the end of your flow and click **Add new action**.
2. Use the search bar to find the **Conditional** flow action.
3. Click **Branch** **A**'s name, and rename it **Support**.
4. In the **Support** branch, click the **Variables** field.
5. Click **Steps** > **Wait for conversation message** > **event** > **message** > **body** > **text**.
6. From the **Select operator** drop-down, select **(String) equals**.
7. In the **Value** field, type **Talk to sales**.
8. Click **Branch** **B**'s name, and rename it **Sales**.
9. In the **Support** branch, click the **Variables** field.
10. Click **Steps** > **Wait for conversation message** > **event** > **message** > **body** > **text**.
11. From the **Select operator** drop-down, select **(String) equals**.
12. In the **Value** field, type **Talk to support**.
13. Click **Next**.

{% hint style="warning" %}

* When using the **(String) equals** operation, the flow will check that the reply content exactly matches the configured value.
* Make sure the values you add here exactly match the values that you added to the items in your [list message](#step-three-reply-with-a-list-message).
  {% endhint %}

### Step seven: Assign tickets to teams in Inbox

{% hint style="info" %}
Now that you've added branches to your flow, it's become a bit more complex. For a clearer view, scroll all the way up to the top of your screen and click **Tree view**.
{% endhint %}

Based on the content of the reply to the list message we sent, the flow will need to route the customer to either the 'Support' team, or the 'Sales' team.

1. Click the **Support** branch.
2. Within the branch, click **Add new action**.
3. Use the search bar to find the **Assign to team in Inbox** flow action.
4. In the **Team ID** field, select the appropriate **Support** team from the list.
5. Click **Next**.
6. Select the **Sales** branch.
7. Within the branch, click **Add new action**.
8. Use the search bar to find the **Assign to team in Inbox** flow action.
9. In the **Team ID** field, select the appropriate **Sales** team from the list.
10. Click **Next**.

### Step eight: Handle messages that aren't for 'Support' or 'Sales'

If the recipient of your list message decided not to click either the 'Support' or 'Sales' buttons, and instead replied with a free-form message, they won't match either of the branches you configured in [step six](#step-six-use-a-conditional-action).

Let's add a new branch to the conditional to handle those responses by asking them to select one of the predefined options, and re-sending them the list message.

1. While in the **Tree view**, look for the dotted line next to your two branches, and click **Add new action**.
2. Use the search bar to find the **Send plain text message to conversation** flow action.
3. In the message content, enter some text to instruct your customer to choose one of the predefined options.
4. Click **Next**.
5. Below this action, click **Add new action**.
6. Use the search bar to find the **Jump** flow action.
7. Choose the **Send List message to Conversation** flow action from the **Jump to action** dropdown.
8. \[Optional] Set a maximum number of jumps.
9. Click **Next**.
10. Below this action, click **Add new action**.
11. Use the search bar to find the **Update feed item** flow action.
12. In the settings, click the **Closed** toggle to the on position.
13. Click **Next**.

### Step nine: Follow up if there is no answer

Sometimes you won't receive a response to the list message. Let's set up a branch to handle situations like this.

1. From the **Tree view**, click the **Wait for conversation message** flow action.
2. Click **Advanced configuration**.
3. Under **Error handling**, select **Ignore and continue**.
4. Close the **Advanced configuration** panel.
5. In the **Fail After** section, decrease the **Duration** to 15 seconds.
6. Click **Next**.
7. Send another test message to the WhatsApp number.
8. From the **Tree view**, click the **Conditional** flow action.
9. **Add a new branch**.
10. Name the branch **Error**.
11. Set up the **Error** variable for **If error is present**.
12. Move this branch above the other branches you have created.

### Step ten: Polish and publish the flow

1. Give your flow a name that you'll recognize.
2. Add a short description to your flow steps.
3. Click **Publish draft** in the top right-hand corner of your screen.

{% hint style="success" %}
**Success!** Your flow is now live.
{% endhint %}

### Step eleven: Test and troubleshoot

Now that your flow has been published, you can test it by sending a new message to the WhatsApp number.

If your flow doesn't seem to be triggering, follow these steps:

1. Click the workspace name in the top left-hand corner of your screen.
2. Select either **Marketing** or **Customer Service**.
3. Go to **Inbox**.
4. Use the search bar to look for an open ticket for your own contact by typing in your phone number.
5. Assign the ticket to yourself, then close it.
6. Re-trigger the flow by sending a WhatsApp message from your phone.
