# 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" %}
The `tunneling` flag determines who controls the conversation: if `true`, the webhook is in control; if `false`, the Agent takes back control.
{% 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.


---

# 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.aisuru.com/en/advanced-features/integrations/dynamic-intents/tunneling-live-chat-example.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.
