# Route messages

Apple Messages that you receive from your customers can be routed to specific agents or teams using [Flows](/applications/automation/flows.md).

To do this, you'll need to know how to get the `biz-intent-id` and `biz-group-id` from the message.

{% hint style="info" %}
Not sure what `biz-intent-id` and `biz-group-id` are, or how to set them up? Learn about [URL entry points](/applications/channels/channels/supported-channels/apple-messages-for-business/how-to/use-entry-points.md#url-entry-points) first.
{% endhint %}

## Extract  `biz-intent-id` and `biz-group-id` from a message

Follow these steps to learn how to find and pass on the `biz-intent-id` and `biz-group-id` from an Apple Messages message in Flows.

### What you'll need

* An installed [Apple Messages for Business channel](/applications/channels/channels/supported-channels/apple-messages-for-business/quickstarts/install-apple-messages-for-business.md).
* A URL entry point for Apple Business messages, containing `biz-intent-id` and `biz-group-id`.
* At least one message that has been sent to that channel using a [URL entry point](/applications/channels/channels/supported-channels/apple-messages-for-business/how-to/use-entry-points.md#url-entry-points).

{% hint style="warning" %}
To set this up for Apple Messages that are sent to you without using a URL entry point, follow [these steps](#extract-ids-without-a-url-entry-point).
{% endhint %}

### Set up your flow

1. Go to **Flows** and set up a new flow. In this example, we'll use the **Conversation started** trigger.
2. For the 'Channel', select **Apple Messages for Business**, then select the specific channel instance you want to use.
3. For the 'Trigger event', select **Conversation started**.
4. For the 'Participant type', select **Contact**.
5. Click **Save**.
6. Click **Add new action**.
7. Under 'Select an action', go to **MessageBird API** > **Conversations** > **Get Message**.
8. In the 'Message ID' field, search for **lastMessageId** from the 'Trigger'.
9. Test the step.&#x20;

### Extract IDs from the test

The test will display data from the most recent message that has been sent to the Apple Messages for Business channel. As long as the most recent message has been sent from a URL entry point with `biz-intent-id` and `biz-group-id`, then this information will also be present in the test's **Output**.

Let's take a look at how we can find these IDs.

Here's an example output:

```json
{
  "requestId": "0d87bfa9-0d83-4835-b5c8-8bf7a0936607",
  "result": {
    "body": {
      "text": {
        "text": "Start a return"
      },
      "type": "text"
    }
  },
  "conversationId": "d21340ea-9fac-46e4-aa6b-2f3fbfb65fd",
  "createdAt": "2023-12-15T18:20:43.712",
  "draft": false,
  "id": "e4d7026b-30f5-4f63-be4f-dcf9e1f1e0a",
  "interactions": null,
  "meta": {
    "referral": {
      "group": "returns_department",
      "metadata": {
        "sourceId": "question"
      },
      "source": "intent"
    }
  }
}
```

#### `biz-intent-id`

First, let's find the `biz-intent-id`.&#x20;

In the test output, it's located at `meta.referral.metadata.sourceid`.

```json
"meta": {
    "referral": {
      "group": "returns_department",
      "metadata": {
        "sourceId": "question"
```

So in this example, the `biz-intent-id` is `"question"`.

#### `biz-group-id`

Now, let's find the `biz-group-id`.

In the test output, it's located at `meta.referral.group`.

```json
"meta": {
    "referral": {
      "group": "returns_department",
      "metadata": {
        "sourceId": "question"
```

So in this example, the `biz-intent-id` is `"returns_department"`.

### Extract IDs without a URL entry point

If the message from the customer has come through a source other than a URL entry point, you will need to do one of the following

* Assign the values to variables that are then modified as strings (to avoid null comparisons).
* In your conditional, add 'IF' `sourceid` = `present` 'AND' `group` = `present` 'AND' `sourceid` = `your value` 'AND' `groupid` = `your value`.

### Next steps

Now that you've found this data, you can use it to set up conditional routing.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bird.com/applications/channels/channels/supported-channels/apple-messages-for-business/how-to/route-messages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
