Backend Webhooks
Helper module for working with Webhooks in Zengine backend Plugins.
Installation
npm i @zenginehq/backend-webhooks --save
Usage
var $webhook = require('@zenginehq/backend-webhooks');
var $firebase = require('@zenginehq/backend-firebase');
var $api = require('@zenginehq/backend-http');
var workspace;
var activity;
$firebase.load(workspaceId).then(function (settings) {
if (!$webhook.validateSecret(settings, eventData.request)) {
return eventData.response.status(403).send('Invalid Webhook Key');
}
return $api.getActivity(activity.id).then(function (fullActivity) {
if ($webhook.activityToFolder(fullActivity, settings.submittedFolder)) {
}
if (!$webhook.activityFromFolder(fullActivity, settings.submittedFolder)) {
}
});
});
Methods
validateSecret(settings, request)
Returns whether the webhook id and secret match what's stored in settings.
Out of the box expects the id to be stored in settings.webhookId
and the key in settings.webhookKey
.
You can customize this by calling $webhook.setIdField('myIdField)
and $webhook.setKeyField('myKeyField')
.
activityToFolder(activity, toFolder)
Returns whether the given activity is a move to the specified folder (ie: record moved from a folder this this one)
activityFromFolder(activity, toFolder)
Returns whether the given activity is a move from the specified folder (ie: record moved from this folder this another one)
API Docs
Full documentation