> For the complete documentation index, see [llms.txt](https://docs.aisuru.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aisuru.com/en/advanced-features/integrations/dynamic-intents/tunneling-live-chat-example.md).

# Tunneling: live chat example on AIsuru

## Tunneling: a live chat example

In this section we'll see how to implement a live chat using dynamic intents and tunneling. This example will let us explore both how tunneling works and the structure of dynamic intent calls in detail.

#### The live chat scenario

A live chat is a perfect example to illustrate tunneling because it requires:

* An ongoing conversation with an external service
* Maintaining context between messages
* Handling responses in real time

#### Dynamic intent structure

To implement the live chat, we configure the dynamic intent with:

* Name: "LIVE\_CHAT"
* Activation phrases: "I want to speak to an operator", "Live chat", etc.
* Webhook: URL of the service that manages the live chat

When the user triggers the intent, the webhook receives a request with this structure:

```json
{
  "intentName": "LIVE_CHAT",
  "utterance": "I want to speak to an operator",
  "slotValues": {},
  "currentTag": "string",
  "currentTagAuthenticated": true,
  "contextVars": {},
  "memoriID": "string",
  "sessionID": "string",
  "culture": "en-US"
}
```

#### Starting the tunneling

The webhook responds by activating tunneling to take control of the conversation:

```json
{
  "emission": "I'm connecting you with an operator. Please wait a moment...",
  "conclusive": true,
  "tunneling": true
  }
}
```

From this point:

1. Every user message is sent directly to the webhook
2. The Agent no longer processes messages — it just forwards them to the chat service
3. The operator's replies arrive through the webhook (which passes them to the Agent via the emission)

#### Managing the conversation

During the chat, each user message generates a request to the webhook:

```json
{
  "intentName": "LIVE_CHAT",
  "utterance": "I have a problem with my order",
  "sessionID": "string",
  "culture": "en-US"
}
```

The webhook responds while keeping the tunneling active:

```json
{
  "emission": "Operator: Of course, please tell me your order number",
  "tunneling": true,
  "conclusive": true
}
```

#### Closing the chat

When the operator closes the chat, the webhook sends a response that ends the tunneling:

```json
{
  "emission": "The chat has been closed. Thank you for using our support service!",
  "tunneling": false,
  "conclusive": true
}
```

The Agent resumes normal control of the conversation.

{% hint style="info" %} <mark style="color:blue;">The</mark> <mark style="color:blue;">`tunneling`</mark> <mark style="color:blue;">flag determines who controls the conversation: if</mark> <mark style="color:blue;">`true`</mark><mark style="color:blue;">, the webhook is in control; if</mark> <mark style="color:blue;">`false`</mark><mark style="color:blue;">, the Agent takes back control.</mark>
{% endhint %}

The live chat example shows how tunneling lets you create complex interactions while keeping a clean, manageable architecture. The same principles apply to many other scenarios that require an ongoing conversation with an external system.
