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

# Live Chat

> Integra chat en vivo en tu sitio web con Shimli.

Shimli incluye un widget de chat en vivo que puedes integrar en tu sitio web. Los visitantes pueden chatear con tu equipo en tiempo real, y las conversaciones se sincronizan con el CRM de Shimli.

## Crear una sesión de chat

Cuando un visitante abre el chat, crea una sesión:

```bash theme={null}
curl -X POST https://api.shimli.app/v1/live-chat/session \
  -H "Content-Type: application/json" \
  -d '{
    "token": "TOKEN_SHIMLI",
    "instance": "ID_INSTANCE",
    "name": "Visitante Anónimo"
  }'
```

El campo `name` es opcional. Si lo omites, la sesión se crea sin nombre.

## Enviar un mensaje

```bash theme={null}
curl -X POST https://api.shimli.app/v1/live-chat/ \
  -H "Content-Type: application/json" \
  -d '{
    "token": "TOKEN_SHIMLI",
    "type": "text",
    "body": "¡Hola! ¿En qué te puedo ayudar?",
    "to": "SESSION_ID",
    "instance": "ID_INSTANCE"
  }'
```

## Marcar como enviado por el usuario

Por defecto, los mensajes se marcan como enviados por el agente. Si quieres marcar un mensaje como enviado por el visitante (por ejemplo, al recibir un mensaje del widget):

```json theme={null}
{
  "token": "TOKEN_SHIMLI",
  "type": "text",
  "body": "Quiero información sobre el producto X",
  "to": "SESSION_ID",
  "instance": "ID_INSTANCE",
  "user": true
}
```

## Flujo de integración

<Steps>
  <Step title="Crea la sesión al cargar el widget">
    Cuando el visitante abre tu sitio, crea una sesión con `POST /v1/live-chat/session`.
  </Step>

  <Step title="Muestra los mensajes en el widget">
    Recibe los mensajes del servidor y muéstralos en el chat del lado del cliente.
  </Step>

  <Step title="Envía los mensajes del visitante">
    Cuando el visitante escribe, envía el mensaje con `user: true`.
  </Step>

  <Step title="Maneja en backend los mensajes del agente">
    Tu backend recibe los mensajes del agente y los reenvía al widget.
  </Step>
</Steps>

## Referencia

* [Create Live Chat Session](/api-reference/live-chat/create-session)
* [Send Live Chat Message](/api-reference/live-chat/send-message)
