ensure session end at Ultravox

This commit is contained in:
rhonda hollis
2026-05-15 13:00:29 -07:00
parent cb581f9be7
commit 57cdd8ed0f
+24
View File
@@ -146,6 +146,25 @@ class TaskLlmUltravox_S2S extends Task {
return data;
}
async hangupCall() {
if (!this.callId || this._hangupSent) return;
this._hangupSent = true;
const url = `https://api.ultravox.ai/api/calls/${this.callId}/send_data_message`;
try {
const {statusCode} = await request(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': this.apiKey
},
body: JSON.stringify({type: 'hang_up'})
});
this.logger.debug({statusCode, callId: this.callId}, 'TaskLlmUltravox_S2S:hangupCall - sent hang_up');
} catch (err) {
this.logger.info({err, callId: this.callId}, 'TaskLlmUltravox_S2S:hangupCall - error');
}
}
_unregisterHandlers(ep) {
this.removeCustomEventListeners();
ep.removeAllListeners('dtmf');
@@ -164,6 +183,7 @@ class TaskLlmUltravox_S2S extends Task {
try {
const data = await this.createCall();
this.callId = data.callId;
const {joinUrl} = data;
// split the joinUrl into host and path
const {host, pathname, search} = new URL(joinUrl);
@@ -188,6 +208,8 @@ class TaskLlmUltravox_S2S extends Task {
await this.awaitTaskDone();
await this.hangupCall();
/* note: the parent llm verb started the span, which is why this is necessary */
await this.parent.performAction(this.results);
@@ -200,6 +222,8 @@ class TaskLlmUltravox_S2S extends Task {
this._api(cs.ep, [cs.ep.uuid, SessionDelete])
.catch((err) => this.logger.info({err}, 'TaskLlmUltravox_S2S:kill - error deleting session'));
this.hangupCall();
this.notifyTaskDone();
}