A TypeScript toolkit for consuming the Bluesky network in real-time.
at main 39 lines 1.1 kB view raw
1// Hello Firehose 2// Minimal example using the @atproto/sync Firehose API directly. 3// Unlike Jetstream, the Firehose provides cryptographic proofs (CID) for each event. 4// 5// Usage: npx tsx examples/hello-firehose.ts 6 7import { Firehose } from "@atproto/sync"; 8import { IdResolver } from "@atproto/identity"; 9 10const firehose = new Firehose({ 11 idResolver: new IdResolver(), 12 filterCollections: ["app.bsky.feed.post"], 13 handleEvent: (evt) => { 14 if (evt.event === "create" && evt.collection === "app.bsky.feed.post") { 15 const record = evt.record as any; 16 17 console.log({ 18 did: evt.did, 19 text: record.text, 20 langs: record.langs, 21 createdAt: record.createdAt, 22 facets: record.facets, 23 embed: record.embed, 24 collection: evt.collection, 25 rkey: evt.rkey, 26 uri: evt.uri?.toString(), 27 // Cryptographic proof — this is what Jetstream doesn't give you 28 cid: evt.cid?.toString(), 29 }); 30 31 console.log("---"); 32 } 33 }, 34 onError: (err) => { 35 console.error("Error:", err); 36 }, 37}); 38 39firehose.start();