work on say and gather

This commit is contained in:
Dave Horton
2020-01-13 14:01:19 -05:00
parent 1debb193c2
commit 1a656f3f0e
16 changed files with 1034 additions and 236 deletions

View File

@@ -1,9 +1,10 @@
const debug = require('debug')('jambonz:feature-server');
//const debug = require('debug')('jambonz:feature-server');
const assert = require('assert');
const request = require('request');
//require('request-debug')(request);
const uuidv4 = require('uuid/v4');
const makeTask = require('./tasks/make_task');
const {CallStatus, CallDirection} = require('./utils/constants');
module.exports = function(srf, logger) {
const {lookupAppByPhoneNumber} = srf.locals.dbHelpers;
@@ -65,30 +66,32 @@ module.exports = function(srf, logger) {
const logger = req.locals.logger;
const app = req.locals.application;
const call_sid = uuidv4();
const method = (app.hook_http_method || 'GET').toUpperCase();
const method = (app.hook_http_method || 'POST').toUpperCase();
const from = req.getParsedHeader('From');
const qs = req.locals.callAttributes = {
CallSid: call_sid,
AccountSid: app.account_sid,
From: req.callingNumber,
To: req.calledNumber,
CallStatus: CallStatus.Trying,
SipStatus: 100,
Direction: CallDirection.Inbound,
CallerName: from.name || req.callingNumber,
SipCallID: req.get('Call-ID'),
RequestorIP: req.get('X-Forwarded-For'),
RequestorName: req.get('X-Originating-Carrier')
};
const opts = {
url: app.call_hook,
method,
json: true,
qs: {
CallSid: call_sid,
AccountSid: app.account_sid,
From: req.callingNumber,
To: req.calledNumber,
CallStatus: 'ringing',
Direction: 'inbound',
CallerName: from.name || req.callingNumber
}
qs
};
if (app.hook_basic_auth_user && app.hook_basic_auth_password) {
Object.assign(opts, {auth: {user: app.hook_basic_auth_user, password: app.hook_basic_auth_password}});
}
if (method === 'POST') {
Object.assign(opts, {json: true, body: req.msg});
}
if (method === 'POST') Object.assign(opts, {body: req.msg});
try {
assert(app && app.call_hook);
request(opts, (err, response, body) => {
if (err) {
logger.error(err, `Error invoking callback ${app.call_hook}`);
@@ -102,7 +105,7 @@ module.exports = function(srf, logger) {
const task = makeTask(logger, taskData[t]);
app.tasks.push(task);
} catch (err) {
logger.info({data: taskData[t]}, `invalid web callback payload: ${err.message}`);
logger.error({err, data: taskData[t]}, `invalid web callback payload: ${err.message}`);
res.send(500, 'Application Error', {
headers: {
'X-Reason': err.message