Messages
A message contains some content that was sent in a conversation. Users send messages using ConversationRef.send. You can track the a conversation's messages in real-time using ConversationRef.subscribeMessages.
messageRef.edit(params): Unit
Parameters
interface EditTextMessageParams
Parameters you can pass when editing a message.
Properties that are undefined will not be changed. To clear / reset a property to the default, pass null.
Custom metadata you have set on the user. This value acts as a patch. Remove specific properties by setting them to null. Default = no custom metadata
The new text to set as the message body
interface EditMessageParams
Parameters you can pass to {@link MessageRef.edit}.
Properties that are undefined will not be changed. To clear / reset a property to the default, pass null.
This is the more advanced method for editing a message. It gives you full control over the message content. You can decide exactly how a text message should be formatted, edit an attachment, or even turn a text message into a location.
Custom metadata you have set on the message. This value acts as a patch. Remove specific properties by setting them to null. Default = no custom metadata
The new content for the message.
Any value provided here will overwrite the existing message content.
By default users do not have permission to send {@link LinkNode}, {@link ActionLinkNode}, or {@link ActionButtonNode}, as they can be used to trick the recipient.
Returns
messageRef.edit(params): Unit
Parameters
interface EditTextMessageParams
Parameters you can pass when editing a message.
Properties that are undefined will not be changed. To clear / reset a property to the default, pass null.
Custom metadata you have set on the user. This value acts as a patch. Remove specific properties by setting them to null. Default = no custom metadata
The new text to set as the message body
interface EditMessageParams
Parameters you can pass to {@link MessageRef.edit}.
Properties that are undefined will not be changed. To clear / reset a property to the default, pass null.
This is the more advanced method for editing a message. It gives you full control over the message content. You can decide exactly how a text message should be formatted, edit an attachment, or even turn a text message into a location.
Custom metadata you have set on the message. This value acts as a patch. Remove specific properties by setting them to null. Default = no custom metadata
The new content for the message.
Any value provided here will overwrite the existing message content.
By default users do not have permission to send {@link LinkNode}, {@link ActionLinkNode}, or {@link ActionButtonNode}, as they can be used to trick the recipient.
Returns
messageRef.edit(params): Unit
Parameters
interface EditTextMessageParams
Parameters you can pass when editing a message.
Properties that are undefined will not be changed. To clear / reset a property to the default, pass null.
Custom metadata you have set on the user. This value acts as a patch. Remove specific properties by setting them to null. Default = no custom metadata
The new text to set as the message body
interface EditMessageParams
Parameters you can pass to {@link MessageRef.edit}.
Properties that are undefined will not be changed. To clear / reset a property to the default, pass null.
This is the more advanced method for editing a message. It gives you full control over the message content. You can decide exactly how a text message should be formatted, edit an attachment, or even turn a text message into a location.
Custom metadata you have set on the message. This value acts as a patch. Remove specific properties by setting them to null. Default = no custom metadata
The new content for the message.
Any value provided here will overwrite the existing message content.
By default users do not have permission to send {@link LinkNode}, {@link ActionLinkNode}, or {@link ActionButtonNode}, as they can be used to trick the recipient.
Returns
messageRef.delete(): Unit
Returns
A snapshot of a message's attributes at a given moment in time.
Automatically expanded to include a snapshot of the user that sent the message, and a snapshot of the referenced message, if this message is a reply.
The unique ID that is used to identify the message in TalkJS
Whether this message was "from a user" or a general system message without a specific sender.
The sender property is always present for "UserMessage" messages and never present for "SystemMessage" messages.
A snapshot of the user who sent the message, or null if it is a system message. The user's attributes may have been updated since they sent the message, in which case this snapshot contains the updated data. It is not a historical snapshot.
Custom metadata you have set on the message
Time at which the message was sent, as a unix timestamp in milliseconds.
Time at which the message was last edited, as a unix timestamp in milliseconds. null if the message has never been edited.
A snapshot of the message that this message is aa reply to, or null if this message is not a reply.
Only UserMessages can reference other messages. The referenced message snapshot does not have a referencedMessage field. Instead, it has referencedMessageId. This prevents TalkJS fetching an unlimited number of messages in a long chain of replies.
Where this message origiranted from:
"web" = Message sent via the UI or via ConversationBuilder.sendMessage
"rest" = Message sent via the REST API's "send message" endpoint
"import" = Message sent via the REST API's "import messages" endpoint
"email" = Message sent by replying to an email notification
The contents of the message, as a plain text string without any formatting or attachments. Useful for showing in a conversation list or in notifications.
The main body of the message, as a list of blocks that are rendered top-to-bottom.
All the emoji reactions that have been added to this message.
There can be up to 50 different reactions on each message.
new MessageSnapshot.constructor(id, type, sender, custom, createdAt, editedAt, referencedMessage, origin, plaintext, content, reactions)
Parameters
The current state of the subscription
An object with the following fields:
type is one of "pending", "active", "unsubscribed", or "error".
When type is "active", includes latestSnapshot and loadedAll.
latestSnapshot: MessageSnapshot[] | null the current state of the messages in the window, or null if you're not a participant in the conversation
loadedAll: boolean true when latestSnapshot contains all the messages in the conversation
When type is "error", includes the error field. It is a JS Error object explaining what caused the subscription to be terminated.
Resolves when the subscription starts receiving updates from the server.
Wait for this promise if you want to perform some action as soon as the subscription is active.
The promise rejects if the subscription is terminated before it connects.
Resolves when the subscription permanently stops receiving updates from the server.
This is either because you unsubscribed or because the subscription encountered an unrecoverable error.
Unsubscribe from this resource and stop receiving updates.
If the subscription is already in the "unsubscribed" or "error" state, this is a no-op.
Expand the window to include older messages
Calling loadMore multiple times in parallel will still only load one page of messages.
reactionRef.add(): Unit
Returns
reactionRef.remove(): Unit
Returns
A summary of a single emoji reaction on a message.
Which emoji the users reacted with.
Either a single Unicode emoji, or the name of a custom emoji with a colon at the start and end. Since custom emoji are defined in the frontend, they are not validated by the TalkJS server. The UI should ignore reactions that use unrecognised custom emoji.
NOTE: In unicode, it is possible to have multiple emoji that look identical but are represented differently. For example, "👍" !== "👍️" because the second emoji includes a {@link https://en.wikipedia.org/wiki/Variation_Selectors_(Unicode_block) | variation selector 16 codepoint}. This codepoint forces the character to appear as an emoji.
TalkJS normalises all emoji reactions to be "fully qualified" {@link https://unicode.org/Public/emoji/16.0/emoji-test.txt | according to this list}. This prevents a message having multiple separate 👍 reactions.
Be careful when processing the emoji property, as this normalisation might break equality checks:
1// Emoji has unnecessary variation selector 16const sent = "👍"// React with thumbs up,await message.reaction(emoji).add()// Fetch the reactionconst snapshot = await message.get();const received = snapshot.reactions[0].emoji;// Fails because TalkJS removed the variation selectorassert sent === received;
The number of times this emoji has been added to the message.
Whether the current user has reacted to the message with this emoji.