Before Dispatch
apply_filters_ref_array( 'vikappointments_before_dispatch_webhook', bool $status, mixed &$payload, array &$headers, object $hook, VAPWebHook $job )
Fires before transmitting the payload to the web hook.
Description
Web hooks are used to immediately notify other websites when specific events trigger. In example, it is possible to post the appointment data to a different host every time a new reservation is created.
Plugins can use this trigger to manipulate the payload to post and the request headers.
By setting the payload to false
, the dispatcher will automatically skip the web hook.
The system always includes the following headers by default:
Content-Type: application/json
X-VAP-WEBHOOK-ID: {ID}
(the web hook identifier)X-VAP-WEBHOOK-ACTION: {ACTION}
(the action that triggered the web hook)X-VAP-WEBHOOK-SECURE: {SECURE}
(the web hook secret key, passed to MD5 algorithm)
Parameters
- $status
-
(bool) True on success, false otherwise.
- &$payload
-
(mixed) The payload to send.
- &$headers
-
(array) An associative array containing the request headers.
- $hook
-
(object) An object holding the web hook details, such as the URL to notify and a secret key.
- $job
-
(VAPWebHook) The instance used to generate the payload.
Example
The following example explains how to implement your own BASIC HTTP authentication scheme.
/**
* Plugins can use this event to manipulate the payload to post and the
* request headers. By setting the payload to "false", the dispatcher
* will automatically skip the web hook.
*
* @param boolean $status True on success, false otherwise.
* @param mixed &$payload The payload to send.
* @param array &$headers The request headers.
* @param object $hook The web hook details.
* @param VAPWebHook $job The web hook job.
*/
add_filter('vikappointments_before_dispatch_webhook', function($status, &$payload, &$headers, $hook, $job)
{
// check whether we are contacting a specific end-point
if (stripos($hook->url, 'mydomain.com'))
{
// include http basic authentication
$headers['Authorization'] = 'Basic ' . base64_encode('{username}:{password}');
}
return $status;
}, 10, 5);
Changelog
Version | Description |
---|---|
1.2 | Introduced. |