mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
work on say and gather
This commit is contained in:
36
lib/utils/constants.json
Normal file
36
lib/utils/constants.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"TaskName": {
|
||||
"Dial": "dial",
|
||||
"Gather": "gather",
|
||||
"Hangup": "hangup",
|
||||
"Listen": "listen",
|
||||
"Play": "play",
|
||||
"redirect": "redirect",
|
||||
"SipDecline": "sip:decline",
|
||||
"SipNotify": "sip:notify",
|
||||
"SipRedirect": "sip:redirect",
|
||||
"Say": "say",
|
||||
"Transcribe": "transcribe"
|
||||
},
|
||||
"CallStatus": {
|
||||
"Trying": "trying",
|
||||
"Ringing": "ringing",
|
||||
"EarlyMedia": "early-media",
|
||||
"InProgress": "in-progress",
|
||||
"Queued": "queued",
|
||||
"Failed": "failed",
|
||||
"Busy": "busy",
|
||||
"NoAnswer": "no-answer",
|
||||
"Completed": "completed"
|
||||
},
|
||||
"CallDirection": {
|
||||
"Inbound": "inbound",
|
||||
"Outbound": "outbound"
|
||||
},
|
||||
"TaskPreconditions": {
|
||||
"None": "none",
|
||||
"Endpoint": "endpoint",
|
||||
"StableCall": "stable-call",
|
||||
"UnansweredCall": "unanswered-call"
|
||||
}
|
||||
}
|
||||
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;
|
||||
50
lib/utils/resources.js
Normal file
50
lib/utils/resources.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const assert = require('assert');
|
||||
|
||||
//this obj is meant to be mixed in into another class
|
||||
//NB: it is required that the class have a 'logger' property
|
||||
module.exports = {
|
||||
resources: new Map(),
|
||||
addResource(name, resource) {
|
||||
this.logger.debug(`addResource: adding ${name}`);
|
||||
|
||||
// duck-typing: resources must have a destroy function and a 'connected' proerty
|
||||
assert(typeof resource.destroy === 'function');
|
||||
assert('connected' in resource);
|
||||
|
||||
this.resources.set(name, resource);
|
||||
},
|
||||
getResource(name) {
|
||||
return this.resources.get(name);
|
||||
},
|
||||
hasResource(name) {
|
||||
return this.resources.has(name);
|
||||
},
|
||||
removeResource(name) {
|
||||
this.logger.debug(`removeResource: removing ${name}`);
|
||||
this.resources.delete(name);
|
||||
},
|
||||
async clearResource(name) {
|
||||
const r = this.resources.get(name);
|
||||
if (r) {
|
||||
this.logger.debug(`clearResource deleting ${name}`);
|
||||
try {
|
||||
if (r.connected) r.destroy();
|
||||
}
|
||||
catch (err) {
|
||||
this.logger.error(err, `clearResource error deleting ${name}`);
|
||||
}
|
||||
this.resources.delete(r);
|
||||
}
|
||||
},
|
||||
async clearResources() {
|
||||
for (const [name, resource] of Array.from(this.resources).reverse()) {
|
||||
try {
|
||||
this.logger.info(`deleting ${name}`);
|
||||
if (resource.connected) await resource.destroy();
|
||||
} catch (err) {
|
||||
this.logger.error(err, `clearResources: error deleting ${name}`);
|
||||
}
|
||||
}
|
||||
this.resources.clear();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user