-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Webhook component integration
- Loading branch information
Showing
35 changed files
with
462 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## Using the Symfony Webhook component | ||
|
||
Symfony provides a specific [Webhook component](https://symfony.com/doc/current/webhook.html) dedicated to this task. | ||
|
||
Its role is to parse requests related to known webhooks and dispatch a corresponding remote event. Then, this event can | ||
be handled by your application through the [Messenger component](https://symfony.com/doc/current/messenger.html). | ||
|
||
The GotenbergBundle offers a native integration of this component if installed. | ||
|
||
### Usage | ||
|
||
To connect the provider to your application, you need to configure the Webhook component routing: | ||
|
||
```yaml | ||
# config/packages/webhook.yaml | ||
framework: | ||
webhook: | ||
routing: | ||
gotenberg: | ||
service: 'sensiolabs_gotenberg.webhook.request_parser' | ||
``` | ||
Then, create your handler to respond to the Gotenberg RemoteEvent: | ||
```php | ||
use Sensiolabs\GotenbergBundle\RemoteEvent\ErrorGotenbergEvent; | ||
use Sensiolabs\GotenbergBundle\RemoteEvent\SuccessGotenbergEvent; | ||
use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface; | ||
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer; | ||
use Symfony\Component\RemoteEvent\RemoteEvent; | ||
|
||
#[AsRemoteEventConsumer('gotenberg')] | ||
class WebhookListener implements ConsumerInterface | ||
{ | ||
public function consume(RemoteEvent $event): void | ||
{ | ||
if ($event instanceof SuccessGotenbergEvent) { | ||
// Handle the event | ||
// PDF content is available as a resource through the getFile() method | ||
} elseif ($event instanceof ErrorGotenbergEvent) { | ||
// Handle the error | ||
} | ||
} | ||
} | ||
``` | ||
|
||
> [!WARNING] | ||
> The webhook component **won't be used** if a [native webhook configuration](native.md) is set. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Going async | ||
|
||
* [Native](./async/native.md) | ||
* [Using the Symfony Webhook component](./async/webhook.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Sensiolabs\GotenbergBundle\RemoteEvent; | ||
|
||
use Symfony\Component\RemoteEvent\RemoteEvent; | ||
|
||
class ErrorGotenbergEvent extends RemoteEvent | ||
{ | ||
public const ERROR = 'error'; | ||
|
||
/** | ||
* @param array{status: int, message: string} $payload | ||
*/ | ||
public function __construct( | ||
string $id, | ||
array $payload, | ||
private readonly int $status, | ||
private readonly string $message, | ||
) { | ||
parent::__construct(self::ERROR, $id, $payload); | ||
} | ||
|
||
public function getStatus(): int | ||
{ | ||
return $this->status; | ||
} | ||
|
||
public function getMessage(): string | ||
{ | ||
return $this->message; | ||
} | ||
} |
Oops, something went wrong.