diff --git a/lib/utils/place-outdial.js b/lib/utils/place-outdial.js index cb6516f3..904c8830 100644 --- a/lib/utils/place-outdial.js +++ b/lib/utils/place-outdial.js @@ -358,6 +358,25 @@ class SingleDialer extends Emitter { this.logger.info(err, 'place-outdial:_configMsEndpoint - error enable inband DTMF'); } } + + const origDestroy = this.ep.destroy.bind(this.ep); + this.ep.destroy = async() => { + try { + if (this.dialTask.transcribeTask) { + // Wait for final transcription before destroying endpoint + // some vendor may take some time to send the final transcription when closing the connectin + // if there is final transcription but the endpoint is destroyed, the transcription will be lost + + // wait for maximum 1 second, if the transcription is not received, destroy the endpoint + this.logger.info('SingleDialer:_configMsEndpoint -' + + ' Dial with transcribe task, wait for some time before destroy'); + await new Promise((resolve) => setTimeout(resolve, 1000)); + } + await origDestroy(); + } catch (err) { + this.logger.error(err, 'SingleDialer:_configMsEndpoint - error destroying endpoint'); + } + }; } /**