Last active
November 19, 2023 20:21
-
-
Save devsnek/701047cdcf378bdd3a6c36c0a8085530 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
'use strict'; | |
const { cborToLexRecord, readCar } = require('@atproto/repo'); | |
const { Subscription } = require('@atproto/xrpc-server'); | |
const SERVICE = 'bsky.network'; | |
const subscription = new Subscription({ | |
service: `wss://${SERVICE}`, | |
method: 'com.atproto.sync.subscribeRepos', | |
getState: () => ({}), | |
validate: (value) => value, | |
}); | |
(async () => { | |
for await (const event of subscription) { | |
const car = await readCar(event.blocks); | |
for (const op of event.ops) { | |
if (op.action !== 'create') { | |
continue; | |
} | |
const recordBytes = car.blocks.get(op.cid) | |
if (!recordBytes) { | |
continue; | |
} | |
const record = cborToLexRecord(recordBytes); | |
const collection = op.path.split('/')[0]; | |
if (collection !== 'app.bsky.feed.post') { | |
continue; | |
} | |
console.log(record.text); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment