Messages

Los mensajes son de lo que están hechas las conversaciones en el Protocolo: son los componentes básicos de sus conversaciones con sus contactos de Protocolo. En esta página, analizaremos los diferentes puntos finales de mensajes que puede usar para administrar mensajes mediante programación. Veremos cómo consultar, enviar, actualizar y eliminar mensajes.

The message model

El modelo de mensajes contiene toda la información sobre los mensajes y archivos adjuntos que envías a tus contactos y grupos, incluida la reacción de tus contactos ante ellos.

Properties

  • Name
    id
    Type
    string
    Description

    Identificador único del mensaje.

  • Name
    conversation_id
    Type
    string
    Description

    Identificador único de la conversación a la que pertenece el mensaje.

  • Name
    contact
    Type
    object
    Description

    El objeto de contacto para el contacto que envió el mensaje.

  • Name
    message
    Type
    string
    Description

    El contenido del mensaje.

  • Name
    reactions
    Type
    array
    Description

    Una matriz de objetos de reacción asociados con el mensaje.

  • Name
    attachments
    Type
    array
    Description

    Una matriz de objetos adjuntos asociados con el mensaje.

  • Name
    read_at
    Type
    timestamp
    Description

    Marca de tiempo de cuándo se leyó el mensaje.

  • Name
    created_at
    Type
    timestamp
    Description

    Marca de tiempo de cuándo se creó el mensaje.

  • Name
    updated_at
    Type
    timestamp
    Description

    Marca de tiempo de la última vez que se actualizó el mensaje.


GET/v1/messages

List all messages

Este punto final le permite recuperar una lista paginada de todos sus mensajes (en una conversación si se proporciona un id de conversación). Por defecto, se muestran un máximo de diez mensajes por página.

Optional attributes

  • Name
    conversation_id
    Type
    string
    Description

    Limitar a los mensajes de una conversación determinada.

  • Name
    limit
    Type
    integer
    Description

    Limite el número de mensajes devueltos.

Request

GET
/v1/messages
curl -G https://api.protocol.chat/v1/messages \
  -H "Authorization: Bearer {token}" \
  -d conversation_id=xgQQXg3hrtjh7AvZ \
  -d limit=10

Response

{
  "has_more": false,
  "data": [
    {
      "id": "SIuAFUNKdSYHZF2w",
      "conversation_id": "xgQQXg3hrtjh7AvZ",
      "contact": {
        "id": "WAz8eIbvDR60rouK",
        "username": "KevinMcCallister",
        "phone_number": "1-800-759-3000",
        "avatar_url": "https://assets.protocol.chat/avatars/buzzboy.jpg",
        "last_active_at": 705103200,
        "created_at": 692233200
      },
      "message": "It’s a nice night for a neck injury.",
      "reactions": [],
      "attachments": [],
      "read_at": 705103200,
      "created_at": 692233200,
      "updated_at": 692233200
    },
    {
      "id": "hSIhXBhNe8X1d8Et",
      // ..
    }
  ]
}

POST/v1/messages

Send a message

Este punto final le permite enviar un nuevo mensaje a una de sus conversaciones.

Required attributes

  • Name
    conversation_id
    Type
    string
    Description

    Identificador único de la conversación a la que pertenece el mensaje.

  • Name
    message
    Type
    string
    Description

    El contenido del mensaje.

Optional attributes

  • Name
    attachments
    Type
    array
    Description

    Una matriz de objetos adjuntos asociados con el mensaje.

Request

POST
/v1/messages
curl https://api.protocol.chat/v1/messages \
  -H "Authorization: Bearer {token}" \
  -d conversation_id="xgQQXg3hrtjh7AvZ" \
  -d message="You’re what the French call ‘les incompetents.’"

Response

{
  "id": "gWqY86BMFRiH5o11",
  "conversation_id": "xgQQXg3hrtjh7AvZ",
  "contact": {
    "id": "inEIRvzjC6YLMX3o",
    "username": "LinnieMcCallister",
    "phone_number": "1-800-759-3000",
    "avatar_url": "https://assets.protocol.chat/avatars/linnie.jpg",
    "last_active_at": 705103200,
    "created_at": 692233200
  },
  "message": "You’re what the French call ‘les incompetents.’",
  "reactions": [],
  "attachments": [],
  "read_at": null,
  "created_at": 692233200,
  "updated_at": null
}

GET/v1/messages/:id

Retrieve a message

Este extremo le permite recuperar un mensaje proporcionando el ID del mensaje. Consulte the list en la parte superior de esta página, para ver qué propiedades se incluyen con los objetos de mensaje.

Request

GET
/v1/messages/SIuAFUNKdSYHZF2w
curl https://api.protocol.chat/v1/messages/SIuAFUNKdSYHZF2w \
  -H "Authorization: Bearer {token}"

Response

{
  "id": "SIuAFUNKdSYHZF2w",
  "conversation_id": "xgQQXg3hrtjh7AvZ",
  "contact": {
    "id": "WAz8eIbvDR60rouK",
    "username": "KevinMcCallister",
    "phone_number": "1-800-759-3000",
    "avatar_url": "https://assets.protocol.chat/avatars/kevin.jpg",
    "last_active_at": 705103200,
    "created_at": 692233200
  },
  "message": "I’m traveling with my dad. He’s at a meeting. I hate meetings.",
  "reactions": [],
  "attachments": [],
  "read_at": 705103200,
  "created_at": 692233200,
  "updated_at": 692233200
}

PUT/v1/messages/:id

Update a message

Este punto final le permite realizar una actualización de un mensaje. Ejemplos de actualizaciones son agregar una reacción, editar el mensaje o agregar un archivo adjunto.

Optional attributes

  • Name
    message
    Type
    string
    Description

    El contenido del mensaje.

  • Name
    reactions
    Type
    array
    Description

    Una matriz de objetos de reacción asociados con el mensaje.

  • Name
    attachments
    Type
    array
    Description

    Una matriz de objetos adjuntos asociados con el mensaje.

Request

PUT
/v1/messages/SIuAFUNKdSYHZF2w
curl -X PUT https://api.protocol.chat/v1/messages/SIuAFUNKdSYHZF2w \
  -H "Authorization: Bearer {token}" \
  -d reactions[red_angry_face][]="KateMcCallister"

Response

{
  "id": "SIuAFUNKdSYHZF2w",
  "conversation_id": "xgQQXg3hrtjh7AvZ",
  "contact": {
    "id": "WAz8eIbvDR60rouK",
    "username": "KevinMcCallister",
    "phone_number": "1-800-759-3000",
    "avatar_url": "https://assets.protocol.chat/avatars/buzzboy.jpg",
    "last_active_at": 705103200,
    "created_at": 692233200
  },
  "message": "I'm not apologizing. I'd rather kiss a toilet seat.",
  "reactions": [
    {
      "red_angry_face": [
        "KateMcCallister"
      ]
    }
  ],
  "attachments": [],
  "read_at": 705103200,
  "created_at": 692233200,
  "updated_at": 692233200
}

DELETE/v1/messages/:id

Delete a message

Este punto final le permite eliminar mensajes de sus conversaciones. Nota: Esto eliminará permanentemente el mensaje.

Request

DELETE
/v1/messages/SIuAFUNKdSYHZF2w
curl -X DELETE https://api.protocol.chat/v1/messages/SIuAFUNKdSYHZF2w \
  -H "Authorization: Bearer {token}"