Message content

Every message has "content" which specifies the information in the message. This could be some formatted text, a file attachment, or a shared location.

See the conceptual documentation for message content to learn more about how TalkJS represents message content.

class ContentBlock

The content of a message is structured as a list of content blocks.

Currently, each message can only have one content block, but this will change in the future. This will not be considered a breaking change, so your code should assume there can be multiple content blocks.

These blocks are rendered in order, top-to-bottom.

Currently the available Content Block types are:

type: "text" (TextBlock)

type: "file" (FileBlock)

type: "location" (LocationBlock)

Properties

type
: String

data class TextBlock

A block of formatted text in a message's content.

Each TextBlock is a tree of children describing the structure of some formatted text. Each child is either a plain text string, or a node representing some text with additional formatting.

For example, if the user typed:

This first bit is bold, and the second bit is bold and italics

Then this would become a Text Block with the structure:

1TextBlock(
2 type="text",
3 children=listOf(
4 Markup(type="bold", children=listOf("This first bit")),
5 " is bold, and ",
6 Markup(
7 type="bold",
8 children=listOf(
9 Markup(type="italic", children=listOf("the second bit"))
10 ),
11 ),
12 " is bold and italics",
13 ),
14)

Rather than relying the automatic message parsing, you can also specify the TextBlock directly using with .

Properties

children
: List<Any>
type
: String

Always "text"

Full documentation of each TextNode variant

data class Markup

A node in a TextBlock that renders its children with a specific style.

Properties

children
: List<Any>
type
: String

The kind of formatting to apply when rendering the children

type: "bold" is used when users type *text* and is rendered with HTML <strong>

type: "italic" is used when users type _text_ and is rendered with HTML <em>

type: "strikethrough" is used when users type ~text~ and is rendered with HTML <s>

data class BulletList

A node in a TextBlock that adds indentation for a bullet-point list around its children (HTML <ul>).

Used when users send a bullet-point list by starting lines of their message with - or *.

Properties

children
: List<Any>
type
: String

Always "bulletList"

data class BulletPoint

A node in a TextBlock that renders its children with a bullet-point (HTML <li>).

Used when users start a line of their message with - or *.

Properties

children
: List<Any>
type
: String

Always "bulletPoint"

A node in a TextBlock that renders its children as a clickable link (HTML <a>).

By default, users do not have permission to send messages containing Link as it can be used to maliciously hide the true destination of a link.

: List<Any>
: String

Always "link"

: String

The URL to open when the node is clicked.

A node in a TextBlock that renders text as a link (HTML <a>).

Used when user-typed text is turned into a link automatically.

Unlike Link, users do have permission to send AutoLink by default, because the text and url properties must match. Specifically:

If text is an email, url must contain a mailto: link to the same email address

If text is a phone number, url must contain a tel: link to the same phone number

If text is a website, the domain name including subdomains must be the same in both text and url. If text includes a protocol (such as https), path (/page), query string (?page=true), or url fragment (#title), they must be the same in url. If text does not specify a protocol, url must use either https or http.

This means that the following AutoLink is valid:

1AutoLink(
2 type = "autolink",
3 text = "talkjs.com",
4 url = "https://talkjs.com/docs/JavaScript_Data_API/Message_Content/#AutoLinkNode",
5)

That link will appear as talkjs.com and link you to the specific section of the documentation that explains how AutoLink works.

These rules ensure that the user knows what link they are clicking, and prevents AutoLink being used for phishing. If you try to send a message containing an AutoLink that breaks these rules, the request will be rejected.

: String

The text to display in the link.

: String

Always "autolink"

: String

The URL to open when a user clicks this node.

A node in a TextBlock that renders its children as a clickable action link which triggers a custom action.

By default, users do not have permission to send messages containing ActionLink as it can be used maliciously to trick others into invoking custom actions. For example, a user could send an "accept offer" action link, but disguise it as a link to a website.

: String

The name of the custom action to invoke when the link is clicked.

: List<Any>
: Map<String, String>

The parameters to pass to the custom action when the link is clicked.

: String

Always "actionLink"

data class ActionButton

A node in a TextBlock that renders its children as a clickable action button which triggers a custom action.

By default, users do not have permission to send messages containing action buttons as they can be used maliciously to trick others into invoking custom actions. For example, a user could send an "accept offer" action button, but disguise it as "view offer".

Properties

action
: String

The name of the custom action to invoke when the button is clicked.

children
: List<Any>
params
: Map<String, String>

The parameters to pass to the custom action when the button is clicked.

type
: String

Always "actionButton"

data class CodeSpan

A node in a TextBlock that renders text in an inline code span (HTML <code>).

Used when a user types ```text``` .

Properties

text
: String
type
: String

Always "codeSpan"

data class CustomEmoji

A node in a TextBlock that is used for custom emoji.

Properties

text
: String

The name (including colons at the start and end) of the custom emoji to show.

type
: String

Always "customEmoji"

data class Mention

A node in a TextBlock that is used when a user is mentioned.

Used when a user types @name and selects the user they want to mention.

Properties

id
: String

The ID of the user who is mentioned.

text
: String

The name of the user who is mentioned.

type
: String

Always "mention"

class FileBlock

Properties

filename
: String
fileToken
: String
size
: Long
subtype (optional)
: String?
type
: String
url
: String
Full documentation of each FileBlock variant

data class GenericFileBlock

The most basic FileBlock variant, used whenever there is no additional metadata for a file.

Do not try to check for subtype == null directly, as this will break when we add new FileBlock variants in the future.

Instead, treat GenericFileBlock as the default. For example:

1when (block) {
2 is VideoBlock -> handleVideoBlock(block)
3 is ImageBlock -> handleImageBlock(block)
4 is AudioBlock -> handleAudioBlock(block)
5 is VoiceBlock -> handleVoiceBlock(block)
6 else -> handleGenericFileBlock(block)
7}

Properties

filename
: String

The name of the file, including file extension

fileToken
: String

An encoded identifier for this file. Use in SendFileBlock to send this file in another message.

size
: Long

The size of the file in bytes

subtype (optional)
: String?

Never set for generic file blocks.

type
: String

Always "file"

url
: String

The URL where you can fetch the file

data class VideoBlock

A FileBlock variant for a video attachment, with additional video-specific metadata.

You can identify this variant by checking for subtype: "video".

Includes metadata about the height and width of the video in pixels, and the duration of the video in seconds, where available.

Videos that you upload with the TalkJS UI will include the dimensions and duration as long as the sender's browser can preview the file. Videos that you upload with the REST API or will include this metadata if you specified it when uploading. Videos attached in a reply to an email notification will not include any metadata.

Properties

duration (optional)
: Double?

The duration of the video in seconds, if known.

filename
: String

The name of the video file, including file extension.

fileToken
: String

An encoded identifier for this file. Use in SendFileBlock to send this video in another message.

height (optional)
: Int?

The height of the video in pixels, if known.

size
: Long

The size of the file in bytes.

subtype
: String

Always "video"

type
: String

Always "file"

url
: String

The URL where you can fetch the file.

width (optional)
: Int?

The width of the video in pixels, if known.

data class ImageBlock

A FileBlock variant for an image attachment, with additional image-specific metadata.

You can identify this variant by checking for subtype: "image".

Includes metadata about the height and width of the image in pixels, where available.

Images that you upload with the TalkJS UI will include the image dimensions as long as the sender's browser can preview the file. Images that you upload with the REST API or will include the dimensions if you specified them when uploading. Image attached in a reply to an email notification will not include the dimensions.

Properties

filename
: String

The name of the image file, including file extension.

fileToken
: String

An encoded identifier for this file. Use in SendFileBlock to send this image in another message.

height (optional)
: Int?

The height of the image in pixels, if known.

size
: Long

The size of the file in bytes.

subtype
: String

Always "image"

type
: String

Always "file"

url
: String

The URL where you can fetch the file.

width (optional)
: Int?

The width of the image in pixels, if known.

data class AudioBlock

A FileBlock variant for an audio attachment, with additional audio-specific metadata.

You can identify this variant by checking for subtype: "audio".

The same file could be uploaded as either an audio block, or as a VoiceBlock. The same data will be available either way, but they will be rendered differently in the UI.

Includes metadata about the duration of the audio file in seconds, where available.

Audio files that you upload with the TalkJS UI will include the duration as long as the sender's browser can preview the file. Audio files that you upload with the REST API or will include the duration if you specified it when uploading. Audio files attached in a reply to an email notification will not include the duration.

Properties

duration (optional)
: Double?

The duration of the audio in seconds, if known

filename
: String

The name of the audio file, including file extension

fileToken
: String

An encoded identifier for this file. Use in SendFileBlock to send this file in another message.

size
: Long

The size of the file in bytes

subtype
: String

Always "audio"

type
: String

Always "file"

url
: String

The URL where you can fetch the file

data class VoiceBlock

A FileBlock variant for a voice recording attachment, with additional voice-recording-specific metadata.

You can identify this variant by checking for subtype: "voice".

The same file could be uploaded as either a voice block, or as an AudioBlock. The same data will be available either way, but they will be rendered differently in the UI.

Includes metadata about the duration of the recording in seconds, where available.

Voice recordings done in the TalkJS UI will always include the duration. Voice recording that you upload with the REST API or will include this metadata if you specified it when uploading.

Voice recordings will never be taken from a reply to an email notification. Any attached audio file will become an AudioBlock instead of a voice block.

Properties

duration (optional)
: Double?

The duration of the voice recording in seconds, if known

filename
: String

The name of the file, including file extension

fileToken
: String

An encoded identifier for this file. Use in SendFileBlock to send this voice recording in another message.

size
: Long

The size of the file in bytes

subtype
: String

Always "voice"

type
: String

Always "file"

url
: String

The URL where you can fetch the file

data class LocationBlock

A block showing a location in the world, typically because a user shared their location in the chat.

In the TalkJS UI, location blocks are rendered as a link to Google Maps, with the map pin showing at the specified coordinate. A thumbnail shows the surrounding area on the map.

Properties

latitude
: Double

The north-south coordinate of the location.

Usually listed first in a pair of coordinates.

Must be a number between -90 and 90

longitude
: Double

The east-west coordinate of the location.

Usually listed second in a pair of coordinates.

Must be a number between -180 and 180

type
: String

Always "location"

data class SendFileBlock

The version of FileBlock that is used when sending or editing messages.

When a user receives the message you send with SendFileBlock, this block will have turned into one of the FileBlock variants.

For information on how to obtain a file token, see FileToken.

The SendFileBlock interface is a subset of the FileBlock interface. If you have an existing FileBlock received in a message, you can re-use that block to re-send the same attachment:

1val existingFileBlock = ...
2val imageToShare = existingFileBlock.content[0] as ImageBlock
3
4val convRef = session.conversation("example_conversation_id")
5convRef.send(SendMessageParams(content=listOf(imageToShare)));

Properties

fileToken
: String

The encoded identifier for the file, obtained by uploading a file with Session.sendFile, or taken from another message.

type
: String

Always "file"