Rich Text
By default, when you create a post, @skyware/bot
parses your post’s text to identify any mentions, hashtags, and URLs. However, in some cases, you may want more control over how a post is displayed. The RichText class provides a convenient interface for constructing a post containing rich text.
Usage
To start, import the RichText
class from @skyware/bot
:
You can then build a rich text string as follows:
You’ll notice that the Bot#post
method can accept either RichText
or a string. Your post will look something like:
Mentions
When you’re manually constructing RichText
, mentioning a user requires you to know the user’s handle and DID. You can then use the .addMention
method to add a mention to your post:
Note that the DID provided could differ from the mentioned handle — a mention is really just a hyperlink! Use this power for good.
Hyperlinks
Speaking of hyperlinks, mentions aren’t the only way to have text act as a link. The .addLink
method we previously used can also take two parameters: text and a URL.
Plain text
As mentioned before, in most cases you won’t need to use the RichText
builder, as methods like post
and reply
will automatically parse your text. However, if you do want to provide facets manually — say, copied from another post — you can provide the facets
option:
Or to include no facets, pass resolveFacets: false
to disable the automatic detection:
Moving on
You may notice that adding a link to a post doesn’t automatically add an embedded preview. Learn more about that in Embeds and Images!