RestAnnotations

The RestAnnotations object lets you publish, delete, and retrieve annotations on messages. Access it via the annotations property of a Channel.

Subscribing to individual annotations in realtime requires the realtime SDK's RealtimeAnnotations interface.

JavaScript

1

const annotations = channel.annotations;

Publish an annotation

annotations.publish(message: Message, annotation: OutboundAnnotation): Promise<void>

Publish an annotation to a message identified by a Message object.

annotations.publish(messageSerial: string, annotation: OutboundAnnotation): Promise<void>

Publish an annotation to a message identified by its serial string.

The action is set automatically to annotation.create. If a clientId is set on the client, it is associated with the annotation; some annotation summarization methods require an identified client.

Parameters

messagerequiredMessage
A Message object identifying the message to annotate. Provide either message or messageSerial.
messageSerialrequiredString
The serial string of the message to annotate. Provide either message or messageSerial.
annotationrequiredOutboundAnnotation
The annotation to publish. Must include at least a type; other required fields depend on the annotation type.

Returns

Promise<void>

Returns a promise. The promise is fulfilled when the annotation has been published to Ably, or rejected with an ErrorInfo object.

Delete an annotation

annotations.delete(message: Message, annotation: OutboundAnnotation): Promise<void>

Remove an annotation contribution from a message identified by a Message object.

annotations.delete(messageSerial: string, annotation: OutboundAnnotation): Promise<void>

Remove an annotation contribution from a message identified by its serial string.

This removes the contribution this clientId previously made to the annotation summary for the message. The exact behaviour depends on the annotation type. The action is set automatically to annotation.delete. The annotation must include a type and may include a name.

Parameters

messagerequiredMessage
A Message object identifying the message whose annotation you want to delete. Provide either message or messageSerial.
messageSerialrequiredString
The serial string of the message whose annotation you want to delete. Provide either message or messageSerial.
annotationrequiredOutboundAnnotation
The annotation deletion request. Must include at least a type; other required fields depend on the annotation type.

Returns

Promise<void>

Returns a promise. The promise is fulfilled when the deletion request has been published to Ably, or rejected with an ErrorInfo object.

Get annotations for a message

annotations.get(message: Message, params: GetAnnotationsParams | null): Promise<PaginatedResult<Annotation>>

Retrieve all annotations for a message identified by a Message object.

annotations.get(messageSerial: string, params: GetAnnotationsParams | null): Promise<PaginatedResult<Annotation>>

Retrieve all annotations for a message identified by its serial string.

Annotations are returned ordered from earliest to most recent. If you only need the latest summary, prefer channel.getMessage(); use annotations.get() only when you need the full list of raw annotations.

Parameters

messagerequiredMessage
A Message object identifying the message to get annotations for. Provide either message or messageSerial.
messageSerialrequiredString
The serial string of the message to get annotations for. Provide either message or messageSerial.
paramsrequiredGetAnnotationsParams or Null
Restrictions on which annotations to return, in particular a limit. Pass null to apply no restrictions; the argument cannot be omitted.

Returns

Promise<PaginatedResult<Annotation>>

Returns a promise, fulfilled with a PaginatedResult containing an array of Annotation objects, or rejected with an ErrorInfo object.

idString
Unique ID assigned by Ably to this annotation.
clientIdString
The client ID of the publisher of this annotation, if any.
nameString
The name of the annotation. This is the field that most annotation aggregations operate on.
countNumber
An optional count, only relevant to the multiple.v1 annotation type.
dataAny
An optional publisher-provided payload. Available on individual annotations but not aggregated or included in annotation summaries.
encodingString
The encoding of the payload; typically empty as annotations received from Ably are automatically decoded client-side using this value. However, if the annotation encoding cannot be processed, this attribute contains the remaining transformations not applied to the data payload.
timestampNumber
Timestamp of when the annotation was received by Ably, as milliseconds since the Unix epoch.
actionAnnotationAction
The action, whether this is an annotation being added or removed.
serialString
This annotation's unique serial, lexicographically totally ordered.
messageSerialString
The serial of the message that this annotation is annotating.
typeString
The annotation type, typically a name together with an aggregation method, for example emoji:distinct.v1.
extrasAny
Metadata and/or ancillary payloads, if provided. Valid payloads include push, headers (a map of strings to strings for arbitrary customer-supplied metadata), ephemeral, and privileged objects.

Create an annotation from an encoded object

Annotation.fromEncoded(encodedAnnotation: Object, channelOptions?: ChannelOptions): Promise<Annotation>

A static factory method to create an Annotation from a deserialized Annotation-like object encoded using Ably's wire protocol. Accessed on the class as Ably.Rest.Annotation. The returned promise resolves with the decoded annotation.

JavaScript

1

const annotation = await Ably.Rest.Annotation.fromEncoded(encodedAnnotation);

Parameters

The Annotation.fromEncoded() method takes the following parameters:

encodedAnnotationrequiredObject
An Annotation-like deserialized object.
channelOptionsoptionalChannelOptions
If you have an encrypted channel, use this to allow the SDK to decrypt the data.

Returns

Promise<Annotation>

Returns a promise that resolves with an Annotation object decoded from the supplied object.

Create annotations from an encoded array

Annotation.fromEncodedArray(encodedAnnotations: Object[], channelOptions?: ChannelOptions): Promise<Annotation[]>

A static factory method to create an array of Annotation objects from an array of deserialized Annotation-like objects encoded using Ably's wire protocol. The returned promise resolves with the decoded annotations.

JavaScript

1

const annotations = await Ably.Rest.Annotation.fromEncodedArray(encodedAnnotations);

Parameters

The Annotation.fromEncodedArray() method takes the following parameters:

encodedAnnotationsrequiredArray<Object>
An array of Annotation-like deserialized objects.
channelOptionsoptionalChannelOptions
If you have an encrypted channel, use this to allow the SDK to decrypt the data.

Returns

Promise<Annotation[]>

Returns a promise that resolves with an array of Annotation objects decoded from the supplied array.