mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-21 17:17:58 +00:00
when using websockets, an action hook may still provide an absolute http url
This commit is contained in:
@@ -4,6 +4,7 @@ const short = require('short-uuid');
|
|||||||
const {HookMsgTypes} = require('./constants.json');
|
const {HookMsgTypes} = require('./constants.json');
|
||||||
const Websocket = require('ws');
|
const Websocket = require('ws');
|
||||||
const snakeCaseKeys = require('./snakecase-keys');
|
const snakeCaseKeys = require('./snakecase-keys');
|
||||||
|
const HttpRequestor = require('./http-requestor');
|
||||||
const MAX_RECONNECTS = 5;
|
const MAX_RECONNECTS = 5;
|
||||||
const RESPONSE_TIMEOUT_MS = process.env.JAMBONES_WS_API_MSG_RESPONSE_TIMEOUT || 5000;
|
const RESPONSE_TIMEOUT_MS = process.env.JAMBONES_WS_API_MSG_RESPONSE_TIMEOUT || 5000;
|
||||||
|
|
||||||
@@ -32,12 +33,20 @@ class WsRequestor extends BaseRequestor {
|
|||||||
*/
|
*/
|
||||||
async request(type, hook, params) {
|
async request(type, hook, params) {
|
||||||
assert(HookMsgTypes.includes(type));
|
assert(HookMsgTypes.includes(type));
|
||||||
|
const url = hook.url || hook;
|
||||||
|
|
||||||
if (this.maliciousClient) {
|
if (this.maliciousClient) {
|
||||||
this.logger.info({url: this.url}, 'WsRequestor:request - discarding msg to malicious client');
|
this.logger.info({url: this.url}, 'WsRequestor:request - discarding msg to malicious client');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* if we have an absolute url, and it is http then do a standard webhook */
|
||||||
|
if (this._isAbsoluteUrl(url) && url.startsWith('http')) {
|
||||||
|
this.logger.debug({hook}, 'WsRequestor: sending a webhook');
|
||||||
|
const requestor = new HttpRequestor(this.logger, this.account_sid, hook, this.secret);
|
||||||
|
return requestor.request(type, hook, params);
|
||||||
|
}
|
||||||
|
|
||||||
/* connect if necessary */
|
/* connect if necessary */
|
||||||
if (!this.ws) {
|
if (!this.ws) {
|
||||||
if (this.connections >= MAX_RECONNECTS) {
|
if (this.connections >= MAX_RECONNECTS) {
|
||||||
@@ -57,8 +66,6 @@ class WsRequestor extends BaseRequestor {
|
|||||||
|
|
||||||
/* prepare and send message */
|
/* prepare and send message */
|
||||||
const payload = params ? snakeCaseKeys(params, ['customerData', 'sip']) : null;
|
const payload = params ? snakeCaseKeys(params, ['customerData', 'sip']) : null;
|
||||||
const url = hook.url || hook;
|
|
||||||
|
|
||||||
assert.ok(url, 'WsRequestor:request url was not provided');
|
assert.ok(url, 'WsRequestor:request url was not provided');
|
||||||
|
|
||||||
const msgid = short.generate();
|
const msgid = short.generate();
|
||||||
|
|||||||
Reference in New Issue
Block a user