1
0
Fork 0
Minimal go client for cross posting to ATProto / BlueSky platform.
Find a file
2024-02-07 07:50:56 +07:00
cmd/goat Add DeletePost 2024-01-20 20:37:50 +07:00
test Truncate post text 2024-02-05 14:36:42 +07:00
embed.go Tidy up the API 2024-01-23 10:53:52 +07:00
facet.go Clean up 2024-01-23 11:20:23 +07:00
go.mod Add mention 2024-01-11 12:52:17 +07:00
go.sum Add session test case 2024-01-22 18:46:00 +07:00
LICENSE Initial commit 2023-12-30 02:11:07 +00:00
post.go Make truncate optional 2024-02-07 07:50:56 +07:00
README.md Make truncate optional 2024-02-07 07:50:56 +07:00
session.go Clean up 2024-02-02 13:21:00 +07:00

goat

Package goat is a simple Go implementation for posting to ATProto platform (e.g. BlueSky).

Credit goes to https://atproto.com/blog/create-post as the inspiration for this library.

Features

Create post

  • Text post: Done
  • Inline URI / link (strict mode): Done
  • Image: Done
  • Link card: Done
  • Mention: Done
  • Quote: Done
  • Reply: Done

Delete post: Done

Update post: BSky API does not yet allow for app.bsky.feed.post update as of Jan 2024; TODO when / if it is allowed

Please note goat does not check for policy adherence, i.e. it does not check for post text length nor image size upload. This is left to the calling app to manage. A Truncate helper function can be called to truncate a long post down to within the maximum length, before sending the post, if a LinkURL to the origin is provided (i.e. permalink).

API

For more details on the API, please consult the go doc.

Go Reference

Here's a brief overview.

ATProto post is flexible and goat accommodates the content using the Prepost data structure.

type Prepost struct {
    Text            string
    Languages       []string
    ImageBlobs      []BlobData // for image attachment
    LinkURL         string     // for link card
    LinkTitle       string     // for link card
    LinkDescription string     // for link card
    LinkThumbnail   BlobData   // for link card
    Quote           PostInfo   // for reposting a quote
    Reply           Reply      // for posting a reply to an existing post
    RKey            string     // for updating an existing post, if not ""
}

type Reply struct {
    Root   PostInfo `json:"root"`
    Parent PostInfo `json:"parent"`
}

type PostInfo struct {
    URI string `json:"uri"`
    CID string `json:"cid"`
}

type BlobData struct {
    Data []byte
    Alt  string // image alt text; cannot be empty
    MIME string // image MIME type; cannot be empty
}

Populate the relevant fields and goat will parse them and process them into the needed format when it sends to the ATProto server.

To create a new post

import "codeberg.org/s877/goat"
...
var pp goat.Prepost
pp.Text = text
pp.Languages = langs
...
_, err := pp.Create(server, handle, password)

If server == "", it will default to "https://bsky.social". ATProto can specify multiple languages in a post, so it takes the form of []string. If including image(s), the []BlobData needs to be prepared beforehand.

To delete a post, use

err := goat.DeletePost(server, handle, password, rkey)

rkey is the last segment in URI after the last "/".

Convenience API

For simpler use cases, the older APIs are still available.

To create a post

_, err := NewPost(server, handle, password, text string, langs []string, blobs []BlobData)

To post a link card, use

_, err := NewLinkCard(server, handle, password, text, title, description, url string, thumbnail BlobData)

To post a quote, use

_, err := NewQuote(server, handle, password, text string, langs []string, quotedPost PostInfo)

Examples

The file cmd/goat/main.go illustrates usage of the goat package.

CLI

cd cmd/goat; go build will produce a binary called goat which also serves as a very simple BlueSky / ATProto CLI client. Run goat to see the command line usage hint.

Miscellaneous

Why call it 'goat'?

Because 'go-ATProto-Post' is a bit lengthy. A better spelling might be goAT, but goat seems simpler. (No goat was harmed during development.)

Maintenance

goat is open sourced in the hope it can help others reuse my experiments with the ATProto platform. No guarantee on future development nor API stability. It is provided as-is.

Thank you for your understanding.