Last active
December 15, 2024 12:45
-
-
Save YonatanKra/bf539ead0b14e58f1ecec0bc1d651c69 to your computer and use it in GitHub Desktop.
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
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