# Chats

A chat is the messages you and a contact have exchanged, so these endpoints take the contact's ID. Assign a chat to an agent or a team, and close or reopen it.

## Endpoints

- [List agents](https://docs.soosh.io/reference/api/chats/list-agents/): `GET /v1/agents`
- [List teams](https://docs.soosh.io/reference/api/chats/list-teams/): `GET /v1/teams`
- [Assign a chat](https://docs.soosh.io/reference/api/chats/assign-chat/): `POST /v1/contacts/{id}/assign`
- [Close a chat](https://docs.soosh.io/reference/api/chats/close-chat/): `POST /v1/contacts/{id}/close`
- [Reopen a chat](https://docs.soosh.io/reference/api/chats/reopen-chat/): `POST /v1/contacts/{id}/reopen`

## Webhook events

- [`chat.assigned`](https://docs.soosh.io/reference/api/webhook-events/chat-assigned/): The agent or team a chat is with changes.
- [`chat.closed`](https://docs.soosh.io/reference/api/webhook-events/chat-closed/): A chat is closed.
- [`chat.reopened`](https://docs.soosh.io/reference/api/webhook-events/chat-reopened/): A closed chat is open again.

## The ChatState object

- `contact_id` (string, uuid)
- `status` (string): One of `open`, `closed`.
- `assigned_agent_id` (nullable string, uuid): The agent the chat is assigned to, or `null`.
- `team_id` (nullable string, uuid): The team the chat is with now, or `null`.
- `contact` (nullable object): The contact as it is now, with `contacts:read`; `null` without it.
  - `id` (string, uuid)
  - `phone` (nullable string): The number as `+` and its digits. `null` for a contact known only by a WhatsApp username.
  - `whatsapp_user_id` (nullable string): The ID WhatsApp gives a contact who uses a WhatsApp username. `null` if WhatsApp hasn't given Soosh one.
  - `name` (nullable string): The name your business gave the contact, in the app or through the API. `null` if nobody has. A new WhatsApp profile name never replaces it.
  - `whatsapp_name` (nullable string): The contact's own WhatsApp profile name.
  - `attributes` (object): Your own fields on the contact. Names are 1 to 64 letters, digits or underscores. A map; each value is a string or number or boolean.
  - `tags` (array of strings)
  - `marketing_opt_out` (boolean): Whether the contact opted out of marketing messages.
  - `number_id` (nullable string, uuid): The WhatsApp number the contact is usually messaged from.
  - `chat` (object): The contact's chat. `last_inbound_at` covers any number. The 24-hour window is per number, so don't work it out from this field.
    - `status` (string): One of `open`, `closed`.
    - `assigned_agent_id` (nullable string, uuid)
    - `last_message_at` (nullable string, date-time)
    - `last_inbound_at` (nullable string, date-time)
  - `created_at` (string, date-time)
  - `updated_at` (string, date-time)

```json
{
  "contact_id": "4ea0d485-435d-407f-837a-c7d67095f23a",
  "status": "open",
  "assigned_agent_id": "5b1d7d0e-3c2a-4f61-9a0e-6f8f3b2c1d40",
  "team_id": null,
  "contact": null
}
```