mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
work on say and gather
This commit is contained in:
37
lib/utils/notifiers.js
Normal file
37
lib/utils/notifiers.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const request = require('request');
|
||||
require('request-debug')(request);
|
||||
const debug = require('debug')('jambonz:feature-server');
|
||||
|
||||
function hooks(logger, callAttributes) {
|
||||
debug(`notifiers: callAttributes ${JSON.stringify(callAttributes)}`);
|
||||
function actionHook(url, method, opts) {
|
||||
debug(`notifiers: opts ${JSON.stringify(opts)}`);
|
||||
const params = Object.assign({}, callAttributes, opts);
|
||||
const obj = {
|
||||
url,
|
||||
method,
|
||||
json: true,
|
||||
qs: 'GET' === method ? params : null,
|
||||
body: 'POST' === method ? params : null
|
||||
};
|
||||
logger.debug(`${method} ${url} sending ${JSON.stringify(obj)}`);
|
||||
return new Promise((resolve, reject) => {
|
||||
request(obj, (err, response, body) => {
|
||||
if (err) {
|
||||
this.logger.info(`TaskDial:_actionHook error ${method} ${url}: ${err.message}`);
|
||||
return reject(err);
|
||||
}
|
||||
if (body) {
|
||||
this.logger.debug(body, `TaskDial:_actionHook response ${method} ${url}`);
|
||||
}
|
||||
resolve(body);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
actionHook
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = hooks;
|
||||
Reference in New Issue
Block a user