Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ce977ee

Browse filesBrowse files
committed
[Notifier] [Bluesky] Allow to attach website preview card
1 parent eff9b52 commit ce977ee
Copy full SHA for ce977ee

File tree

5 files changed

+96
-7
lines changed
Filter options

5 files changed

+96
-7
lines changed

‎src/Symfony/Component/Notifier/Bridge/Bluesky/BlueskyOptions.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Bluesky/BlueskyOptions.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,16 @@ public function attachMedia(File $file, string $description = ''): static
4343

4444
return $this;
4545
}
46+
47+
public function attachCard(string $uri, File $thumb, string $title = '', string $description = ''): static
48+
{
49+
$this->options['external'] = [
50+
'uri' => $uri,
51+
'thumb' => $thumb,
52+
'title' => $title,
53+
'description' => $description,
54+
];
55+
56+
return $this;
57+
}
4658
}

‎src/Symfony/Component/Notifier/Bridge/Bluesky/BlueskyTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Bluesky/BlueskyTransport.php
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@ protected function doSend(MessageInterface $message): SentMessage
9191
unset($options['attach']);
9292
}
9393

94+
if (isset($options['external'])) {
95+
$uploadedMedia = $this->uploadMedia([
96+
[
97+
'file' => $options['external']['thumb'],
98+
'description' => $options['external']['description'],
99+
],
100+
]);
101+
102+
$options['record']['embed'] = [
103+
'$type' => 'app.bsky.embed.external',
104+
'external' => [
105+
'uri' => $options['external']['uri'],
106+
'title' => $options['external']['title'],
107+
'description' => $options['external']['description'],
108+
'thumb' => $uploadedMedia[array_key_first($uploadedMedia)]['image'],
109+
],
110+
];
111+
unset($options['external']);
112+
}
113+
94114
$response = $this->client->request('POST', \sprintf('https://%s/xrpc/com.atproto.repo.createRecord', $this->getEndpoint()), [
95115
'auth_bearer' => $this->authSession['accessJwt'] ?? null,
96116
'json' => $options,

‎src/Symfony/Component/Notifier/Bridge/Bluesky/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Bluesky/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.3
5+
---
6+
7+
* Add option to attach a website preview card
8+
49
7.2
510
---
611

‎src/Symfony/Component/Notifier/Bridge/Bluesky/README.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Bluesky/README.md
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,29 @@ DSN example
1010
BLUESKY_DSN=bluesky://nyholm.bsky.social:p4ssw0rd@bsky.social
1111
```
1212

13+
Adding Options to a Message
14+
---------------------------
15+
16+
With an `ChatMessage` Message, you can use the `BlueskyOptions` class to add message options.
17+
18+
```php
19+
use Symfony\Component\Notifier\Bridge\Bluesky\BlueskyOptions;
20+
use Symfony\Component\Notifier\Message\ChatMessage;
21+
22+
$message = new ChatMessage('My message');
23+
24+
// Add website preview card to the message
25+
$options = (new BlueskyOptions())
26+
->attachCard('https://example.com', new File('image.jpg'))
27+
// ...
28+
;
29+
30+
// Add the custom options to the Bluesky message and send the message
31+
$message->options($options);
32+
33+
$chatter->send($message);
34+
```
35+
1336
Resources
1437
---------
1538

‎src/Symfony/Component/Notifier/Bridge/Bluesky/Tests/BlueskyTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Bluesky/Tests/BlueskyTransportTest.php
+36-7Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,12 @@ public function testParseFacetsUrlWithTrickyRegex()
274274
$this->assertEquals($expected, $this->parseFacets($input));
275275
}
276276

277-
public function testWithMedia()
277+
/**
278+
* @dataProvider sendMessageWithEmbedDataProvider
279+
*/
280+
public function testWithEmbed(BlueskyOptions $blueskyOptions, string $expectedJsonResponse)
278281
{
279-
$transport = $this->createTransport(new MockHttpClient((function () {
282+
$transport = $this->createTransport(new MockHttpClient((function () use ($expectedJsonResponse) {
280283
yield function (string $method, string $url, array $options) {
281284
$this->assertSame('POST', $method);
282285
$this->assertSame('https://bsky.social/xrpc/com.atproto.server.createSession', $url);
@@ -299,23 +302,49 @@ public function testWithMedia()
299302
]]);
300303
};
301304

302-
yield function (string $method, string $url, array $options) {
305+
yield function (string $method, string $url, array $options) use ($expectedJsonResponse) {
303306
$this->assertSame('POST', $method);
304307
$this->assertSame('https://bsky.social/xrpc/com.atproto.repo.createRecord', $url);
305308
$this->assertArrayHasKey('authorization', $options['normalized_headers']);
306-
$this->assertSame('{"repo":null,"collection":"app.bsky.feed.post","record":{"$type":"app.bsky.feed.post","text":"Hello World!","createdAt":"2024-04-28T08:40:17.000000Z","embed":{"$type":"app.bsky.embed.images","images":[{"alt":"A fixture","image":{"$type":"blob","ref":{"$link":"bafkreibabalobzn6cd366ukcsjycp4yymjymgfxcv6xczmlgpemzkz3cfa"},"mimeType":"image\/png","size":760898}}]}}}', $options['body']);
309+
$this->assertSame($expectedJsonResponse, $options['body']);
307310

308311
return new JsonMockResponse(['cid' => '103254962155278888']);
309312
};
310313
})()));
311314

312-
$options = (new BlueskyOptions())
313-
->attachMedia(new File(__DIR__.'/fixtures.gif'), 'A fixture');
314-
$result = $transport->send(new ChatMessage('Hello World!', $options));
315+
$result = $transport->send(new ChatMessage('Hello World!', $blueskyOptions));
315316

316317
$this->assertSame('103254962155278888', $result->getMessageId());
317318
}
318319

320+
public function sendMessageWithEmbedDataProvider(): iterable
321+
{
322+
yield 'With media' => [
323+
'options' => (new BlueskyOptions())->attachMedia(new File(__DIR__.'/fixtures.gif'), 'A fixture'),
324+
'expectedResponse' => '{"repo":null,"collection":"app.bsky.feed.post","record":{"$type":"app.bsky.feed.post","text":"Hello World!","createdAt":"2024-04-28T08:40:17.000000Z","embed":{"$type":"app.bsky.embed.images","images":[{"alt":"A fixture","image":{"$type":"blob","ref":{"$link":"bafkreibabalobzn6cd366ukcsjycp4yymjymgfxcv6xczmlgpemzkz3cfa"},"mimeType":"image\/png","size":760898}}]}}}',
325+
];
326+
327+
yield 'With website preview card and all optionnal informations' => [
328+
'options' => (new BlueskyOptions())
329+
->attachCard(
330+
'https://example.com',
331+
new File(__DIR__.'/fixtures.gif'),
332+
'Fork me im famous',
333+
'Click here to go to website!'
334+
),
335+
'expectedResponse' => '{"repo":null,"collection":"app.bsky.feed.post","record":{"$type":"app.bsky.feed.post","text":"Hello World!","createdAt":"2024-04-28T08:40:17.000000Z","embed":{"$type":"app.bsky.embed.external","external":{"uri":"https:\/\/example.com","title":"Fork me im famous","description":"Click here to go to website!","thumb":{"$type":"blob","ref":{"$link":"bafkreibabalobzn6cd366ukcsjycp4yymjymgfxcv6xczmlgpemzkz3cfa"},"mimeType":"image\/png","size":760898}}}}}',
336+
];
337+
338+
yield 'With website preview card and minimal information' => [
339+
'options' => (new BlueskyOptions())
340+
->attachCard(
341+
'https://example.com',
342+
new File(__DIR__.'/fixtures.gif')
343+
),
344+
'expectedResponse' => '{"repo":null,"collection":"app.bsky.feed.post","record":{"$type":"app.bsky.feed.post","text":"Hello World!","createdAt":"2024-04-28T08:40:17.000000Z","embed":{"$type":"app.bsky.embed.external","external":{"uri":"https:\/\/example.com","title":"","description":"","thumb":{"$type":"blob","ref":{"$link":"bafkreibabalobzn6cd366ukcsjycp4yymjymgfxcv6xczmlgpemzkz3cfa"},"mimeType":"image\/png","size":760898}}}}}',
345+
];
346+
}
347+
319348
/**
320349
* A small helper function to test BlueskyTransport::parseFacets().
321350
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.