# Chat Variables

## Definition

Chat variables store information from a chat session, including data about the app, user, and any inputs during the interaction. These variables can be utilised in an AI agent's subsequent actions.

***

## Actions & delimiters

The following actions support chat variables. To display a variable's value within an AI agent's action content, enclose the variable name within curly braces `{ }` as a delimiter.

<table><thead><tr><th width="375">Actions that require { ... } delimiter</th><th>Actions that do not require delimiter</th></tr></thead><tbody><tr><td><a href="../modules/ai-agents/workflows-and-actions/send-message">Send Message</a></td><td><a href="../modules/ai-agents/workflows-and-actions/branch">Branch</a></td></tr><tr><td><a href="../modules/ai-agents/workflows-and-actions/send-file">Send File</a></td><td><a href="../modules/ai-agents/workflows-and-actions/set-variable">Set variable</a></td></tr><tr><td><a href="../modules/ai-agents/workflows-and-actions/show-carousel">Show Carousel</a></td><td><a href="../modules/ai-agents/workflows-and-actions/send-api-request">Send API Request</a></td></tr><tr><td><a href="../modules/ai-agents/workflows-and-actions/show-survey">Show Survey</a></td><td></td></tr><tr><td><a href="../modules/ai-agents/workflows-and-actions/create-ticket">Create Ticket</a></td><td></td></tr></tbody></table>

## System Variables <a href="#variables" id="variables"></a>

The [Set variable](https://documentation.proto.cx/docs/modules/ai-agents/workflows-and-actions/set-variable) action can create new variables or reference existing system variables:

### `_user_input` <a href="#user_input" id="user_input"></a>

Captures and stores the person's input at each interaction stage within the AI agent. It is dynamic, meaning that it updates automatically each time the person enters a new input.

### `_lang` <a href="#lang" id="lang"></a>

Records the language identified from the person's input during each interaction.

### `_channel_profile` <a href="#channel_profile" id="channel_profile"></a>

Holds profile information for the person as obtained from the messaging app. It includes details such as the person's ID in Proto, their display name, the type of channel they're using, their profile picture URL, and other information that varies depending on the app.

For people connecting through Webchat, this variable also captures additional information if certain features are activated in the Webchat settings, such as:

* Data from a pre-chat form
* Person's location and IP address

{% code title="Example" overflow="wrap" %}

```
{
	"id": JSHSFHDHBJVKOISFIU,
	"display_name": "Weiying",
	"location": "MY",
	"email": "weiying@proto.cx",
	"phone_number": "34898483245",
	"ip_address": "0.0.0.0",
}
```

{% endcode %}

### `_customer` <a href="#customer" id="customer"></a>

{% hint style="warning" %}
Note that "customer" is a legacy term for an audience member, now referred to more generically as "people" or "persons" in the current platform and documentation.
{% endhint %}

Contains profile information for persons who have a [People](https://documentation.proto.cx/docs/modules/people) profile. This includes their name, email, phone number, and any [custom fields](https://documentation.proto.cx/docs/settings/teamspaces/custom-fields).

{% code title="Example" overflow="wrap" %}

```
{
	"id": customer.id,
	"external_customer_id": customer.external_customer_id,
	"name": customer.name,
	"location": customer.location,
	"email": customer.email,
	"phone_number": customer.phone_number,
	"provided_unique_id": customer.provided_unique_id,
	"tags": list(set(customer_tags)),
	"tag_groups": [tag_group.name for tag_group in customer.tag_groups],
	"custom_fields": {
		cf.custom_field.name: cf.value
		for cf in (customer_custom_fields or [])
	}
}
```

{% endcode %}

### `_channel` <a href="#channel" id="channel"></a>

Channel variables store information about a [channel](https://documentation.proto.cx/docs/modules/ai-agents/publishing) such as the channel ID, channel type, and other details unique to each channel.

{% code title="Example" overflow="wrap" %}

```
{
	"id": channel.id,
	"type": "webchat",
}
```

{% endcode %}

### `_new_ticket` <a href="#new_ticket" id="new_ticket"></a>

Contains ticket info when a new [email ticket](https://documentation.proto.cx/docs/modules/tickets) is created.

{% code title="Example" overflow="wrap" %}

```
{
    "id": new_ticket_id,
    "title": subject,
    "customer_id": customer_id,
    "assignee_type": assignee.type, 
    "assignee_id": assignee.id,
    "description": description,
    "bot_id": bot.id,
    "channel_id": channel.id,
    "custom_attrs": ["fetched_custom_field.name: cf.value"]
}
```

{% endcode %}

### **`_track.fetch_ticket_by_ticket_id("ticket_id_here")`** <a href="#track.fetch_ticket_by_ticket_id-ticket_id_here" id="track.fetch_ticket_by_ticket_id-ticket_id_here"></a>

Ticket variable that fetches ticket info by ticket ID.

{% code title="Example" overflow="wrap" %}

```
{
    "id": new_ticket_id, 
    "status": ticket_status, 
    "assignee_names": [assignee_names], 
    "assigned_team_names": [assigned_team_names],
    "customer_name": customer_name
}
```

{% endcode %}

### `_track.fetch_tickets_by_email("customer_email_here")` <a href="#track.fetch_tickets_by_email-customer_email_here" id="track.fetch_tickets_by_email-customer_email_here"></a>

Ticket variable that returns a list of tickets and their info by user email.

{% code title="Example" overflow="wrap" %}

```
[
    {
        "id": new_ticket_id, 
        "status": ticket_status, 
        "assignee_names": [assignee_names], 
        "assigned_team_names": [assigned_team_names],
        "customer_name": customer_name
    }
    ...
]
```

{% endcode %}


---

# 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://documentation.proto.cx/docs/developer-documentation/chat-variables.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.
