1. Threads And Channels
  2. Write & Update Messages

Threads And Channels

Write & Update Messages

In order to write messages, you have to write to a thread about a specific resource. If the resource has a third party associated with it, the message will automatically be published to a channel.

if a third party receives a message, they are able to respond by replying to the email or sms. The response will be added to the thread and channel.

Create a message

POST
`/v1/threads/:thread`

You don't need to create the thread since it uses a predicable URL schema. Take whatever resource you want to discuss on the thread and prefix thrd_ to get the ID of the thread. If the thread did not previously exist, it will automatically be created.

js
        const data = {
  text: "Hello, this is my first thread message!",
};

// This thread will be about a delivery with the ID del_cv8ynU5WyJSEWHXAgSjcKt
fetch(`https://api.packagex.io/v1/threads/thrd_del_cv8ynU5WyJSEWHXAgSjcKt`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
});

      

Update a message

When updating or editing messages you can either include the message ID in the URL, or just keep the endpoint as /v1/threads/:thread and include a message_id parameter in the request body.

POST
`/v1/threads/:thread/messages/:message`

You can update a message by posting to the message ID.

js
        const data = {
  text: "Hello, this is my first thread message that I edited!!!",
};

fetch(`https://api.packagex.io/v1/threads/thrd_del_cv8ynU5WyJSEWHXAgSjcKt/messages/msg_nh2huipTftu4svtVkSpzoo`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
});

      

Delete a message

You can only delete a message if you are the publisher of the message.

DELETE
`/v1/threads/:thread/messages/:message`
js
        fetch(`https://api.packagex.io/v1/threads/thrd_del_cv8ynU5WyJSEWHXAgSjcKt/messages/1676406647`, {
  method: "DELETE",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
});

      

Add a reaction

POST
`/v1/threads/:thread/messages/:message`

You can update a message by posting to the message ID.

js
        const data = {
  reaction: "😋",
};

fetch(`https://api.packagex.io/v1/threads/thrd_del_cv8ynU5WyJSEWHXAgSjcKt/messages/msg_nh2huipTftu4svtVkSpzoo`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
});

      

Remove a reaction

POST
`/v1/threads/:thread/messages/:message`

Removing a reaction is the same process as adding one but you explicitly set the reaction to a null value.

js
        const data = {
  reaction: null,
};

fetch(`https://api.packagex.io/v1/threads/thrd_del_cv8ynU5WyJSEWHXAgSjcKt/messages/msg_nh2huipTftu4svtVkSpzoo`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
});