REST createCall must use absolute url in call_hook and call_status_hook

This commit is contained in:
Dave Horton
2021-02-19 11:47:03 -05:00
parent c9eeb41eb6
commit 5f10ef585f
+28 -2
View File
@@ -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');
}
}