From 7e2fe72b6ccf59806e489ec1f549d83e4ff38a77 Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Mon, 28 Apr 2025 19:46:08 +0700 Subject: [PATCH] fix say verb cannot failover if tts_response-code != 2xx (#1174) --- lib/tasks/say.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/tasks/say.js b/lib/tasks/say.js index 705d17ea..137ce20b 100644 --- a/lib/tasks/say.js +++ b/lib/tasks/say.js @@ -223,7 +223,17 @@ class TaskSay extends TtsTask { }); ep.once('playback-stop', (evt) => { this.logger.debug({evt}, 'Say got playback-stop'); - if (evt.variable_tts_error) { + const tts_error = evt.variable_tts_error; + let response_code = 200; + // Check if any property ends with _response_code + for (const [key, value] of Object.entries(evt)) { + if (key.endsWith('_response_code')) { + response_code = parseInt(value, 10) || 200; + break; + } + } + + if (tts_error) { writeAlerts({ account_sid, alert_type: AlertType.TTS_FAILURE, @@ -232,7 +242,7 @@ class TaskSay extends TtsTask { target_sid }).catch((err) => this.logger.info({err}, 'Error generating alert for no tts')); } - if (evt.variable_tts_cache_filename && !this.killed) { + if (!tts_error && response_code < 300 && evt.variable_tts_cache_filename && !this.killed) { const text = parseTextFromSayString(this.text[segment]); addFileToCache(evt.variable_tts_cache_filename, { account_sid, @@ -246,7 +256,8 @@ class TaskSay extends TtsTask { } if (this._playResolve) { - evt.variable_tts_error ? this._playReject(new Error(evt.variable_tts_error)) : this._playResolve(); + (tts_error || response_code >= 300) ? this._playReject(new Error(evt.variable_tts_error)) : + this._playResolve(); } }); // wait for playback-stop event received to confirm if the playback is successful