Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Last active December 15, 2024 12:45
Show Gist options
  • Save YonatanKra/bf539ead0b14e58f1ecec0bc1d651c69 to your computer and use it in GitHub Desktop.
Save YonatanKra/bf539ead0b14e58f1ecec0bc1d651c69 to your computer and use it in GitHub Desktop.
import { AtpAgent } from "@atproto/api";
export class AltTextBot {
#agent = new AtpAgent({ service: 'https://bsky.social' });
async checkSinglePost(postUri: string) {
try {
await this.#agent.getPost(await parsePostUri(postUri, this.#agent));
} catch (e) {
return e;
}
}
}
async function parsePostUri(uri: string, agent: AtpAgent): Promise<{ repo: string; collection: string; rkey: string; } | boolean> {
// Extract handle and post ID
const match = uri.match(/profile\/([^/]+)\/post\/([^/]+)/);
if (!match) {
return false;
}
const [, handle, rkey] = match;
// Get the did
const { data: { did: repo }} = await agent.resolveHandle({handle});
// Use the official bsky app
const collection = 'app.bsky.feed.post';
return {
repo,
collection,
rkey
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment