@@ -24,27 +24,23 @@ class DispatchWebhookJob implements ShouldQueue
2424 use SerializesModels;
2525
2626 protected Webhook $ webhook ;
27- protected string $ event ;
2827 protected User $ initiator ;
2928 protected int $ initiatedTime ;
30-
31- /**
32- * @var string|Loggable
33- */
34- protected $ detail ;
29+ protected array $ webhookData ;
3530
3631 /**
3732 * Create a new job instance.
3833 *
3934 * @return void
4035 */
41- public function __construct (Webhook $ webhook , string $ event , $ detail )
36+ public function __construct (Webhook $ webhook , string $ event , Loggable | string $ detail )
4237 {
4338 $ this ->webhook = $ webhook ;
44- $ this ->event = $ event ;
45- $ this ->detail = $ detail ;
4639 $ this ->initiator = user ();
4740 $ this ->initiatedTime = time ();
41+
42+ $ themeResponse = Theme::dispatch (ThemeEvents::WEBHOOK_CALL_BEFORE , $ event , $ this ->webhook , $ detail , $ this ->initiator , $ this ->initiatedTime );
43+ $ this ->webhookData = $ themeResponse ?? WebhookFormatter::getDefault ($ event , $ this ->webhook , $ detail , $ this ->initiator , $ this ->initiatedTime )->format ();
4844 }
4945
5046 /**
@@ -54,15 +50,13 @@ public function __construct(Webhook $webhook, string $event, $detail)
5450 */
5551 public function handle ()
5652 {
57- $ themeResponse = Theme::dispatch (ThemeEvents::WEBHOOK_CALL_BEFORE , $ this ->event , $ this ->webhook , $ this ->detail , $ this ->initiator , $ this ->initiatedTime );
58- $ webhookData = $ themeResponse ?? WebhookFormatter::getDefault ($ this ->event , $ this ->webhook , $ this ->detail , $ this ->initiator , $ this ->initiatedTime )->format ();
5953 $ lastError = null ;
6054
6155 try {
6256 $ response = Http::asJson ()
6357 ->withOptions (['allow_redirects ' => ['strict ' => true ]])
6458 ->timeout ($ this ->webhook ->timeout )
65- ->post ($ this ->webhook ->endpoint , $ webhookData );
59+ ->post ($ this ->webhook ->endpoint , $ this -> webhookData );
6660 } catch (\Exception $ exception ) {
6761 $ lastError = $ exception ->getMessage ();
6862 Log::error ("Webhook call to endpoint {$ this ->webhook ->endpoint } failed with error \"{$ lastError }\"" );
0 commit comments