Created
June 12, 2023 22:00
-
-
Save Shelob9/26f0cf0bdb924c7ff078639377f04fdd to your computer and use it in GitHub Desktop.
Send a skeet, with images https://bsky.app/profile/josh412.com/post/3jxyrdxfvre2r
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function sendSkeet({ text, agent, attatchments }: { | |
text: string, | |
agent: bsky.BskyAgent, | |
attatchments?: Attatchments, | |
}) { | |
const rt = new RichText({ text }); | |
await rt.detectFacets(agent); | |
const post: any = { | |
$type: 'app.bsky.feed.post', | |
text: rt.text, | |
facets: rt.facets, | |
createdAt: new Date().toISOString(), | |
} | |
if (attatchments && attatchments.length > 0) { | |
const images = await Promise.all(attatchments.map(async ({ file, description, encoding }) => { | |
const upload = await agent.uploadBlob(file, { encoding, }); | |
return { | |
image: upload.data.blob, | |
alt: description, | |
}; | |
})); | |
if( images.length > 0 ){ | |
post.embed = { | |
images: images, | |
$type: "app.bsky.embed.images", | |
}; | |
} | |
} | |
const res = await agent.post(post); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment