Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Created June 12, 2023 22:00
Show Gist options
  • Save Shelob9/26f0cf0bdb924c7ff078639377f04fdd to your computer and use it in GitHub Desktop.
Save Shelob9/26f0cf0bdb924c7ff078639377f04fdd to your computer and use it in GitHub Desktop.
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