diff --git a/lib/tasks/llm/llms/ultravox_s2s.js b/lib/tasks/llm/llms/ultravox_s2s.js index 1946ba4f..4c8ec939 100644 --- a/lib/tasks/llm/llms/ultravox_s2s.js +++ b/lib/tasks/llm/llms/ultravox_s2s.js @@ -146,8 +146,9 @@ class TaskLlmUltravox_S2S extends Task { return data; } - _unregisterHandlers() { + _unregisterHandlers(ep) { this.removeCustomEventListeners(); + ep.removeAllListeners('dtmf'); } _registerHandlers(ep) { @@ -155,6 +156,7 @@ class TaskLlmUltravox_S2S extends Task { this.addCustomEventListener(ep, LlmEvents_Ultravox.ConnectFailure, this._onConnectFailure.bind(this, ep)); this.addCustomEventListener(ep, LlmEvents_Ultravox.Disconnect, this._onDisconnect.bind(this, ep)); this.addCustomEventListener(ep, LlmEvents_Ultravox.ServerEvent, this._onServerEvent.bind(this, ep)); + ep.on('dtmf', this._onDtmf.bind(this, ep)); } async _startListening(cs, ep) { @@ -189,7 +191,7 @@ class TaskLlmUltravox_S2S extends Task { /* note: the parent llm verb started the span, which is why this is necessary */ await this.parent.performAction(this.results); - this._unregisterHandlers(); + this._unregisterHandlers(ep); } async kill(cs) { @@ -346,6 +348,18 @@ class TaskLlmUltravox_S2S extends Task { excludeEvents: this.excludeEvents }, 'TaskLlmUltravox_S2S:_populateEvents'); } + + _onDtmf(ep, evt) { + this.logger.info({evt}, 'TaskLlmUltravox_S2S:_onDtmf - DTMF received'); + const {dtmf} = evt; + const data = { + type: 'user_text_message', + text: `DTMF received: ${dtmf}`, + urgency: 'immediate' + }; + this._api(ep, [ep.uuid, ClientEvent, JSON.stringify(data)]) + .catch((err) => this.logger.info({err, evt}, 'TaskLlmUltravox_S2S:_onDtmf - Error sending DTMF as text message')); + } } module.exports = TaskLlmUltravox_S2S;