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 group.
Vanilla JavaScript:
await window.CordSDK.thread.sendMessage(
  'my-awesome-thread-id',
  {
    content: [{ type: 'p', children: [{ text: 'Amazing job!' }]}],
  }
);
await window.CordSDK.thread.sendMessage(
  'my-awesome-thread-id',
  {
    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
Omit<ClientCreateThread, "id">
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.

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

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.

groupID
optional
string
The group ID this thread is in.

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

location
required
Location
The location of this thread.

addSubscribers
optional
string[]
A list of subscribers to add to this 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.

This is an array of objects, each of which has the following fields:


type
required
"file"
The type of attachment. This is file for file attachments.

id
required
string
The ID of the file to attach. This must have been previously uploaded via the file API.

content #

required
object[]
The content of the message.

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.

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.

translationKey #

optional
string | null
An optional translation key used for this message. This is useful for system-generated messages where you might want to translate or customize them at runtime. See the translations documentation for more information.

extraClassnames #

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

skipLinkPreviews #

optional
boolean
If set, Cord won't analyze links in the message to generate previews.

Ask Cordy