class RichText

Used to build a rich text string with facets.

Methods

build()

Completes the rich text string and returns the result, with parsed facets and the length of the string in graphemes.

Returns

{ facets: AppBskyRichtextFacet.Main[]; length: number; text: string; }

text(substr)

Append a string.

Parameters

substr: string

Returns

this

mention(handle, did)

Append a mention.

Parameters

handle: string
did: string

Returns

this

Append a link. You can use the uri parameter to specify a different URI than the substr.

Create a hyperlink

new RichText().text("Go to ").link("https://bsky.app").build();

Create a hyperlink with custom text

new RichText().text("Go to ").link("Bluesky", "https://bsky.app").build();

Parameters

substr: string
uri: string = substr

Returns

this

tag(tag)

Append a tag.

Parameters

tag: string

Returns

this

detectFacets(text, bot)

Returns a RichText instance with all facets (mentions, links, tags, etc) resolved.

Parameters

text: string

The text to detect facets in.

bot: Bot

Used to resolve mentions to DIDs.

detectFacetsWithoutResolution(text)

Detects rich text facets in a string (mentions, links, tags, etc). Will produce invalid facets! For instance, mentions will not have their DIDs set. Use detectFacets to produce valid facets that can be attached to a post.

Parameters

text: string