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

# Cerrar conversación

> Cierra una conversación activa con un usuario final

## Descripción

Cierra una conversación activa en el panel de atención externo. Permite especificar un mensaje de cierre que se enviará al usuario y la razón del cierre.

Al ejecutarse, Jelou emite el evento `conversation.close` hacia el webhook configurado en la integración.

## Endpoint

```
POST https://gateway.jelou.ai/platform/v1/external-support/{projectId}/conversations/close
```

## Parámetros de ruta

**projectId** `string` *required*

Identificador único del proyecto de Jelou desde el que se cierra la conversación.

## Parámetros del cuerpo

**botId** `string` *required*

Identificador del canal de Jelou asociado a la conversación.

**userId** `string` *required*

Identificador del usuario final cuya conversación se desea cerrar.

**redirectPayload** `object`

Mensaje que se enviará al usuario al momento del cierre de la conversación.

* `type` — Tipo de mensaje: `text` o `edge`.
* `text` — Texto del mensaje de cierre (cuando `type` es `text`).

## Autenticación

Todas las peticiones deben incluir el encabezado `x-api-key` con la API key del proyecto de Jelou.

```
x-api-key: API_KEY
```

## Ejemplo de solicitud

El siguiente ejemplo cierra la conversación del usuario `USER_ID` e incluye un mensaje de cierre:

```bash cURL theme={null}
curl --request POST \
  --url https://gateway.jelou.ai/platform/v1/external-support/PROJECT_ID/conversations/close \
  --header 'x-api-key: API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "botId": "BOT_ID",
    "userId": "USER_ID",
    "redirectPayload": {
      "type": "text",
      "text": "Mensaje de cierre de conversación"
    }
  }'
```

## Respuestas

| Código | Estado | Descripción |
| - | - | - |
| 200 | OK | Conversación cerrada exitosamente. |
| 401 | Unauthorized | Credenciales de autenticación inválidas o faltantes. |
| 404 | Not Found | Canal o usuario no encontrado. |
| 422 | Unprocessable Entity | Los campos enviados contienen valores inválidos o no cumplen las validaciones esperadas. |
| 500 | Internal Server Error | Error interno del servidor. |

## Ejemplo de respuesta

```json theme={null}
{
  "message": [
    "Conversation closed successfully"
  ],
  "statusMessage": "success",
  "status": 1,
  "data": {
    "conversationId": "CONVERSATION_ID",
    "status": "closed",
    "endedReason": "closed_by_operator"
  }
}
```

***

## Evento webhook `conversation.close`

Al ejecutar este recurso, Jelou emitirá el evento `conversation.close` al webhook configurado en la integración. El payload incluye la razón del cierre y el mensaje enviado al usuario.

```json theme={null}
{
  "event": "conversation.close",
  "timestamp": 1777992928697,
  "field": "conversation",
  "object": "conversation_event",
  "event_type": "close",
  "project_id": "PROJECT_ID",
  "room_id": "ROOM_ID",
  "contact": {
    "id": "USER_ID",
    "name": "USER_NAME"
  },
  "conversation": {
    "id": "CONVERSATION_ID"
  },
  "bot": {
    "id": "BOT_ID",
    "name": "BOT_NAME"
  },
  "value": {
    "reason": "closed_by_operator",
    "redirectPayload": {
      "type": "text",
      "text": "Mensaje de cierre de conversación"
    }
  }
}
```

### Campos del payload

| Campo | Tipo | Descripción |
| - | - | - |
| `event` | string | Nombre del evento: `conversation.close` |
| `timestamp` | number | Marca de tiempo Unix en milisegundos del momento del evento. |
| `project_id` | string | Identificador del proyecto de Jelou. |
| `room_id` | string | Identificador de la sala de conversación. |
| `contact.id` | string | Identificador del usuario final. |
| `contact.name` | string | Nombre del usuario final. |
| `conversation.id` | string | Identificador único de la conversación cerrada. |
| `bot.id` | string | Identificador del canal asociado. |
| `bot.name` | string | Nombre del canal asociado. |
| `value.reason` | string | Razón del cierre: `closed_by_operator`. |
| `value.redirectPayload.type` | string | Tipo del mensaje de cierre: `text` o `edge`. |
| `value.redirectPayload.text` | string | Texto del mensaje enviado al usuario al cerrar (opcional). |


## OpenAPI

````yaml POST /v1/external-support/{projectId}/conversations/close
openapi: 3.1.0
info:
  title: Jelou API
  description: >-
    API for the Jelou platform. Send messages, manage campaigns, handle
    conversations, users, databases, and widgets.
  version: 1.0.0
servers:
  - url: https://api.jelou.ai
    description: Production server
security:
  - basicAuth: []
tags:
  - name: Messages
    description: Send messages to users
  - name: Campaigns
    description: HSM campaigns and templates
  - name: Conversations
    description: Chat history and metrics
  - name: Users
    description: User state and cache management
  - name: Clients
    description: WhatsApp clients of the company
  - name: Resources
    description: Media resource management
  - name: Datum
    description: Database CRUD operations
  - name: Widget
    description: Widget and room management
  - name: PMA Custom
    description: External support panel integration
  - name: Memory
    description: Per-user session memory management (Memory API v2)
paths:
  /v1/external-support/{projectId}/conversations/close:
    servers:
      - url: https://gateway.jelou.ai/platform
        description: External Support Panel API
    post:
      tags:
        - External Support Panel
      summary: Close Conversation
      description: Close an active conversation in the external support panel.
      operationId: closeExternalConversation
      parameters:
        - name: projectId
          in: path
          required: true
          description: Unique identifier of the Jelou project
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - botId
                - userId
              properties:
                botId:
                  type: string
                userId:
                  type: string
                redirectPayload:
                  type: object
                  properties:
                    type:
                      type: string
                    text:
                      type: string
      responses:
        '200':
          description: Conversation closed successfully
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - apiKey: []
components:
  responses:
    Unauthorized:
      description: Unauthorized - Invalid authentication credentials
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: Not found - Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    UnprocessableEntity:
      description: Unprocessable entity - Validation error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      properties:
        message:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
        statusMessage:
          type: string
        status:
          type: integer
        error:
          type: object
          properties:
            code:
              type: string
            key:
              type: string
            description:
              type: string
            developerMessages:
              type: object
            clientMessages:
              type: object
        validationError:
          type: object
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
      description: Basic authentication using Base64 encoded clientId:clientSecret
    apiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: API key del proyecto de Jelou

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.