> ## 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_treble_sessions

> One row per conversation flow execution, inbound or outbound.

# fact\_treble\_sessions

Each row is one execution of a conversational flow by one user — from the moment it starts (a campaign send or an inbound message) to the moment it ends. This is the anchor table of the warehouse: messages, journeys, and variables all join back to it through `session_id`.

## What questions does it answer?

* How many conversations ran, inbound vs outbound?
* Which flows (`poll_name`) generate the most conversations?
* Where do users stop? (`last_node_id`, resolvable against `dim_poll_nodes`)
* Which keyword triggered each inbound conversation?
* How long do conversations last, and how do they end?

## Columns

| Column              | Type       | Description                                                                                                                                                                                    |
| ------------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `session_id`        | Int64      | Unique identifier of the conversation flow                                                                                                                                                     |
| `company_id`        | Int32      | Your company (filtered automatically)                                                                                                                                                          |
| `created_at`        | DateTime64 | When the conversation started                                                                                                                                                                  |
| `cellphone`         | String     | User's phone number                                                                                                                                                                            |
| `country_code`      | String     | User's country code                                                                                                                                                                            |
| `status`            | String     | Who handled the conversation: `AI` (stayed with the automated flow), `HumanHandover` (handed over to a human agent), `Rating` (went through an agent and reached the satisfaction-rating step) |
| `is_valid`          | Bool       | `true` once at least one message of the conversation was confirmed delivered to or read by the user — the conversation actually reached the phone                                              |
| `poll_id`           | Int32      | Flow identifier                                                                                                                                                                                |
| `poll_name`         | String     | Flow name                                                                                                                                                                                      |
| `channel_id`        | Int32      | WhatsApp line identifier                                                                                                                                                                       |
| `channel_cellphone` | String     | WhatsApp line number                                                                                                                                                                           |
| `direction`         | String     | `INBOUND` (user started) or `OUTBOUND` (campaign started)                                                                                                                                      |
| `contact_id`        | Int64      | Treble contact; `0` if none                                                                                                                                                                    |
| `finished_at`       | DateTime64 | When it ended; `NULL` if still open                                                                                                                                                            |
| `trigger_keyword`   | String     | The keyword that triggered an inbound flow, when one matched; empty otherwise and for outbound                                                                                                 |
| `last_node_id`      | Int32      | The last flow node this conversation reached; `0` if it never reached one                                                                                                                      |
| `synced_at`         | DateTime64 | When this row was last written/corrected                                                                                                                                                       |

## Example queries

### Where do conversations end, per flow?

```sql theme={null}
SELECT
    s.last_node_id,
    n.node_type,
    n.question_text,
    count() AS conversations_ended_here
FROM fact_treble_sessions AS s
LEFT JOIN dim_poll_nodes AS n
    ON n.company_id = s.company_id AND n.node_id = s.last_node_id
WHERE s.poll_id = {your_poll_id}
  AND s.created_at >= today() - 30
GROUP BY s.last_node_id, n.node_type, n.question_text
ORDER BY conversations_ended_here DESC
```

### Inbound conversations by trigger keyword

```sql theme={null}
SELECT trigger_keyword, count() AS conversations
FROM fact_treble_sessions
WHERE direction = 'INBOUND'
  AND created_at >= today() - 7
GROUP BY trigger_keyword
ORDER BY conversations DESC
```
