mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2026-03-21 18:57:53 +00:00
add deleteCall function to properly cleanup Ultravox session
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user