initial work on dial verb

This commit is contained in:
Dave Horton
2020-01-07 20:57:49 -05:00
parent 523e2a308b
commit 1debb193c2
8 changed files with 309 additions and 22 deletions

View File

@@ -63,17 +63,33 @@ module.exports = function(srf, logger) {
*/
async function invokeWebCallback(req, res, next) {
const logger = req.locals.logger;
const app = req.locals.application;
const call_sid = uuidv4();
const account_sid = req.locals.application.account_sid;
const application_sid = req.locals.application.application_sid;
const method = (app.hook_http_method || 'GET').toUpperCase();
const from = req.getParsedHeader('From');
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
}
};
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});
}
try {
const app = req.locals.application;
assert(app && app.call_hook);
request.post({
url: app.call_hook,
json: true,
body: req.msg
}, (err, response, body) => {
request(opts, (err, response, body) => {
if (err) {
logger.error(err, `Error invoking callback ${app.call_hook}`);
return res.send(603, 'Bad webhook');