ReviewOS

also looking at this

stacks/postline

Sync Bluesky engagement metrics into analytics

#12
Merged glennmichael123 wants to merge feat/metrics-sync into main
10 files +200 -4
storage/framework/core/socials/src/drivers/bluesky.tsmodified+27-0
Changes to storage/framework/core/socials/src/drivers/bluesky.ts
@@ -218,6 +218,33 @@ export class BlueskyPublishingDriver implements SocialPublishingDriver {
218218 }
219219 }
220220
221 /**
222 * Engagement counts for up to 25 of the account's posts per call
223 * (app.bsky.feed.getPosts). Deleted posts are simply absent from the
224 * response.
225 */
226 async postMetrics(
227 identity: SocialIdentityCredentials,
228 uris: string[],
229 ): Promise<Array<{ uri: string, likeCount: number, repostCount: number, replyCount: number }>> {
230 if (!identity.accessToken) throw new Error('Bluesky access token is missing for this identity.')
231 if (uris.length === 0) return []
232
233 const url = new URL(`${this.service}/xrpc/app.bsky.feed.getPosts`)
234 for (const uri of uris.slice(0, 25)) url.searchParams.append('uris', uri)
235
236 const payload = await this.request<{ posts?: Array<{ uri: string, likeCount?: number, repostCount?: number, replyCount?: number }> }>(url, {
237 headers: { authorization: `Bearer ${identity.accessToken}` },
238 })
239
240 return (payload.posts || []).map(post => ({
241 uri: post.uri,
242 likeCount: post.likeCount || 0,
243 repostCount: post.repostCount || 0,
244 replyCount: post.replyCount || 0,
245 }))
246 }
247
221248 async timeline(identity: SocialIdentityCredentials, query: TimelineQuery = {}): Promise<TimelineResult> {
222249 if (!identity.accessToken) throw new Error('Bluesky access token is missing for this identity.')
223250