togdon / reply-bot

0 stars 0 forks source link

create post in bluesky to respond to shared games score #25

Open notcool11 opened 2 days ago

notcool11 commented 2 days ago

starter guide here: https://docs.bsky.app/docs/tutorials/creating-a-post

@gitmann might have started on this a bit already, so check with them.

data should get pulled from this google sheet: https://docs.google.com/spreadsheets/d/1wD8zsIcn9vUPmL749MFAreXx8cfaYeqRfFoGuSnJ2Lk/edit?gid=0#gid=0

part of this work will be to have the correct account and verbiage to use, so some dependency not issue 15: https://github.com/togdon/reply-bot/issues/15

however, in the meantime at small scale running locally, likely fine to just use a personal account/token as a POC.

notcool11 commented 2 days ago

potentially respond with the techguild account? https://bsky.app/profile/nytguildtech.bsky.social

notcool11 commented 1 day ago

flailed on this a bunch, still not joy.

created a test post in bluesky, you can get the details of the post with this (no auth needed):

 https://bsky.social/xrpc/com.atproto.repo.getRecord?repo=did:plc:ltradugkwaw6yfotr7boceaj&collection=app.bsky.feed.post&rkey=3lacbaedvft2w

following this guide on posting a reply: https://docs.bsky.app/docs/advanced-guides/posts#replies-quote-posts-and-embeds

trying this curl

 curl -u tyler-j:my-password \
  -X POST https://public.api.bsky.app/xrpc/com.atproto.repo.createRecord \
  -H "Content-Type: application/json" \
  -d '{
    "$type": "app.bsky.feed.post",
    "text": "automated reply 1",
    "createdAt": "2024-11-06T18:56:57+0000",  
    "reply": {
        "root": {
            "uri": "at://did:plc:ltradugkwaw6yfotr7boceaj/app.bsky.feed.post/3lacbaedvft2w",
            "cid": "bafyreidewtz66ajyfuol6y33y4i46a6nmyhoue4gepyfq2c4sxz6b5nvre",
        }, 
        "parent": {
            "uri": "at://did:plc:ltradugkwaw6yfotr7boceaj/app.bsky.feed.post/3lacbaedvft2w",
            "cid": "bafyreidewtz66ajyfuol6y33y4i46a6nmyhoue4gepyfq2c4sxz6b5nvre",
        },
    }
  }'

getting a 405 not allowed. so there has to be something wrong in the URL. there is some noise in bluesky docs about using a pds_url? not sure what that is. 🤷

oahnh commented 21 hours ago

@notcool11 Was able to get api post request working through this doc: https://docs.bsky.app/blog/create-post#replies

First ran this to get a session token:

http post https://bsky.social/xrpc/com.atproto.server.createSession \
        identifier="my-bsky-handle" \
        password="my-bsky-password"

Set the bearer token with the output from the session above, and called this on your created post:

http post https://bsky.social/xrpc/com.atproto.repo.createRecord \
    Authorization:"Bearer my-bearer-token" \
    repo="oahn.bsky.social" \
    collection=app.bsky.feed.post \
    record:="{\"$type\":\"app.bsky.feed.post\",\"text\":\"noah replying through bsky api\",\"createdAt\":\"2023-08-07T05:49:40.501974Z\",\"reply\":{\"root\":{\"uri\":\"at://did:plc:ltradugkwaw6yfotr7boceaj/app.bsky.feed.post/3lacbaedvft2w\",\"cid\":\"bafyreidewtz66ajyfuol6y33y4i46a6nmyhoue4gepyfq2c4sxz6b5nvre\"},\"parent\":{\"uri\":\"at://did:plc:ltradugkwaw6yfotr7boceaj/app.bsky.feed.post/3lacbaedvft2w\",\"cid\":\"bafyreidewtz66ajyfuol6y33y4i46a6nmyhoue4gepyfq2c4sxz6b5nvre\"}}}"
notcool11 commented 18 hours ago

translated the above into curl.

get a token

curl --location 'https://bsky.social/xrpc/com.atproto.server.createSession' \
--header 'Content-Type: application/json' \
--data '{
    "identifier": "<handle>.bsky.social",
    "password": "xxx"
}'

pass to this:

curl --location 'https://bsky.social/xrpc/com.atproto.repo.createRecord' \
--header 'Content-Type: application/json' \
--header 'Authorization: <token from above>' \
--data '{
    "repo": "did:plc:ltradugkwaw6yfotr7boceaj",
    "collection": "app.bsky.feed.post",
    "record": {
        "$type": "app.bsky.feed.post",
        "text": "automated reply 2",
        "createdAt": "2024-11-07T17:49:40.501974Z",  
        "reply": {
         "root": {
             "uri": "at://did:plc:ltradugkwaw6yfotr7boceaj/app.bsky.feed.post/3lacbaedvft2w",
             "cid": "bafyreidewtz66ajyfuol6y33y4i46a6nmyhoue4gepyfq2c4sxz6b5nvre"
         }, 
         "parent": {
             "uri": "at://did:plc:ltradugkwaw6yfotr7boceaj/app.bsky.feed.post/3lacbaedvft2w",
             "cid": "bafyreidewtz66ajyfuol6y33y4i46a6nmyhoue4gepyfq2c4sxz6b5nvre"
         }
    }
  }
}'
notcool11 commented 16 hours ago

created branch: https://github.com/togdon/reply-bot/tree/add-bluesky-reply