### Get Record Example (Swift) Source: https://github.com/uakihir0/kbsky/blob/main/docs/pods/README.md Demonstrates how to use the kbsky library in Swift to fetch a record from the ATProtocol. It shows the instantiation of the BskyFactory and the call to the getRecord method with necessary parameters. ```swift let response = BskyFactory() .atproto(apiUri: "https://bsky.social/") .repo() .getRecord(request: CoreRepoGetRecordRequest( repo: "uakihir0.com", collection: "app.bsky.feed.post", rkey: nil, uri: "at://did:plc:bwdof2anluuf5wmfy2upgulw/app.bsky.feed.post/3jqcyfp3zt22s" ) ) print(response.data?.uri ?? "nil") ``` -------------------------------- ### Authenticate with Password using kbsky Source: https://context7.com/uakihir0/kbsky/llms.txt This code example demonstrates how to create an authentication session using handle and password credentials to obtain access tokens for API operations. It uses the BlueskyFactory to create a session and extracts access and refresh tokens. ```kotlin import work.socialhub.kbsky.BlueskyFactory import work.socialhub.kbsky.api.entity.com.atproto.server.ServerCreateSessionRequest import work.socialhub.kbsky.auth.BearerTokenAuthProvider import work.socialhub.kbsky.domain.Service.BSKY_SOCIAL // Create a session with credentials val response = BlueskyFactory .instance(BSKY_SOCIAL.uri) .server() .createSession( ServerCreateSessionRequest().also { it.identifier = "your-handle.bsky.social" it.password = "your-password" } ) // Extract tokens for subsequent API calls val accessJwt = response.data.accessJwt val refreshJwt = response.data.refreshJwt println("Access Token: $accessJwt") // Create an auth provider for authenticated requests val auth = BearerTokenAuthProvider( accessTokenJwt = accessJwt, refreshTokenJwt = refreshJwt ) ``` -------------------------------- ### Install kbsky.js using npm Source: https://github.com/uakihir0/kbsky/blob/main/docs/js/README.md Installs the kbsky.js library into your project using npm. You can install the latest version or a specific version by referencing a branch name. ```shell npm add uakihir0/kbsky.js or npm add uakihir0/kbsky.js#{{BRANCH_NAME}} ``` -------------------------------- ### Real-time Firehose Streaming - Kotlin Source: https://context7.com/uakihir0/kbsky/llms.txt Subscribe to the ATProtocol firehose to receive real-time events for posts, likes, and follows across the network using the kbsky stream library. This example demonstrates filtering events and handling connection callbacks. ```kotlin import work.socialhub.kbsky.stream.ATProtocolStreamFactory import work.socialhub.kbsky.stream.api.entity.com.atproto.SyncSubscribeReposRequest import work.socialhub.kbsky.stream.entity.callback.OpenedCallback import work.socialhub.kbsky.stream.entity.com.atproto.callback.SyncEventCallback import work.socialhub.kbsky.model.share.RecordUnion import kotlinx.coroutines.runBlocking import kotlinx.coroutines.delay import kotlinx.coroutines.launch runBlocking { val stream = ATProtocolStreamFactory .instance() // Uses default firehose endpoint .sync() .subscribeRepos( SyncSubscribeReposRequest().also { // Filter for specific record types it.filter = listOf( "app.bsky.feed.post", // Posts "app.bsky.feed.like", // Likes "app.bsky.graph.follow" // Follows ) } ) // Handle incoming events stream.eventCallback(object : SyncEventCallback { override fun onEvent( cid: String?, uri: String?, record: RecordUnion ) { println("Event CID: $cid") println("Event URI: $uri") println("Record: $record") } }) // Handle connection opened stream.openedCallback(object : OpenedCallback { override fun onOpened() { println("Stream connection opened") } }) // Open stream and run for 10 seconds launch { stream.open() }.let { job -> delay(10000) job.cancel() stream.close() } } ``` -------------------------------- ### PLC Directory Lookup - Kotlin Source: https://context7.com/uakihir0/kbsky/llms.txt Query the PLC Directory to resolve Decentralized Identifiers (DIDs) and retrieve associated account metadata using the kbsky library. This example shows how to fetch DID details and extract the handle. ```kotlin import work.socialhub.kbsky.PLCDirectoryFactory val plcDirectory = PLCDirectoryFactory.instance() // Lookup DID details val response = plcDirectory.DIDDetails( "did:plc:xyz123..." ) // Get the handle (alsoKnownAs contains at:// URIs) val handle = response.data.alsoKnownAs?.firstOrNull() println("Handle: $handle") // Access other DID document fields println("Services: ${response.data.service}") println("Verification Methods: ${response.data.verificationMethods}") ``` -------------------------------- ### Get User Profile Information in Kotlin Source: https://context7.com/uakihir0/kbsky/llms.txt Retrieves detailed profile information for a specific user, either by their handle or DID. The `actor().getProfile()` method fetches a single profile, while `actor().getProfiles()` can fetch multiple profiles concurrently. The returned profile data includes display name, handle, follower count, following count, and post count. ```kotlin import work.socialhub.kbsky.BlueskyFactory import work.socialhub.kbsky.api.entity.app.bsky.actor.ActorGetProfileRequest import work.socialhub.kbsky.api.entity.app.bsky.actor.ActorGetProfilesRequest import work.socialhub.kbsky.domain.Service.BSKY_SOCIAL val client = BlueskyFactory.instance(BSKY_SOCIAL.uri) // Get single profile val profile = client.actor().getProfile( ActorGetProfileRequest(auth).also { it.actor = "bsky.app" // handle or DID } ) println("Display Name: ${profile.data.displayName}") println("Handle: ${profile.data.handle}") println("Followers: ${profile.data.followersCount}") println("Following: ${profile.data.followsCount}") println("Posts: ${profile.data.postsCount}") // Get multiple profiles at once val profiles = client.actor().getProfiles( ActorGetProfilesRequest(auth).also { it.actors = listOf("user1.bsky.social", "user2.bsky.social") } ) profiles.data.profiles.forEach { p -> println("${p.handle}: ${p.displayName}") } ``` -------------------------------- ### Create Posts with Replies and Rich Text in Kotlin Source: https://context7.com/uakihir0/kbsky/llms.txt Demonstrates how to create simple text posts, reply to existing posts, and delete posts using the kbsky Kotlin SDK. It requires authentication credentials and utilizes the `feed().post()` and `feed().deletePost()` methods. The `FeedPostRequest` object is used to construct the post content, including optional reply references. ```kotlin import work.socialhub.kbsky.BlueskyFactory import work.socialhub.kbsky.api.entity.app.bsky.feed.FeedPostRequest import work.socialhub.kbsky.api.entity.app.bsky.feed.FeedDeletePostRequest import work.socialhub.kbsky.model.app.bsky.feed.FeedPostReplyRef import work.socialhub.kbsky.model.com.atproto.repo.RepoStrongRef import work.socialhub.kbsky.domain.Service.BSKY_SOCIAL val client = BlueskyFactory.instance(BSKY_SOCIAL.uri) // Simple text post val response = client.feed().post( FeedPostRequest(auth).also { it.text = "Hello from kbsky!" } ) println("Post URI: ${response.data.uri}") // Reply to a post val rootRef = RepoStrongRef( "at://did:plc:xxx/app.bsky.feed.post/123", // parent post URI "bafyrei..." // parent post CID ) val replyResponse = client.feed().post( FeedPostRequest(auth).also { it.text = "This is a reply!" it.reply = FeedPostReplyRef().also { reply -> reply.root = rootRef reply.parent = rootRef } } ) // Delete a post client.feed().deletePost( FeedDeletePostRequest(auth).also { it.uri = response.data.uri } ) ``` -------------------------------- ### Upload Videos with Job Status Tracking in Kotlin Source: https://context7.com/uakihir0/kbsky/llms.txt This snippet shows how to upload videos using the kbsky Kotlin library. It includes checking upload limits, performing the upload, and tracking the job status. Requires authentication and a video file. ```kotlin import work.socialhub.kbsky.BlueskyFactory import work.socialhub.kbsky.api.entity.app.bsky.video.VideoUploadVideoRequest import work.socialhub.kbsky.api.entity.app.bsky.video.VideoGetJobStatusRequest import work.socialhub.kbsky.api.entity.app.bsky.video.VideoGetUploadLimitsRequest import work.socialhub.kbsky.domain.Service.BSKY_SOCIAL import java.io.File val client = BlueskyFactory.instance(BSKY_SOCIAL.uri) // Check upload limits val limits = client.video().getUploadLimits( VideoGetUploadLimitsRequest(auth) ) println("Can upload: ${limits.data.canUpload}") println("Remaining daily bytes: ${limits.data.remainingDailyBytes}") // Upload video val videoBytes = File("video.mp4").readBytes() val uploadResponse = client.video().uploadVideo( VideoUploadVideoRequest(auth).also { it.video = videoBytes it.name = "video.mp4" } ) // Check job status val jobStatus = client.video().getJobStatus( VideoGetJobStatusRequest(auth).also { it.jobId = uploadResponse.data.jobId } ) println("Job state: ${jobStatus.data.jobStatus.state}") ``` -------------------------------- ### Like and Unlike Posts with Bluesky SDK Source: https://context7.com/uakihir0/kbsky/llms.txt Demonstrates how to like and unlike posts using the Bluesky SDK. It requires authentication and a reference to the post (URI and CID). The operation returns a URI for the like action, which is used for unliking. ```kotlin import work.socialhub.kbsky.BlueskyFactory import work.socialhub.kbsky.api.entity.app.bsky.feed.FeedLikeRequest import work.socialhub.kbsky.api.entity.app.bsky.feed.FeedDeleteLikeRequest import work.socialhub.kbsky.api.entity.app.bsky.feed.FeedRepostRequest import work.socialhub.kbsky.api.entity.app.bsky.feed.FeedDeleteRepostRequest import work.socialhub.kbsky.model.com.atproto.repo.RepoStrongRef import work.socialhub.kbsky.domain.Service.BSKY_SOCIAL val client = BlueskyFactory.instance(BSKY_SOCIAL.uri) // Reference to the post to interact with val postRef = RepoStrongRef( "at://did:plc:xxx/app.bsky.feed.post/123", // post URI "bafyrei..." // post CID ) // Like a post val likeResponse = client.feed().like( FeedLikeRequest(auth).also { it.subject = postRef } ) println("Like URI: ${likeResponse.data.uri}") // Unlike (delete like) client.feed().deleteLike( FeedDeleteLikeRequest(auth).also { it.uri = likeResponse.data.uri } ) // Repost val repostResponse = client.feed().repost( FeedRepostRequest(auth).also { it.subject = postRef } ) println("Repost URI: ${repostResponse.data.uri}") // Undo repost client.feed().deleteRepost( FeedDeleteRepostRequest(auth).also { it.uri = repostResponse.data.uri } ) ``` -------------------------------- ### Authenticate with Password using kbsky.js Source: https://github.com/uakihir0/kbsky/blob/main/docs/js/README.md Demonstrates how to authenticate with the Bluesky API using a handle and password. It retrieves an access token and then uses it to post a 'Hello World!' message. ```typescript import kbsky from "kbsky-js"; import BlueskyFactory = kbsky.work.socialhub.kbsky.BlueskyFactory; import ServerCreateSessionRequest = kbsky.work.socialhub.kbsky.api.entity.app.bsky.actor.ServerCreateSessionRequest; import BearerTokenAuthProvider = kbsky.work.socialhub.kbsky.domain.service.auth.BearerTokenAuthProvider; import FeedPostRequest = kbsky.work.socialhub.kbsky.api.entity.app.bsky.feed.FeedPostRequest; const response = await BlueskyFactory .instance("https://bsky.social") .server() .createSession( new ServerCreateSessionRequest().also((it) => { it.identifier = "YOUR_HANDLE"; it.password = "YOUR_PASSWORD"; }) ); console.log(response.data.accessJwt); // Access resources with the obtained access token const auth = new BearerTokenAuthProvider(response.data.accessJwt); await BlueskyFactory .instance("https://bsky.social") .feed() .post( new FeedPostRequest(auth).also((it) => { it.text = "Hello World!"; }) ); ``` -------------------------------- ### Retrieve User Timeline with Pagination in Kotlin Source: https://context7.com/uakihir0/kbsky/llms.txt Fetches the authenticated user's home timeline, supporting pagination to retrieve posts in chunks. The `feed().getTimeline()` method is used, with parameters for `limit` and `cursor` to control the number of posts and navigate through pages. The response contains a list of timeline items and a cursor for the next page. ```kotlin import work.socialhub.kbsky.BlueskyFactory import work.socialhub.kbsky.api.entity.app.bsky.feed.FeedGetTimelineRequest import work.socialhub.kbsky.domain.Service.BSKY_SOCIAL val client = BlueskyFactory.instance(BSKY_SOCIAL.uri) // Get first page of timeline val response = client.feed().getTimeline( FeedGetTimelineRequest(auth).also { it.limit = 50 } ) response.data.feed.forEach { item -> val post = item.post println("@${post.author.handle}: ${post.record}") } // Get next page using cursor val nextPage = client.feed().getTimeline( FeedGetTimelineRequest(auth).also { it.cursor = response.data.cursor it.limit = 50 } ) ``` -------------------------------- ### Make ATProtocol Repo Request in Swift Source: https://github.com/uakihir0/kbsky/blob/main/docs/spm/README.md Demonstrates how to make a repository request using the kbsky library in Swift. It initializes the BskyFactory, specifies the AT Protocol API URI, and constructs a CoreRepoGetRecordRequest to fetch a record. The output prints the URI of the fetched record or 'nil' if not found. ```swift let response = BskyFactory() .atproto(apiUri: "https://bsky.social/") .repo() .getRecord(request: CoreRepoGetRecordRequest( repo: "uakihir0.com", collection: "app.bsky.feed.post", rkey: nil, uri: "at://did:plc:bwdof2anluuf5wmfy2upgulw/app.bsky.feed.post/3jqcyfp3zt22s" ) ) print(response.data?.uri ?? "nil") ``` -------------------------------- ### Authenticate with Password and Post to Bluesky Source: https://github.com/uakihir0/kbsky/blob/main/README.md This Kotlin code demonstrates how to authenticate with the Bluesky API using a handle and password, obtain an access token, and then post a message. It utilizes the BlueskyFactory and ServerCreateSessionRequest. ```kotlin val response = BlueskyFactory .instance(BSKY_SOCIAL.uri) .server() .createSession( ServerCreateSessionRequest().also { it.identifier = HANDLE it.password = PASSWORD } ) println(response.data.accessJwt) val auth = BearerTokenAuthProvider(response.data.accessJwt) BlueskyFactory .instance(BSKY_SOCIAL.uri) .feed() .post( FeedPostRequest(auth).also { it.text = "Hello World!" } ) ``` -------------------------------- ### Subscribe to Repository Events using kbsky.js Source: https://github.com/uakihir0/kbsky/blob/main/docs/js/README.md Demonstrates how to subscribe to repository events (like new posts) from the AT Protocol using a WebSocket stream. It filters events for 'app.bsky.feed.post' and logs the received records. ```typescript import kbsky from "kbsky-js"; import ATProtocolStreamFactory = kbsky.work.socialhub.kbsky.ATProtocolStreamFactory; import SyncSubscribeReposRequest = kbsky.work.socialhub.kbsky.api.entity.com.atproto.sync.SyncSubscribeReposRequest; import EventCallback = kbsky.work.socialhub.kbsky.stream.EventCallback; const stream = ATProtocolStreamFactory .instance( "https://bsky.social", "wss://bsky.network" ) .sync() .subscribeRepos( new SyncSubscribeReposRequest().also((it) => { it.filter = ["app.bsky.feed.post"]; }) ); stream.eventCallback({ onEvent: (cid, uri, record) => { console.log(record); } }); ``` -------------------------------- ### Implement OAuth Authentication with kbsky Source: https://context7.com/uakihir0/kbsky/llms.txt This snippet illustrates the OAuth authentication flow for secure third-party application authorization using Pushed Authorization Request (PAR). It covers creating an OAuth context, initiating PAR, building the authorization URL, and exchanging the authorization code for tokens. ```kotlin import work.socialhub.kbsky.auth.AuthFactory import work.socialhub.kbsky.auth.OAuthContext import work.socialhub.kbsky.auth.OAuthProvider import work.socialhub.kbsky.auth.OAuthSession import work.socialhub.kbsky.auth.api.entity.oauth.BuildAuthorizationUrlRequest import work.socialhub.kbsky.auth.api.entity.oauth.OAuthPushedAuthorizationRequest import work.socialhub.kbsky.auth.api.entity.oauth.OAuthAuthorizationCodeTokenRequest import work.socialhub.kbsky.domain.Service.BSKY_SOCIAL import io.ktor.http.Url // Step 1: Create OAuth context and initiate PAR val context = OAuthContext().also { it.clientId = "https://your-app.com/oauth/client-metadata.json" it.redirectUri = "http://127.0.0.1/callback" } val auth = AuthFactory.instance(BSKY_SOCIAL.uri) val parResponse = auth.oauth() .pushedAuthorizationRequest( context, OAuthPushedAuthorizationRequest().also { it.loginHint = "user-handle.bsky.social" } ) // Step 2: Build authorization URL and redirect user val authorizeUrl = auth.oauth().buildAuthorizationUrl( context, BuildAuthorizationUrlRequest().also { it.requestUri = parResponse.data.requestUri } ) println("Redirect user to: $authorizeUrl") // Step 3: After user authorizes, exchange code for tokens val callbackUrl = "http://127.0.0.1/callback?code=AUTH_CODE_HERE" val code = Url(callbackUrl).parameters["code"] val tokenResponse = auth.oauth() .authorizationCodeTokenRequest( context, OAuthAuthorizationCodeTokenRequest().also { it.code = code!! } ) // Step 4: Use OAuth provider for API calls val oAuthSession = OAuthSession().also { it.clientId = context.clientId it.publicKey = context.publicKey it.privateKey = context.privateKey } val oAuthProvider = OAuthProvider( accessTokenJwt = tokenResponse.data.accessToken, session = oAuthSession ) ``` -------------------------------- ### Search Posts with Bluesky SDK Source: https://context7.com/uakihir0/kbsky/llms.txt Allows searching for posts based on keywords or queries. This function takes a search query and an optional limit for the number of results. It returns a list of posts matching the criteria, including author information and post content. ```kotlin import work.socialhub.kbsky.BlueskyFactory import work.socialhub.kbsky.api.entity.app.bsky.feed.FeedSearchPostsRequest import work.socialhub.kbsky.domain.Service.BSKY_SOCIAL val client = BlueskyFactory.instance(BSKY_SOCIAL.uri) val searchResults = client.feed().searchPosts( FeedSearchPostsRequest( auth = auth, q = "kotlin multiplatform" ).also { it.limit = 25 } ) searchResults.data.posts.forEach { post -> println("@${post.author.handle}: ${post.record}") println("URI: ${post.uri}") println("---") } ``` -------------------------------- ### Post a Message using kbsky OAuth Provider Source: https://github.com/uakihir0/kbsky/blob/main/docs/OAUTH.md This Kotlin code demonstrates how to execute resources, specifically posting a message to the feed, after obtaining an access token and setting up the `OAuthProvider`. It requires the `clientId`, `accessToken`, `refreshToken`, `publicKey`, `privateKey`, and the PDS URL. ```kotlin val oAuthSession = OAuthSession().also { it.clientId = "{{CLIENT ID}}" it.publicKey = "{{PUBLIC KEY}}" it.privateKey = "{{PRIVATE KEY}}" } val oAuthProvider = OAuthProvider( accessTokenJwt = "{{ACCESS TOKEN}}", session = oAuthSession ) BlueskyFactory .instance("{{PDS URL}}") .feed() .post( FeedPostRequest(oAuthProvider).also { it.text = "TEST" } ) ``` -------------------------------- ### Make PAR Request and Build Authorization URL using kbsky Source: https://github.com/uakihir0/kbsky/blob/main/docs/OAUTH.md This Kotlin code snippet shows how to make a Pushed Authorization Request (PAR) and then build the URL for the authentication page. It requires creating an `OAuthContext` with `clientId` and `redirectUri`, and then uses the `requestUri` from the PAR response to construct the authorization URL. ```kotlin val context = OAuthContext().also { it.clientId = "{{client-metadata.json URL}}" it.redirectUri = "{{CALLBACK URI}}" } auth.oauth() .pushedAuthorizationRequest(context, OAuthPushedAuthorizationRequest().also { it.loginHint = "{{HANDLE}}" } ) auth.oauth() .buildAuthorizationUrl(context, BuildAuthorizationUrlRequest().also { it.requestUri = response.data.requestUri }) println(authorizeUrl) ``` -------------------------------- ### Video Upload API Source: https://context7.com/uakihir0/kbsky/llms.txt Upload videos to Bluesky with job status tracking. ```APIDOC ## Video Upload Upload videos to Bluesky with job status tracking. ### Check upload limits **Method**: GET **Endpoint**: `/app/bsky/video/getUploadLimits` #### Response **Success Response (200)** - **canUpload** (boolean) - Indicates if the user can upload videos. - **remainingDailyBytes** (long) - The number of bytes remaining for daily uploads. ### Upload video **Method**: POST **Endpoint**: `/app/bsky/video/uploadVideo` #### Request Body - **video** (bytes) - Required - The video file content. - **name** (string) - Required - The name of the video file. #### Response **Success Response (200)** - **jobId** (string) - The ID of the video upload job. ### Check job status **Method**: GET **Endpoint**: `/app/bsky/video/getJobStatus` #### Query Parameters - **jobId** (string) - Required - The ID of the video upload job. #### Response **Success Response (200)** - **state** (string) - The current state of the job (e.g., 'queued', 'processing', 'completed', 'failed'). ``` -------------------------------- ### Subscribe to Repository Updates (Stream) Source: https://github.com/uakihir0/kbsky/blob/main/README.md This Kotlin code demonstrates how to subscribe to repository updates from the AT Protocol using the stream functionality. It allows filtering events and provides a callback for processing received records. ```kotlin val stream = ATProtocolStreamFactory .instance( apiUri = BSKY_SOCIAL.uri, streamUri = BSKY_NETWORK.uri ) .sync() .subscribeRepos( SyncSubscribeReposRequest().also { it.filter = listOf( "app.bsky.feed.post" ) } ) stream.eventCallback( object : EventCallback { override fun onEvent( cid: String?, uri: String?, record: RecordUnion ) { print(record) } }) ``` -------------------------------- ### Real-time Firehose Streaming API Source: https://context7.com/uakihir0/kbsky/llms.txt Subscribe to the ATProtocol firehose to receive real-time events for all posts, likes, and follows across the network. ```APIDOC ## Real-time Firehose Streaming ### Description Subscribe to the ATProtocol firehose to receive real-time events for all posts across the network. ### Method GET (WebSocket connection) ### Endpoint `/sync/subscribe_repos` ### Parameters #### Path Parameters None #### Query Parameters - `filter` (array of strings) - Optional - Filters for specific record types (e.g., `app.bsky.feed.post`, `app.bsky.feed.like`, `app.bsky.graph.follow`). #### Request Body None ### Request Example ```json // Request parameters are typically sent as query parameters or within the connection setup. // Example of filter parameter: { "filter": [ "app.bsky.feed.post", "app.bsky.feed.like", "app.bsky.graph.follow" ] } ``` ### Response #### Success Response (200) - `cid` (string) - The CID of the event. - `uri` (string) - The URI of the event. - `record` (object) - The event record data (type depends on the event). #### Response Example ```json // Example of a post event record { "cid": "bafybeig...", "uri": "at://did:plc:abcd.../app.bsky.feed.post/xyz...", "record": { "$type": "app.bsky.feed.post", "createdAt": "2023-10-27T10:00:00.000Z", "text": "Hello AT Protocol!" // ... other post fields } } ``` ``` -------------------------------- ### Search Posts API Source: https://context7.com/uakihir0/kbsky/llms.txt Search for posts on Bluesky based on keywords or queries. ```APIDOC ## Search Posts Search for posts matching specific keywords or queries. ### Method GET ### Endpoint /app/bsky/feed/searchPosts ### Description Searches for posts containing the specified query string. ### Query Parameters - **q** (string) - Required - The search query string. - **limit** (integer) - Optional - The maximum number of posts to return. ### Response #### Success Response (200) - **posts** (array) - A list of post objects matching the search query, including author details and post content. ``` -------------------------------- ### Post Images with Metadata in Kotlin Source: https://context7.com/uakihir0/kbsky/llms.txt Enables posting images to Bluesky with associated alt text and aspect ratio information. This process involves uploading the image blob first using `repo().uploadBlob()`, then creating an `EmbedImages` object with the blob and metadata, and finally including this embed in a `FeedPostRequest`. The `File` class is used for reading image bytes. ```kotlin import work.socialhub.kbsky.BlueskyFactory import work.socialhub.kbsky.api.entity.com.atproto.repo.RepoUploadBlobRequest import work.socialhub.kbsky.api.entity.app.bsky.feed.FeedPostRequest import work.socialhub.kbsky.model.app.bsky.embed.EmbedImages import work.socialhub.kbsky.model.app.bsky.embed.EmbedImagesImage import work.socialhub.kbsky.model.app.bsky.embed.EmbedDefsAspectRatio import work.socialhub.kbsky.domain.Service.BSKY_SOCIAL val client = BlueskyFactory.instance(BSKY_SOCIAL.uri) // Step 1: Upload the image blob val imageBytes = File("photo.png").readBytes() val uploadResponse = client.repo().uploadBlob( RepoUploadBlobRequest( auth = auth, name = "photo.png", bytes = imageBytes, contentType = "image/png" ) ) // Step 2: Create embed with image metadata val embedImages = EmbedImages().also { embed -> embed.images = mutableListOf( EmbedImagesImage().also { img -> img.image = uploadResponse.data.blob img.alt = "Description of the image for accessibility" img.aspectRatio = EmbedDefsAspectRatio(1920, 1080) } ) } // Step 3: Post with image attachment val postResponse = client.feed().post( FeedPostRequest(auth).also { it.text = "Check out this photo!" it.embed = embedImages } ) println("Post with image: ${postResponse.data.uri}") ``` -------------------------------- ### Build Authorization URL Source: https://github.com/uakihir0/kbsky/blob/main/docs/OAUTH.md Construct the URL for the user to authenticate and authorize the application. ```APIDOC ## GET /oauth/authorize ### Description Builds the authorization URL using the `requestUri` obtained from the PAR endpoint. Users will be redirected to this URL to grant the application access. ### Method GET ### Endpoint `/oauth/authorize` ### Parameters #### Query Parameters - **request_uri** (string) - Required - The `requestUri` obtained from the Pushed Authorization Request. ### Request Example ``` https://example.com/oauth/authorize?request_uri=urn:ietf:params:oauth:request_uri:abcdef123456 ``` ### Response #### Success Response (200) - **authorizeUrl** (string) - The complete URL for the user to authorize the application. #### Response Example ``` https://example.com/oauth/authorize?request_uri=urn:ietf:params:oauth:request_uri:abcdef123456 ``` ``` -------------------------------- ### Like and Repost Operations Source: https://context7.com/uakihir0/kbsky/llms.txt Allows users to like, unlike, repost, and undo reposts on posts within the Bluesky network. ```APIDOC ## Like and Repost Operations Interact with posts through likes and reposts, with ability to undo these actions. ### Method POST ### Endpoint /app/bsky/feed/like ### Description Likes a specific post. ### Request Body - **subject** (RepoStrongRef) - Required - The post to like. ### Response #### Success Response (200) - **uri** (string) - The URI of the created like. ### Method DELETE ### Endpoint /app/bsky/feed/deleteLike ### Description Removes a like from a specific post. ### Request Body - **uri** (string) - Required - The URI of the like to delete. ### Response #### Success Response (200) - **No content** ### Method POST ### Endpoint /app/bsky/feed/repost ### Description Reposts a specific post. ### Request Body - **subject** (RepoStrongRef) - Required - The post to repost. ### Response #### Success Response (200) - **uri** (string) - The URI of the created repost. ### Method DELETE ### Endpoint /app/bsky/feed/deleteRepost ### Description Removes a repost of a specific post. ### Request Body - **uri** (string) - Required - The URI of the repost to delete. ### Response #### Success Response (200) - **No content** ``` -------------------------------- ### Retrieve OAuth Meta Information using kbsky Source: https://github.com/uakihir0/kbsky/blob/main/docs/OAUTH.md This snippet demonstrates how to access the kbsky library to retrieve meta information required for OAuth authentication. It initializes the AuthFactory with the Bluesky social URI and calls the `wellKnown()` and `oAuthProtectedResource()` methods to obtain necessary endpoints. ```kotlin val auth = AuthFactory .instance(BSKY_SOCIAL.uri) .wellKnown() .oAuthProtectedResource() auth.wellKnown() .oAuthAuthorizationServer() ``` -------------------------------- ### Manage User Mutes and Blocks in Kotlin Source: https://context7.com/uakihir0/kbsky/llms.txt This snippet demonstrates how to mute, unmute, block, and unblock users using the kbsky Kotlin library. It includes fetching lists of muted and blocked accounts. Requires authentication credentials. ```kotlin import work.socialhub.kbsky.BlueskyFactory import work.socialhub.kbsky.api.entity.app.bsky.graph.GraphMuteActorRequest import work.socialhub.kbsky.api.entity.app.bsky.graph.GraphUnmuteActorRequest import work.socialhub.kbsky.api.entity.app.bsky.graph.GraphBlockRequest import work.socialhub.kbsky.api.entity.app.bsky.graph.GraphDeleteBlockRequest import work.socialhub.kbsky.api.entity.app.bsky.graph.GraphGetMutesRequest import work.socialhub.kbsky.api.entity.app.bsky.graph.GraphGetBlocksRequest import work.socialhub.kbsky.domain.Service.BSKY_SOCIAL val client = BlueskyFactory.instance(BSKY_SOCIAL.uri) // Mute a user client.graph().muteActor( GraphMuteActorRequest(auth).also { it.actor = "annoying-user.bsky.social" } ) // Unmute a user client.graph().unmuteActor( GraphUnmuteActorRequest(auth).also { it.actor = "annoying-user.bsky.social" } ) // Get list of muted accounts val mutes = client.graph().getMutes( GraphGetMutesRequest(auth) ) // Block a user val blockResponse = client.graph().block( GraphBlockRequest(auth).also { it.subject = "did:plc:xyz..." } ) // Unblock (delete block) client.graph().deleteBlock( GraphDeleteBlockRequest(auth).also { it.uri = blockResponse.data.uri } ) // Get list of blocked accounts val blocks = client.graph().getBlocks( GraphGetBlocksRequest(auth) ) ``` -------------------------------- ### Retrieve DID Details from PLC Directory Source: https://github.com/uakihir0/kbsky/blob/main/README.md This Kotlin snippet shows how to query the PLC Directory for Decentralized Identifiers (DIDs) and retrieve their details. It uses the PLCDirectoryFactory and DIDDetails methods. ```kotlin val response = PLCDirectoryFactory .instance() .DIDDetails(did) println(checkNotNull(response.data.alsoKnownAs)[0]) ``` -------------------------------- ### Add kbsky Dependencies to Gradle (Snapshot) Source: https://github.com/uakihir0/kbsky/blob/main/README.md This snippet demonstrates how to include snapshot versions of the kbsky modules in your Gradle project. It requires configuring a custom Maven repository for snapshots. ```kotlin repositories { + maven { url = uri("https://repo.repsy.io/mvn/uakihir0/public") } } dependencies { + implementation("work.socialhub.kbsky:core:0.4.0-SNAPSHOT") + implementation("work.socialhub.kbsky:auth:0.4.0-SNAPSHOT") + implementation("work.socialhub.kbsky:stream:0.4.0-SNAPSHOT") } ``` -------------------------------- ### OAuth Meta Information Source: https://github.com/uakihir0/kbsky/blob/main/docs/OAUTH.md Retrieve meta information to discover necessary OAuth endpoints. ```APIDOC ## GET /.well-known/oauth-authorization-server ### Description Retrieves meta information about the OAuth authorization server, including endpoints for authorization and token requests. ### Method GET ### Endpoint `/.well-known/oauth-authorization-server` ### Parameters None ### Request Example None ### Response #### Success Response (200) - **response** (object) - Contains URLs for OAuth endpoints. - **authorization_endpoint** (string) - The URL for the authorization endpoint. - **token_endpoint** (string) - The URL for the token endpoint. - **pushed_authorization_request_endpoint** (string) - The URL for the Pushed Authorization Request endpoint. #### Response Example ```json { "authorization_endpoint": "https://example.com/oauth/authorize", "token_endpoint": "https://example.com/oauth/token", "pushed_authorization_request_endpoint": "https://example.com/oauth/par" } ``` ``` -------------------------------- ### Follow and Unfollow Users with Bluesky SDK Source: https://context7.com/uakihir0/kbsky/llms.txt Enables managing user followings. This includes following a user by their DID, unfollowing them using the follow URI, and retrieving lists of followers and followed accounts. Requires authentication. ```kotlin import work.socialhub.kbsky.BlueskyFactory import work.socialhub.kbsky.api.entity.app.bsky.graph.GraphFollowRequest import work.socialhub.kbsky.api.entity.app.bsky.graph.GraphDeleteFollowRequest import work.socialhub.kbsky.api.entity.app.bsky.graph.GraphGetFollowersRequest import work.socialhub.kbsky.api.entity.app.bsky.graph.GraphGetFollowsRequest import work.socialhub.kbsky.domain.Service.BSKY_SOCIAL val client = BlueskyFactory.instance(BSKY_SOCIAL.uri) // Follow a user by DID val followResponse = client.graph().follow( GraphFollowRequest(auth).also { it.subject = "did:plc:xyz123..." } ) println("Follow URI: ${followResponse.data.uri}") // Unfollow (delete follow) client.graph().deleteFollow( GraphDeleteFollowRequest(auth).also { it.uri = followResponse.data.uri } ) // Get followers of a user val followers = client.graph().getFollowers( GraphGetFollowersRequest(auth).also { it.actor = "user.bsky.social" it.limit = 50 } ) followers.data.followers.forEach { follower -> println("Follower: ${follower.handle}") } // Get accounts a user follows val following = client.graph().getFollows( GraphGetFollowsRequest(auth).also { it.actor = "user.bsky.social" } ) ``` -------------------------------- ### Access PLC Directory using kbsky.js Source: https://github.com/uakihir0/kbsky/blob/main/docs/js/README.md Shows how to retrieve details for a specific DID (Decentralized Identifier) from the PLC Directory using the kbsky.js library. It fetches DID details and logs one of the 'alsoKnownAs' entries. ```typescript import kbsky from "kbsky-js"; import PLCDirectoryFactory = kbsky.work.socialhub.kbsky.PLCDirectoryFactory; const response = await PLCDirectoryFactory .instance() .DIDDetails("did:plc:example"); console.log(response.data.alsoKnownAs[0]); ``` -------------------------------- ### Follow and Unfollow Users Source: https://context7.com/uakihir0/kbsky/llms.txt Manage social connections by following and unfollowing users on Bluesky. ```APIDOC ## Follow and Unfollow Users Manage social connections by following and unfollowing users. ### Method POST ### Endpoint /app/bsky/graph/follow ### Description Follows a specified user. ### Request Body - **subject** (string) - Required - The DID of the user to follow. ### Response #### Success Response (200) - **uri** (string) - The URI of the created follow relationship. ### Method DELETE ### Endpoint /app/bsky/graph/deleteFollow ### Description Unfollows a specified user. ### Request Body - **uri** (string) - Required - The URI of the follow relationship to delete. ### Response #### Success Response (200) - **No content** ### Method GET ### Endpoint /app/bsky/graph/getFollowers ### Description Retrieves a list of users who are following a specified actor. ### Query Parameters - **actor** (string) - Required - The DID or handle of the actor whose followers to retrieve. - **limit** (integer) - Optional - The maximum number of followers to return. ### Response #### Success Response (200) - **followers** (array) - A list of follower objects, each containing actor details. ### Method GET ### Endpoint /app/bsky/graph/getFollows ### Description Retrieves a list of users that a specified actor is following. ### Query Parameters - **actor** (string) - Required - The DID or handle of the actor whose following list to retrieve. - **limit** (integer) - Optional - The maximum number of following entries to return. ### Response #### Success Response (200) - **follows** (array) - A list of followed user objects, each containing actor details. ``` -------------------------------- ### Mute and Block Users API Source: https://context7.com/uakihir0/kbsky/llms.txt Manage user relationships by muting or blocking accounts. ```APIDOC ## Mute and Block Users Manage user relationships by muting or blocking accounts. ### Mute a user **Method**: POST **Endpoint**: `/app/bsky/graph/muteActor` #### Request Body - **actor** (string) - Required - The handle or DID of the user to mute. ### Unmute a user **Method**: POST **Endpoint**: `/app/bsky/graph/unmuteActor` #### Request Body - **actor** (string) - Required - The handle or DID of the user to unmute. ### Get list of muted accounts **Method**: GET **Endpoint**: `/app/bsky/graph/mutes` ### Block a user **Method**: POST **Endpoint**: `/app/bsky/graph/block` #### Request Body - **subject** (string) - Required - The DID of the user to block. ### Unblock (delete block) **Method**: POST **Endpoint**: `/app/bsky/graph/deleteBlock` #### Request Body - **uri** (string) - Required - The URI of the block record to delete. ### Get list of blocked accounts **Method**: GET **Endpoint**: `/app/bsky/graph/blocks` ``` -------------------------------- ### PLC Directory Lookup API Source: https://context7.com/uakihir0/kbsky/llms.txt Query the PLC Directory to resolve Decentralized Identifiers (DIDs) and retrieve associated account metadata. ```APIDOC ## PLC Directory Lookup ### Description Query the PLC Directory to resolve DIDs and retrieve account metadata. ### Method GET ### Endpoint `/did/{did}` ### Parameters #### Path Parameters - **did** (string) - Required - The Decentralized Identifier (DID) to look up (e.g., `did:plc:xyz123...`). #### Query Parameters None #### Request Body None ### Request Example `GET /did/did:plc:xyz123...` ### Response #### Success Response (200) - `data` (object) - Contains the DID document details. - `alsoKnownAs` (array of strings) - Optional - List of alternative identifiers, including AT Protocol URIs. - `service` (object) - Optional - Service endpoints associated with the DID. - `verificationMethods` (object) - Optional - Verification methods for the DID. #### Response Example ```json { "data": { "did": "did:plc:xyz123...", "handle": "example.bsky.social", "alsoKnownAs": [ "at://did:plc:xyz123..." ], "service": { "atproto_did": { "type": "AtprotoKey", "endpoint": "https://did.plc.directory/" } }, "verificationMethods": { "0": { "type": "Ed25519VerificationKey2018", "publicKeyMultibase": "z6mk1..." } } } } ``` ``` -------------------------------- ### Add kbsky Dependencies to Gradle (Stable) Source: https://github.com/uakihir0/kbsky/blob/main/README.md This snippet shows how to add the stable versions of the kbsky core, auth, and stream modules to your Gradle project. It requires the mavenCentral() repository to be configured. ```kotlin repositories { mavenCentral() } dependencies { + implementation("work.socialhub.kbsky:core:0.3.0") + implementation("work.socialhub.kbsky:auth:0.3.0") + implementation("work.socialhub.kbsky:stream:0.3.0") } ``` -------------------------------- ### Add kbsky Dependencies to Gradle Project Source: https://context7.com/uakihir0/kbsky/llms.txt This snippet shows how to add kbsky dependencies to a Gradle project for Kotlin Multiplatform development. It includes configurations for both stable versions from Maven Central and snapshot versions from RePsy. ```kotlin // build.gradle.kts - Stable version from Maven Central repositories { mavenCentral() } dependencies { implementation("work.socialhub.kbsky:core:0.3.0") implementation("work.socialhub.kbsky:auth:0.3.0") implementation("work.socialhub.kbsky:stream:0.3.0") } // For snapshot versions repositories { maven { url = uri("https://repo.repsy.io/mvn/uakihir0/public") } } dependencies { implementation("work.socialhub.kbsky:core:0.4.0-SNAPSHOT") implementation("work.socialhub.kbsky:auth:0.4.0-SNAPSHOT") implementation("work.socialhub.kbsky:stream:0.4.0-SNAPSHOT") } // For regular Java projects using Maven // // work.socialhub.kbsky // core-jvm // 0.3.0 // ``` -------------------------------- ### Notifications API Source: https://context7.com/uakihir0/kbsky/llms.txt Retrieve and manage user notifications, including likes, reposts, follows, and mentions. ```APIDOC ## Notifications Retrieve and manage user notifications including likes, reposts, follows, and mentions. ### Method GET ### Endpoint /app/bsky/notification/getUnreadCount ### Description Gets the count of unread notifications for the authenticated user. ### Response #### Success Response (200) - **count** (integer) - The number of unread notifications. ### Method GET ### Endpoint /app/bsky/notification/listNotifications ### Description Lists notifications for the authenticated user. ### Query Parameters - **limit** (integer) - Optional - The maximum number of notifications to return. ### Response #### Success Response (200) - **notifications** (array) - A list of notification objects, each containing details like reason, author, and record. ### Method POST ### Endpoint /app/bsky/notification/updateSeen ### Description Marks notifications as seen up to a specified timestamp. ### Request Body - **seenAt** (string) - Required - The timestamp indicating the last seen notification. ### Response #### Success Response (200) - **No content** ``` -------------------------------- ### Manage Notifications with Bluesky SDK Source: https://context7.com/uakihir0/kbsky/llms.txt Provides functionality to retrieve and manage user notifications, including fetching the unread count, listing notifications (likes, reposts, follows, mentions, replies), and marking them as seen. Requires authentication and uses `kotlinx-datetime` for timestamping. ```kotlin import work.socialhub.kbsky.BlueskyFactory import work.socialhub.kbsky.api.entity.app.bsky.notification.NotificationListNotificationsRequest import work.socialhub.kbsky.api.entity.app.bsky.notification.NotificationGetUnreadCountRequest import work.socialhub.kbsky.api.entity.app.bsky.notification.NotificationUpdateSeenRequest import work.socialhub.kbsky.domain.Service.BSKY_SOCIAL import kotlinx.datetime.Clock val client = BlueskyFactory.instance(BSKY_SOCIAL.uri) // Get unread notification count val unreadCount = client.notification().getUnreadCount( NotificationGetUnreadCountRequest(auth) ) println("Unread notifications: ${unreadCount.data.count}") // List notifications val notifications = client.notification().listNotifications( NotificationListNotificationsRequest(auth).also { it.limit = 50 } ) notifications.data.notifications.forEach { notification -> println("Reason: ${notification.reason}") // like, repost, follow, mention, reply println("From: ${notification.author.handle}") println("Record: ${notification.record}") } // Mark notifications as seen client.notification().updateSeen( NotificationUpdateSeenRequest(auth).also { it.seenAt = Clock.System.now().toString() } ) ```