> ## Documentation Index
> Fetch the complete documentation index at: https://help.treble.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# fact_sessions

> One row per executed conversation flow.

# fact\_sessions

Each row represents an executed conversation flow (inbound or outbound). A conversation flow is the complete interaction of a user with a Treble flow, from start to finish.

## What questions does it answer?

* How many conversation flows were executed?
* How many were inbound and how many outbound?
* Which campaigns generated the most flows?
* What was the final status of each flow?
* Which WhatsApp line was used?

## Columns

| Column              | Type       | Description                                                           |
| ------------------- | ---------- | --------------------------------------------------------------------- |
| `session_id`        | Int64      | Unique identifier of the conversation flow                            |
| `company_id`        | Int32      | Company identifier (filtered automatically)                           |
| `created_at`        | DateTime64 | Start date and time                                                   |
| `cellphone`         | String     | User's cellphone number                                               |
| `country_code`      | String     | User's country code                                                   |
| `status`            | String     | Final status of the flow: `HumanHandover`, `Rating`, `Finished`, etc. |
| `is_valid`          | Bool       | Whether the flow completed successfully                               |
| `poll_id`           | Int32      | Campaign/conversation identifier                                      |
| `poll_name`         | String     | Campaign name                                                         |
| `channel_id`        | Int32      | WhatsApp line identifier                                              |
| `channel_cellphone` | String     | WhatsApp line number                                                  |
| `inbound_outbound`  | String     | `INBOUND` if the user started, `OUTBOUND` if from a campaign          |
| `contact_id`        | Int64      | Contact identifier in Treble. `0` if no associated contact            |
| `finished_at`       | DateTime64 | End date and time                                                     |

## Example queries

### Inbound vs outbound usage per day

```sql theme={null}
SELECT
    toDate(created_at) AS day,
    inbound_outbound,
    count() AS total,
    countIf(is_valid) AS valid
FROM client_analytics.fact_sessions
WHERE created_at >= now() - INTERVAL 30 DAY
GROUP BY day, inbound_outbound
ORDER BY day DESC
```

### Top campaigns by volume

```sql theme={null}
SELECT
    poll_name,
    inbound_outbound,
    count() AS flows,
    countIf(status = 'HumanHandover') AS moved_to_agent
FROM client_analytics.fact_sessions
WHERE created_at >= now() - INTERVAL 30 DAY
GROUP BY poll_name, inbound_outbound
ORDER BY flows DESC
LIMIT 20
```
