An small PHP library for Bluesky social using the AT Protocol.
Installing using composer is suggested
composer require potibm/phlueskyYou will need a PSR-7, PSR-17 and PSR-18 client or adapter from this list. For development symfony/http-client and nyholm/psr7 are used.
The HTTP service discovery will do the magic. In most cases no additional steps are required.
$api = new \potibm\Bluesky\BlueskyApi('nick.bsky.social', 'abcd-efgh-ijkl-mnop');
$postService = new \potibm\Bluesky\BlueskyPostService($api);
$post = \potibm\Bluesky\Feed\Post::create('✨ example mentioning @atproto.com to share the URL 👨❤️👨 https://en.wikipedia.org/wiki/CBOR.');
$response = $api->createRecord($post);$post = \potibm\Bluesky\Feed\Post::create('✨ example mentioning @atproto.com to share the URL 👨❤️👨 https://en.wikipedia.org/wiki/CBOR.');
$post = $postService->addFacetsFromMentionsAndLinks($post);$post = \potibm\Bluesky\Feed\Post::create('✨ example mentioning @atproto.com to share the URL 👨❤️👨 https://en.wikipedia.org/wiki/CBOR. and #HashtagFun');
$post = $postService->addFacetsFromMentionsAndLinksAndTags($post);$post = \potibm\Bluesky\Feed\Post::create('example post with image attached');
$post = $postService->addImage(
$post,
'image.jpg',
'alt text'
);$post = \potibm\Bluesky\Feed\Post::create('post which embeds an external URL as a card');
$post = $postService->addWebsiteCard(
$post,
'https://example.com',
'Example website',
'Example website description',
'optionalimage.jpg'
);$post = \potibm\Bluesky\Feed\Post::create('example of a reply');
$post = $postService->addReply(
$post,
'at://did:plc:u5cwb2mwiv2bfq53cjufe6yn/app.bsky.feed.post/3k43tv4rft22g'
);$post = \potibm\Bluesky\Feed\Post::create('example of a quote-post');
$post = $postService->addQuote(
$post,
'at://did:plc:u5cwb2mwiv2bfq53cjufe6yn/app.bsky.feed.post/3k44deefqdk2g'
);While performing requests using the API, exceptions may be thrown.
The exceptions are of the base type potibm\Bluesky\Exception\Exception.
The exception message will contain details from the API.
try {
$response = $api->createRecord($post);
} catch (\potibm\Bluesky\Exception\HttpRequestException $e) {
echo 'Error performing request on HTTP level: ' . $e->getMessage();
} catch (\potibm\Bluesky\Exception\AuthenticationErrorException $e) {
echo 'Unable to authorize: ' . $e->getMessage();
} catch (\potibm\Bluesky\Exception\HttpStatusCodeException $e) {
echo 'Unable to perform request on API level: ' . $e->getMessage();
} catch (\potibm\Bluesky\Exception\InvalidPayloadException $e) {
echo 'Received unserializable JSON payload: ' . $e->getMessage();
}The MIT License (MIT). Please see License File for more information.