1.0.1 • Published 4 years ago

polling-to-webhook v1.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

polling-to-webhook

A simple way to implement a polling mechanism that triggers a webhook in response.

npm.io

  • cron expression config
    • location: config/default.json
    • content:
{
    "job": {
        "cron": "* * * * *"
    }
}
  • callbacks to evaluate the response from the polling
const evaluteTrue = function(response){
    console.log("positive evaluation");
    return true;
}

const evaluteFalse = function(response){
    console.log("negative evaluation");
    return false;
}
  • request-promise options that will be used for the polling and for the webhook response
const options = {uri:'https://www.google.pt/', method: 'GET'};
const webhookOptions = {uri:'http://localhost:8000/', method: 'GET'};
  • simple use case of polling-2-webhook
const pollingManager = require('polling-to-webhook');
pollingManager.registerPolling('key1', options, webhookOptions, evaluteTrue);
pollingManager.registerPolling('key2', options, webhookOptions, evaluteTrue);
pollingManager.registerPolling('key3', options, webhookOptions, evaluteTrue);
pollingManager.registerPolling('key4', options, webhookOptions, evaluteFalse);
  • If you need to refresh tokens or headers, just register a new object with the same key of the object you wish to update.