Skip to content

Instantly share code, notes, and snippets.

@so-asano
Created August 19, 2023 20:59
Show Gist options
  • Save so-asano/882c990e67ac630a167cd45872b0af26 to your computer and use it in GitHub Desktop.
Save so-asano/882c990e67ac630a167cd45872b0af26 to your computer and use it in GitHub Desktop.
const agent = new BskyAgent({ service: 'https://bsky.social' })
await agent.login({ 'identifier': IDENTIFIER, 'password': PASSWORD })
const mentionLikeText = '@mention'
const text = `${mentionLikeText} This mention is URL link. I think this is really bad...`
const byteStart = 0
const byteEnd = (new TextEncoder().encode(mentionLikeText)).length
const richText = new RichText({ text })
if (!richText.facets) {
richText.facets = []
}
richText.facets?.push({
index: { byteStart: byteStart, byteEnd: byteEnd },
features: [
{ $type: "app.bsky.richtext.facet#link", uri: 'https://example.com/some-bad-url' }
],
})
const facets = richText.facets
const postObj = {
$type: 'app.bsky.feed.post',
text,
facets,
langs: ['ja', 'en'],
}
await agent.post(postObj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment