Loading...
 
Skip to main content

Webhooks

New in Tiki25, Webhooks can be used by an external system for notifying your system about a certain event or update.
They are for example, a universal means of sending data about contacts and their activities to a third party in real time as a change or activity occurs.

To allow web applications to communicate with each other in an automated way, Webhooks allow interaction between them through the use of customized callbacks.

In other words, a webhook triggers an action following an event. It allows you to receive an alert when a chosen event occurs in another system.

In Tiki25, we have integrated this system because some functionalities might need these kinds of callbacks in order to finalize with the actions they serve.

Initial commit: https://gitlab.com/tikiwiki/tiki/-/merge_requests/1649

Requirements

For this to work in Tiki, some configuration needs to be done but before that here is all you need:

  • the URL of the system from which you want to receive events. You need so to create a webhook in your caller system giving the correct tiki-webhooks.php url (it is output in Tiki admin)
  • The secret key which you should find and copy from the administration panel of the calling system.

Setup

For this to work, you have to do two steps:

Into the caller system

There, when you create a webhook, you will be asked to fill in the callback URL where the data will be retransmitted once an action has just been completed.
It is therefore there that you will look for the correct url tiki-webhooks.php.

This file is responsible for authenticating the user via a webhook. Webhooks are automatically verified. We try to check all those defined one by one and the first one to succeed wins. If none pass the check, we return an error.

You must therefore copy the secret code that will be provided to you, and that you will use in Tiki as described in the following point.

Into Tiki

  1. Go to Tiki admin -> Advanced -> security -> webhooks (Tab)
  2. Enable Webhook access
  3. create a webhook handler:
    • Verification type is 'base64 hmac',
    • Algo is sha256,
    • Header value is 'Webhook-Signature' and
    • Secret you can copy from your calling system admin panel
Click to expand
Click to expand

Webhook handling

Now that the prerequisites are done, you need to add the php code that manages the webhook in your Tiki installation.
This should be done here: _custom/lib/setup/custom.php.
In this file you should proceed like this:

  1. First define your custom event handler function
  2. Bind your custom function to an event. For this this case the event must be tiki.webhook.received
There is a readme explaining but in short, it can be something like:
Copy to clipboard
function my_webhook_handler($args) { // access the webhook object at $args['webhook'] // access input with normal PHP STDIN or access any other Tiki global variables as $user, $input, $_REQUEST, etc. } TikiLib::lib('events')->bind('tiki.webhook.received', 'my_webhook_handler');


Note that the chosen user at webhook creation time is automatically logged in, so your custom.php code will perform actions on behalf of that user.