add deleteCall function to properly cleanup Ultravox session

This commit is contained in:
oddsix
2026-03-11 12:01:54 -04:00
parent 1560efaf03
commit a726aa8658

View File

@@ -146,6 +146,23 @@ class TaskLlmUltravox_S2S extends Task {
return data;
}
async deleteCall() {
if (!this.callId) return;
const baseUrl = 'https://api.ultravox.ai';
const url = `${baseUrl}/api/calls/${this.callId}`;
try {
const {statusCode} = await request(url, {
method: 'DELETE',
headers: {
'X-API-Key': this.apiKey
}
});
this.logger.debug({statusCode, callId: this.callId}, 'Ultravox call deleted');
} catch (err) {
this.logger.info({err, callId: this.callId}, 'TaskLlmUltravox_S2S:deleteCall - error');
}
}
_unregisterHandlers(ep) {
this.removeCustomEventListeners();
ep.removeAllListeners('dtmf');
@@ -164,6 +181,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 +206,8 @@ class TaskLlmUltravox_S2S extends Task {
await this.awaitTaskDone();
await this.deleteCall();
/* note: the parent llm verb started the span, which is why this is necessary */
await this.parent.performAction(this.results);
@@ -200,6 +220,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.deleteCall();
this.notifyTaskDone();
}