diff --git a/lib/routes/api/accounts.js b/lib/routes/api/accounts.js index afa8a03..3ac5cd3 100644 --- a/lib/routes/api/accounts.js +++ b/lib/routes/api/accounts.js @@ -131,8 +131,34 @@ async function validateCreateCall(logger, sid, req) { }); } - if (!obj.call_hook || (typeof obj.call_hook === 'object' && !obj.call_hook.url)) { - throw new DbErrorBadRequest('either url or application_sid required'); + if (!obj.call_hook && !obj.application_sid) { + throw new DbErrorBadRequest('either call_hook or application_sid required'); + } + if (typeof obj.call_hook === 'string') { + const url = obj.call_hook; + obj.call_hook = { + url, + method: 'POST' + }; + } + if (typeof obj.call_status_hook === 'string') { + const url = obj.call_status_hook; + obj.call_status_hook = { + url, + method: 'POST' + }; + } + if (typeof obj.call_hook === 'object' && typeof obj.call_hook.url != 'string') { + throw new DbErrorBadRequest('call_hook must be string or an object containing a url property'); + } + if (typeof obj.call_status_hook === 'object' && typeof obj.call_status_hook.url != 'string') { + throw new DbErrorBadRequest('call_status_hook must be string or an object containing a url property'); + } + if (obj.call_hook && !/^https?:/.test(obj.call_hook.url)) { + throw new DbErrorBadRequest('call_hook url be an absolute url'); + } + if (obj.call_status_hook && !/^https?:/.test(obj.call_status_hook.url)) { + throw new DbErrorBadRequest('call_status_hook url be an absolute url'); } }