mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
initial work on dial verb
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user