feat: use json schema to get all announcements

This commit is contained in:
2025-12-23 14:22:44 -08:00
parent 5b99450b7c
commit 7dcb20f4e4
11 changed files with 415 additions and 134 deletions
+25 -4
View File
@@ -12,11 +12,16 @@ import { AtpAgent } from "@atproto/api";
* @returns A message indicating the success or failure of the operation.
*/
export const announceOnBluesky = async(
content: string,
content: Array<string>,
): Promise<string> => {
if (process.env.BSKY_APP_PASSWORD === undefined) {
return "Bluesky credentials are not set.";
}
const [ firstPost, ...restOfPosts ] = content;
const failedReplies: Array<string> = [];
if (firstPost === undefined) {
return "No posts to send to Bluesky.";
}
const agent = new AtpAgent({
service: "https://bsky.social",
});
@@ -25,14 +30,30 @@ export const announceOnBluesky = async(
password: process.env.BSKY_APP_PASSWORD,
});
const blueskyRequest = await agent.post({
text: content,
text: firstPost,
}).catch((error: unknown) => {
return error instanceof Error
? error.message
: String(error);
});
if (typeof blueskyRequest === "string") {
return `Failed to send message to Bluesky. ${blueskyRequest}`;
return `Failed to send initial post to Bluesky. ${blueskyRequest}`;
}
return "Successfully sent message to Bluesky.";
let { uri } = blueskyRequest;
for (const post of restOfPosts) {
// eslint-disable-next-line no-await-in-loop -- We need to do this sequentially.
const blueskyResponse = await agent.post({
replyTo: uri,
text: post,
});
if (typeof blueskyResponse !== "string") {
const { uri: replyUri } = blueskyResponse;
uri = replyUri;
continue;
}
failedReplies.push(post);
}
return `Successfully sent initial post to Bluesky. ${failedReplies.length > 0
? `Failed to send ${failedReplies.length.toString()} replies: ${failedReplies.join(", ")}`
: `All ${(content.length - 1).toString()} replies were sent successfully.`}`;
};