Created
May 6, 2020 21:55
-
-
Save nasrulhazim/9659298fc56679d0de12cfd901ef2c5b to your computer and use it in GitHub Desktop.
Webhook Handler Controller
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
<?php | |
namespace App\Http\Controllers\Webhooks; | |
use App\Http\Controllers\Controller; | |
use App\Models\WebhookCall; | |
use App\WebhookClient\SignatureValidator\GitHubSignatureValidator; | |
use Illuminate\Http\Request; | |
use Spatie\WebhookClient\WebhookConfig; | |
use Spatie\WebhookClient\WebhookProcessor; | |
use Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile; | |
class GitHubController extends Controller | |
{ | |
/** | |
* Handle the incoming request. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function __invoke(Request $request, string $configKey = null) | |
{ | |
$webhookConfig = new WebhookConfig([ | |
'name' => 'github', | |
'signing_secret' => ($configKey) ? | |
config('webhooks.github.signing_secret.' . $configKey) : | |
config('webhooks.github.signing_secret'), | |
'signature_header_name' => config('webhooks.github.signature_header_name'), | |
'signature_validator' => GitHubSignatureValidator::class, | |
'webhook_profile' => ProcessEverythingWebhookProfile::class, | |
'webhook_model' => WebhookCall::class, | |
'process_webhook_job' => config('webhooks.github.model'), | |
]); | |
(new WebhookProcessor($request, $webhookConfig))->process(); | |
return response()->json([ | |
'message' => 'ok', | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment