Send a new message

Add a message to a thread or create a new one


Overview #

Add a new message to a thread. The message will be authored by the current user and belong to their current organization.
await window.CordSDK.thread.sendMessage(
  'my-awesome-thread-id',
  {
    id: crypto.randomUUID(),
    content: [{ type: 'p', children: [{ text: 'Amazing job!' }]}],
  }
);
Copy

What this function returns #

A promise that resolves to true if the operation succeeded or rejects if it failed.

Arguments this function takes #


threadID #

required
string
The ID of the thread to add the message to. If this thread does not yet exist, the createThread parameter determines what happens.

data #

required
ClientCreateMessage
The data values for the new message.

This is an object with the following fields:


createThread #

optional
ClientCreateThread
The parameters for creating a thread if the supplied thread doesn't exist yet. If the thread doesn't exist but createThread isn't provided, the call will generate an error. This value is ignored if the thread already exists.

This is an object with the following fields:


name
required
string
The name of the thread. This is shown to users when the thread is referenced, such as in notifications. This should generally be something like the page title.

url
required
string
A URL where the thread can be seen. This determines where a user is sent when they click on a reference to this thread, such as in a notification, or if they click on a reference to a message in the thread and the message doesn't have its own URL.

location
required
Location
The location of this thread.

metadata
optional
EntityMetadata
Arbitrary key-value pairs that can be used to store additional information.

extraClassnames
optional
string | null
An optional space separated list of classnames to add to the thread.

addReactions #

optional
string[]
A list of unicode strings representing the reactions you want to add to this message. Trying to create a reaction that already exists for a user does nothing.

addAttachments #

optional
CreateFileAttachment[]
A list of attachments to add to the message. The same file cannot be attached to the same message multiple times.

content #

required
object[]
The content of the message.

id #

optional
string
The ID for the message. If a message is created with no ID, a random UUID-based ID will be automatically created for it.

iconURL #

optional
string | null
The URL of the icon to show next to the message. This is only used for action_message messages; other messages show the avatar of the author. If an action_message does not have an icon set, no icon is shown.

metadata #

optional
EntityMetadata
Arbitrary key-value pairs that can be used to store additional information.

url #

optional
string | null
A URL where the message can be seen. This determines where a user is sent when they click on a reference to this message, such as in a notification. If unset, it defaults to the thread's URL.

type #

optional
"action_message" | "user_message"
The type of message this is. A user_message is a message that the author sent. An action_message is a message about something that happened, such as the thread being resolved. The default value is user_message.

extraClassnames #

optional
string | null
A optional space separated list of classnames to add to the message.

Ask Cordy