/Gauche-app-bsky

Primary LanguageSchemeMIT LicenseMIT

Gauche Bluesky API library

A convenience library to access Bluesky API.

Prerequisites

Gauche 0.9.13 or later

You need to have Bluesky handle and its app password. The first thing you do is to call make-bsky-session with those parameters to obtain a <bsky-session> object, which can be used for subsequent API calls.

API

Creating a session

(make-bsky-session :optional handle app-password) accesses bsky.app to get a session token. Returns <bsky-session> on success. Throws <bsky-error> condition if something goes wrong.

If handle and/or app-password is omitted, values of the environment variable GAUCHE_BSKY_HANDLE and GAUCHE_BSKY_APP_PASSWORD are used, respectively.

List your posts

(bsky-list-record session) retunrs a list of your posts.

Retrieving a post

You need to know the rkey to retrieve a post. Rkey is shown in the last part of the post’s URL.

(bsky-get-record session rkey) returns <bsky-record> of the post.

Posting a text

Currently, only a simple text posting is supported.

(bsky-post-text session text :key created-at langs quote-post reply) posts text.

  • Created-at is the post’s timestamp, and the current time is used when omitted.

  • Langs must be a list of language tags (e.g. "en_US" or "ja").

  • Quoted-post must be a <bsky-record> of the post to quote.

  • Reply must be a two-element list of <bsky-record>, the first element is the root post of the thread, and the second element is the direct parent of the post.

Obtanining user’s info

The actor argument of the following procedures should be DID of a user.

  • (bsky-get-followers session actor)

  • (bsky-get-follows session actor)

  • (bsky-get-listss session actor)

Returns the given user’s list of followers, follows, and lists.

Error handling

If Bluesky API call fails, a condition of type <bsky-error> is thrown. Along with the error message in the API response, the condition has the following slots.

  • status-code: String HTTP status code.

  • http-headers: List of http response headers, in the form as http-get or http-post returned.

  • payload: If the response is in JSON, a parsed JSON structure. Otherwise, a string of the response body.

You can throw <bsky-error> with (bsky-error status-code http-headers body).