Khosmo
This module allows you to easily implement a webhook service to monitor changes of state. They rely on the pre-configuration of triggers that when triggered send notifications and share data in real time. This module also has a built-in server for implementing a webhook receiving API.
Get started
Install module in your project
npm i --save khosmo
Basic usage
Start module:
const khosmo = ;
Create webhook events pointing to one http data receptor:
// hook onekhosmo;// hook twokhosmo;
To trigger a hook call it by passing the data you want to send:
khosmo;
You can also notify with a simple text, example:
khosmo;
Send notification with custom headers using JSON object:
khosmo.send( [webhook_name], [data], [headers])
khosmo;
Server api
Khosmo has an integrated server that can serve as a webhook. This way you can create services to receive data sent from any webhook sender.
Build one basic Khosmo receiver:
const khosmo = ;// Configurekhosmo;// Defines a global service for receiving messageskhosmoall { console;};
Start the server with:
khosmo;
The webhook receiver is started and all messages sent to http: // localhost:8000
will be captured in khosmo.all()
.
The default service settings are set to:
khosmo.config()
. Check all the settings in the options session
Filter JSON data
Set data filters for the message receiver. All data sent in JSON will be filtered through a specific, preconfigured key contained in the first level of the object, example:
// Configure the JSON key to perform the action filter// "action_type" is filter custom keykhosmo;// Create one filter to actionkhosmo;
- The webhook sends a notification as the template below to be filtered in this action:
Server router
You can create a customized http api through the system of routes integrated in the Khosmo, example:
khosmo;//-khosmo;
File observer
Define a file monitor to identify and intercept actions that occur in a particular directory, for example:
khosmo;
Check params:
observe( [path], [callback], [options] )
Now run a hook trigger and notify a service whenever there are changes in states to any file.
// create one hook triggerkhosmo;// create one file observer definindo ./my_files como diretório de monitoramentokhosmo;
Options
All options configure of Khosmo.
{ "action": "action_check_key", "parser": true, "route": "/", "debug": false}
key | Specifications |
---|---|
action | String with action key to filter on receiver |
parser | Boolean to convert body request to json (true is default) |
route | Default route the receiver api |
debug | Boolean define if debug mod is active |
Current features
- Notifications trigger
- Webhook receptor service filter
- Api http service
- File observer
License
The MIT License (MIT)