- Go 100%
| cmd/goat | ||
| test | ||
| embed.go | ||
| facet.go | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| post.go | ||
| README.md | ||
| session.go | ||
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.
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.