Open dcsan opened 1 year ago
updated: it will fetch an image from a URL if you pass an http
something as the imageUrl string
right now it downloads the image to the local file system we could probably just pass a buffer around but didn't figure that out yet, to avoid local temp image files.
also being able to post with just a text string or a full PostParams
structure... having that union type string | PostParam
was giving me some problems in my own code. it was turning up as an intersection &
sometimes. Perhaps the api params used that? The difference between PostParams
and PostParam
so I had to expose those types via the imports/exports
I think we could do fine by reducing the different options and just require always pass a PostParams type to the APIs.
If you just want text then just pass {text}
no big deal.
from discord:
skimmed your PR, I definitely have comments, I probably won't be able to sit down and write them out until the weekend though the biggest thing I saw was that it uses node-specific stuff in the bot internals, which I want to avoid if at all possible, and it's definitely not necessary for image posting
do you mean in the examples/basic bot?
Or stuff added to the SDK? not sure how i can avoid node stuff in the SDK like reading files etc?
Very interested in posting images, even more so in acquiring them from posts in the feed. Does this implement image embeds as a standard part of Posts?
yes it adds some extra fields to a post as used in my faqbot here https://github.com/dcsan/bsky-faq-bot/blob/dc/chat-gpt/src/models/FaqManager.ts#LL238C1-L243C1
const post: PostParam = {
text,
imageUrl: faq.imageUrl,
imageAlt: faq.imageAlt,
}
there's also an internal method to post that as a blob, and form an embed, tho you can access that directly.
you can send just an image as a string to a local file path or an http URL and it will fetch, and then the API. wraps them up in a blob/embed.
I don't yet support a list of images though that would be an easy add.
even more so in acquiring them from posts in the feed if you want to acquire from the feed then you can fetch the image URL and post it.
blocked until I get comments from @tautologer meantime you could use my fork of the lib https://github.com/dcsan/easy-bsky-bot-sdk/tree/dc/image-post
FYI you can use an npm module directly from git in the package.json
"easy-bsky-bot-sdk": "github:dcsan/easy-bsky-bot-sdk",
fwiw this fork is working great for me and would love to see it merged :)
WIP on image posting. it posts images now
note that for this to work have to disable your custom fetch handler see #8
disabled and that works but not quite sure why you had that (polyfill?) It was incompatible with node-fetch, which is itself an ESM only module, so i just use default fetch with node18 and its working.
so the API allows you to use
imageUri: string
orembed: ImageEmbed
The
makeEmbed
is a bit lower level function if people want to make/pass multiple imageswe guess at file encoding based on the suffix if it's not passed in explicitly.
TODO