Message content

View as Markdown

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)

Method Overview

constructor

ContentBlock()

toJson

Map<String, dynamic> contentBlock.toJson()

Returns

Map<String, dynamic>

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 children: [
3 Markup(type: 'bold', children: ['This first bit']),
4 ' is bold, and ',
5 Markup(
6 type: 'bold',
7 children: [
8 Markup(type: 'italic', children: ['the second bit']),
9 ],
10 ),
11 ' is bold and italics',
12 ],
13)

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

Method Overview

Properties

children
: List<Object>

The tree of formatted text nodes.

type
: String

constructor

TextBlock({required children})

Parameters

required children (named)
: List<Object>

toJson

Map<String, dynamic> textBlock.toJson()

Returns

Map<String, dynamic>
Full documentation of each TextNode variant

class Markup

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

Method Overview

Properties

children
: List<Object>
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>

constructor

Markup({required type, required children})

Parameters

required type (named)
: String
required children (named)
: List<Object>

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 *.

Method Overview

Properties

children
: List<Object>
type
: String

constructor

BulletList({required children})

Parameters

required children (named)
: List<Object>

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 *.

Method Overview

Properties

children
: List<Object>
type
: String

constructor

BulletPoint({required children})

Parameters

required children (named)
: List<Object>

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<Object>
: String
: String

The URL to open when the node is clicked.

Link({required url, required children})

Parameters

: String
: List<Object>
Map<String, dynamic> link.toJson()

Returns

Map<String, dynamic>

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 text: 'talkjs.com',
3 url: 'https://talkjs.com/docs/JavaScript_Data_API/Message_Content/#AutoLinkNode',
4)

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
: String

The URL to open when a user clicks this node.

AutoLink({required url, required text})

Parameters

: String
: String
Map<String, dynamic> autoLink.toJson()

Returns

Map<String, dynamic>

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<Object>
: Map<String, String>

The parameters to pass to the custom action.

: String
ActionLink({required action, required params, required children})

Parameters

: String
: Map<String, String>
: List<Object>
Map<String, dynamic> actionLink.toJson()

Returns

Map<String, dynamic>

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".

Method Overview

Properties

action
: String

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

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

The parameters to pass to the custom action.

type
: String

constructor

ActionButton({required action, required params, required children})

Parameters

required action (named)
: String
required params (named)
: Map<String, String>
required children (named)
: List<Object>

toJson

Map<String, dynamic> actionButton.toJson()

Returns

Map<String, dynamic>

class CodeSpan

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

Used when a user types text .

Method Overview

Properties

text
: String
type
: String

constructor

CodeSpan({required text})

Parameters

required text (named)
: String

class CustomEmoji

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

Method Overview

Properties

text
: String

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

type
: String

constructor

CustomEmoji({required text})

Parameters

required text (named)
: String

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.

Method Overview

Properties

id
: String

The ID of the user who is mentioned.

text
: String

The name of the user who is mentioned.

type
: String

constructor

Mention({required id, required text, internalId})

Parameters

required id (named)
: String
required text (named)
: String
internalId (named)
: String?

toJson

Map<String, dynamic> mention.toJson()

Returns

Map<String, dynamic>

class FileBlock

Method Overview

constructor

FileBlock()

toJson

Map<String, dynamic> fileBlock.toJson()

Returns

Map<String, dynamic>
Full documentation of each FileBlock variant

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:

1switch (block) {
2 case VideoBlock():
3 handleVideoBlock(block);
4 case ImageBlock():
5 handleImageBlock(block);
6 case AudioBlock():
7 handleAudioBlock(block);
8 case VoiceBlock():
9 handleVoiceBlock(block);
10 default:
11 handleGenericFileBlock(block);
12}

Method Overview

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
: int

The size of the file in bytes

subtype (optional)
: String?

Never set for generic file blocks.

type
: String
url
: String

The URL where you can fetch the file

constructor

GenericFileBlock({required fileToken, required url, required size, required filename})

Parameters

required fileToken (named)
: String
required url (named)
: String
required size (named)
: int
required filename (named)
: String

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 TalkSession.uploadVideo will include this metadata if you specified it when uploading. Videos attached in a reply to an email notification will not include any metadata.

Method Overview

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
: int

The size of the file in bytes.

subtype
: String
type
: String
url
: String

The URL where you can fetch the file.

width (optional)
: int?

The width of the video in pixels, if known.

constructor

VideoBlock({required fileToken, required url, required size, required filename, width, height, duration})

Parameters

required fileToken (named)
: String
required url (named)
: String
required size (named)
: int
required filename (named)
: String
width (named)
: int?
height (named)
: int?
duration (named)
: double?

toJson

Map<String, dynamic> videoBlock.toJson()

Returns

Map<String, dynamic>

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 TalkSession.uploadImage will include the dimensions if you specified them when uploading. Image attached in a reply to an email notification will not include the dimensions.

Method Overview

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
: int

The size of the file in bytes.

subtype
: String
type
: String
url
: String

The URL where you can fetch the file.

width (optional)
: int?

The width of the image in pixels, if known.

constructor

ImageBlock({required fileToken, required url, required size, required filename, width, height})

Parameters

required fileToken (named)
: String
required url (named)
: String
required size (named)
: int
required filename (named)
: String
width (named)
: int?
height (named)
: int?

toJson

Map<String, dynamic> imageBlock.toJson()

Returns

Map<String, dynamic>

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 TalkSession.uploadAudio 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.

Method Overview

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
: int

The size of the file in bytes

subtype
: String
type
: String
url
: String

The URL where you can fetch the file

constructor

AudioBlock({required fileToken, required url, required size, required filename, duration})

Parameters

required fileToken (named)
: String
required url (named)
: String
required size (named)
: int
required filename (named)
: String
duration (named)
: double?

toJson

Map<String, dynamic> audioBlock.toJson()

Returns

Map<String, dynamic>

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 TalkSession.uploadVoice 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.

Method Overview

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
: int

The size of the file in bytes

subtype
: String
type
: String
url
: String

The URL where you can fetch the file

constructor

VoiceBlock({required fileToken, required url, required size, required filename, duration})

Parameters

required fileToken (named)
: String
required url (named)
: String
required size (named)
: int
required filename (named)
: String
duration (named)
: double?

toJson

Map<String, dynamic> voiceBlock.toJson()

Returns

Map<String, dynamic>

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.

Method Overview

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

constructor

LocationBlock({required latitude, required longitude})

Parameters

required latitude (named)
: double
required longitude (named)
: double

toJson

Map<String, dynamic> locationBlock.toJson()

Returns

Map<String, dynamic>

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 .

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:

1final existingFileBlock = ...
2final imageToShare = existingFileBlock.content[0] as ImageBlock;
3
4final convRef = await session.conversation('example_conversation_id');
5await convRef.sendMessage(SendMessageParams(content: [imageToShare]));

Method Overview

Properties

fileToken
: String

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

type
: String

constructor

SendFileBlock({required fileToken})

Parameters

required fileToken (named)
: String

toJson

Map<String, dynamic> sendFileBlock.toJson()

Returns

Map<String, dynamic>