Last active
April 4, 2024 22:32
-
-
Save haileyok/a08d699d5e96cf133047c0501d7cc53e to your computer and use it in GitHub Desktop.
quote the post you create
This file contains hidden or 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 {BskyAgent} from '@atproto/api' | |
import {dataToCborBlock, TID} from '@atproto/common' | |
import {lexToIpld} from '@atproto/lexicon' | |
import {cborToLex} from '@atproto/repo' | |
const agent = new BskyAgent({ | |
service: 'https://pds.haileyok.com', | |
}) | |
const doIt = async () => { | |
await agent.login({ | |
identifier: 'haileyok.com', | |
password: 'SECRET', | |
}) | |
const nextRkey = TID.next() | |
const nextRkeyStr = nextRkey.toString() | |
const did = agent.session.did | |
const record = { | |
text: 'yes, this should be doable', | |
createdAt: new Date().toISOString(), | |
embed: { | |
$type: 'app.bsky.embed.record', | |
record: { | |
uri: `at://${agent.session.did}/app.bsky.feed.post/${nextRkeyStr}`, | |
} | |
}, | |
reply: { | |
root: { | |
"cid": "bafyreibt3bazk7xgvonij4tso2tvxrhsssiwzjndhbrtu4vs3yepfhnm34", | |
"uri": "at://did:plc:tj6tznbcdj47lfrfkdfmt7ul/app.bsky.feed.post/3kpdizych6c2a" | |
}, | |
parent: { | |
"uri": "at://did:plc:7qvnag2wmk2iidyvs2yz4rww/app.bsky.feed.post/3kpdj67bexn2x", | |
"cid": "bafyreiatocatfchkjdwjekrofi6zqhl4vektypxwjz6pv2flbjuglzirpe" | |
} | |
} | |
} | |
const block = await dataToCborBlock(lexToIpld(record)) | |
cborToLex(block.bytes) | |
const cid = block.cid | |
await agent.api.app.bsky.feed.post.create( | |
{repo: did, rkey: nextRkeyStr}, | |
{ | |
...record, | |
embed: { | |
...record.embed, | |
record: { | |
...record.embed.record, | |
cid: cid.toString() | |
} | |
}, | |
} | |
) | |
} | |
doIt() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment