Skip to content

Instantly share code, notes, and snippets.

@devsnek
Last active November 19, 2023 20:21
Show Gist options
  • Save devsnek/701047cdcf378bdd3a6c36c0a8085530 to your computer and use it in GitHub Desktop.
Save devsnek/701047cdcf378bdd3a6c36c0a8085530 to your computer and use it in GitHub Desktop.
'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