From 5389083107e63750bbc2235e618b335bab90cb44 Mon Sep 17 00:00:00 2001 From: akirilyuk Date: Tue, 1 Feb 2022 18:30:20 +0100 Subject: [PATCH] normalize things --- lib/tasks/cognigy/index.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/tasks/cognigy/index.js b/lib/tasks/cognigy/index.js index 90574049..8439aa6d 100644 --- a/lib/tasks/cognigy/index.js +++ b/lib/tasks/cognigy/index.js @@ -4,6 +4,7 @@ const makeTask = require('../make_task'); const { SocketClient } = require('@cognigy/socket-client'); const SpeechConfig = require('./speech-config'); const queue = require('queue'); +const normalizeJambones = require('../utils/normalize-jambones'); const parseGallery = (obj = {}) => { const {_default} = obj; @@ -199,13 +200,22 @@ class Cognigy extends Task { } _makeReferTask(number) { - const refer = makeTask(this.logger, {'sip:refer': { + const refer = makeTask(this.logger, normalizeJambones(this.logger, [{'sip:refer': { referTo: number, referredBy: 'cognigy' - }}); + }}])[0]); return refer; } + _makeHangupTask(reason) { + const hangup = makeTask(this.logger, normalizeJambones(this.logger, [{hangup: { + headers: { + 'X-Reason': reason + } + }}])[0]); + return hangup; + } + /* if we need to interrupt the currently-running say task(s), call this */ _killSayTasks(ep) { // this will also remove all other upcoming tasks after the say task @@ -273,6 +283,7 @@ class Cognigy extends Task { this._enqueueTask(async() => { this.performAction({cognigyResult: 'hangup Succeeded'}); this.reportedFinalAction = true; + cs.replaceApplication([this._makeReferTask(evt.data.reason)]); cs.replaceApplication([{hangup: { headers: { 'X-Reason': evt.data.reason @@ -286,10 +297,7 @@ class Cognigy extends Task { this._enqueueTask(async() => { this.performAction({cognigyResult: 'refer succeeded'}); this.reportedFinalAction = true; - cs.replaceApplication([{'sip:refer': { - referTo: evt.data.number, - referredBy: 'cognigy' - }}]); + cs.replaceApplication([this._makeReferTask(evt.data.number)]); }); return; default: