Webhooks
This page has not yet been updated for the new Laravel package.
Currently, r4nkt sends out webhooks for only one event type, but more event types may come in the future.
R4nkt signs all requests that hit your game's specified webhook url. This package will automatically verify each webhook request's signature. If any signature is not valid, the request was likely not sent by r4nkt and will be rejected and a R4nkt\R4nktWebhooks\WebhookFailed
exception will be thrown.
Unless something is wrong, this package will respond with a status code of 200
to all webhook requests. This will prevent r4nkt from resending the same event.
When using this package, you have two ways to handle incoming webhook requests:
you can opt to queue a job
you can set up event listeners
Using Jobs to Handle Webhook Requests
If you want to do something when a specific event type comes in you can define a job that does the work. Here's an example of such a job:
You are advised to make this job queueable. This will minimize the webhook request response time, allow you to handle more r4nkt webhook requests, and help avoid timeouts.
Once your job is created, it must be registered in the jobs array in the r4nkt.php
config file. The key should be the name of the r4nkt event type and the value should be the job's fully qualified class name.
Using Event Listeners to Handle Webhook Requests
Upon receiving a valid webhook request, this package will fire a r4nkt-webhooks::*
event. So, you can define event listeners to listen for any events this package might fire.
The event payload will be the instance of R4nktWebhookCall
that was created for the incoming request.
Here is an example of how you can listen for an event by registering a listener in the EventServiceProvider
:
Here's an example of such a listener:
You are advised to make this event listener queueable. This will minimize the webhook request response time, allow you to handle more r4nkt webhook requests, and help avoid timeouts.
The above example is only one way to handle events in Laravel. To learn the other options, read the Laravel documentation on handling events.
Using the Webhook Call Object
As already noted, your events or jobs will receive an instance of R4nkt\LaravelWebhooks\R4nktWebhookCall
.
You can access the raw payload by calling:
Or you can opt to get more specific information:
Last updated