@@ -158,9 +158,9 @@ type ThreadRoot struct {
158158
159159// Reposting/Retweeting
160160type CreateRecordPayload struct {
161- Collection string `json:"collection"`
162- Repo string `json:"repo"`
163- Record RepostRecord `json:"record"`
161+ Collection string `json:"collection"`
162+ Repo string `json:"repo"`
163+ Record interface {} `json:"record"`
164164}
165165
166166type DeleteRecordPayload struct {
@@ -169,12 +169,18 @@ type DeleteRecordPayload struct {
169169 RKey string `json:"rkey"`
170170}
171171
172- type RepostRecord struct {
172+ type PostInteractionRecord struct {
173173 Type string `json:"$type"`
174174 CreatedAt string `json:"createdAt"`
175175 Subject Subject `json:"subject"`
176176}
177177
178+ type CreatePostRecord struct {
179+ Type string `json:"$type"`
180+ Text string `json:"text"`
181+ CreatedAt time.Time `json:"createdAt"`
182+ }
183+
178184type Subject struct {
179185 URI string `json:"uri"`
180186 CID string `json:"cid"`
@@ -422,7 +428,7 @@ func GetTimeline(token string, context string) (error, *Timeline) {
422428func GetPost (token string , uri string , depth int , parentHeight int ) (error , * ThreadRoot ) {
423429 // Example URL at://did:plc:dqibjxtqfn6hydazpetzr2w4/app.bsky.feed.post/3lchbospvbc2j
424430
425- url := "https://public. bsky.social/xrpc/app.bsky.feed.getPostThread?depth=" + fmt .Sprintf ("%d" , depth ) + "&parentHeight=" + fmt .Sprintf ("%d" , parentHeight ) + "&uri=" + uri
431+ url := "https://bsky.social/xrpc/app.bsky.feed.getPostThread?depth=" + fmt .Sprintf ("%d" , depth ) + "&parentHeight=" + fmt .Sprintf ("%d" , parentHeight ) + "&uri=" + uri
426432
427433 resp , err := SendRequest (& token , http .MethodGet , url , nil )
428434 if err != nil {
@@ -451,23 +457,60 @@ func GetPost(token string, uri string, depth int, parentHeight int) (error, *Thr
451457 return nil , & thread
452458}
453459
454- func UpdateStatus (token string , status string ) error {
460+ // This handles both normal & replys
461+ func UpdateStatus (token string , my_did string , status string , in_reply_to * string ) (* ThreadRoot , error ) {
455462 url := "https://public.bsky.social/xrpc/com.atproto.repo.createRecord"
456463
457- resp , err := SendRequest (& token , http .MethodPost , url , nil )
464+ reqBody := []byte {}
465+ var err error
466+
467+ if in_reply_to == nil || * in_reply_to == "" {
468+
469+ payload := CreateRecordPayload {
470+ Collection : "app.bsky.feed.post" ,
471+ Repo : my_did ,
472+ Record : CreatePostRecord {
473+ Type : "app.bsky.feed.post" ,
474+ Text : status ,
475+ CreatedAt : time .Now ().UTC (),
476+ },
477+ }
478+
479+ reqBody , err = json .Marshal (payload )
480+ if err != nil {
481+ return nil , errors .New ("failed to marshal payload" )
482+ }
483+
484+ } else {
485+ return nil , errors .New ("in_reply_to not implemented" )
486+ }
487+
488+ resp , err := SendRequest (& token , http .MethodPost , url , bytes .NewReader (reqBody ))
458489 if err != nil {
459- return err
490+ return nil , errors . New ( "failed to post" )
460491 }
492+
461493 defer resp .Body .Close ()
462494
463495 if resp .StatusCode != http .StatusOK {
464496 bodyBytes , _ := io .ReadAll (resp .Body )
465497 bodyString := string (bodyBytes )
466498 fmt .Println ("Response Status:" , resp .StatusCode )
467499 fmt .Println ("Response Body:" , bodyString )
468- return nil
500+ return nil , errors .New ("failed to update status" )
501+ }
502+
503+ postData := CreateRecordResult {}
504+ if err := json .NewDecoder (resp .Body ).Decode (& postData ); err != nil {
505+ return nil , err
469506 }
470- return errors .New ("failed to update status" )
507+
508+ err , thread := GetPost (token , postData .URI , 0 , 1 )
509+ if err != nil {
510+ return nil , errors .New ("failed to fetch made post" )
511+ }
512+
513+ return thread , nil
471514}
472515
473516func ReTweet (token string , id string , my_did string ) (error , * ThreadRoot , * string ) {
@@ -481,7 +524,7 @@ func ReTweet(token string, id string, my_did string) (error, *ThreadRoot, *strin
481524 payload := CreateRecordPayload {
482525 Collection : "app.bsky.feed.repost" ,
483526 Repo : my_did ,
484- Record : RepostRecord {
527+ Record : PostInteractionRecord {
485528 Type : "app.bsky.feed.repost" ,
486529 CreatedAt : time .Now ().UTC ().Format (time .RFC3339 ),
487530 Subject : Subject {
@@ -529,7 +572,7 @@ func LikePost(token string, id string, my_did string) (error, *ThreadRoot) {
529572 payload := CreateRecordPayload {
530573 Collection : "app.bsky.feed.like" ,
531574 Repo : my_did ,
532- Record : RepostRecord {
575+ Record : PostInteractionRecord {
533576 Type : "app.bsky.feed.like" ,
534577 CreatedAt : time .Now ().UTC ().Format (time .RFC3339 ),
535578 Subject : Subject {
0 commit comments