mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2026-07-04 19:32:01 +00:00
ensure session end at Ultravox
This commit is contained in:
@@ -146,6 +146,25 @@ class TaskLlmUltravox_S2S extends Task {
|
|||||||
return data;
|
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) {
|
_unregisterHandlers(ep) {
|
||||||
this.removeCustomEventListeners();
|
this.removeCustomEventListeners();
|
||||||
ep.removeAllListeners('dtmf');
|
ep.removeAllListeners('dtmf');
|
||||||
@@ -164,6 +183,7 @@ class TaskLlmUltravox_S2S extends Task {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await this.createCall();
|
const data = await this.createCall();
|
||||||
|
this.callId = data.callId;
|
||||||
const {joinUrl} = data;
|
const {joinUrl} = data;
|
||||||
// split the joinUrl into host and path
|
// split the joinUrl into host and path
|
||||||
const {host, pathname, search} = new URL(joinUrl);
|
const {host, pathname, search} = new URL(joinUrl);
|
||||||
@@ -188,6 +208,8 @@ class TaskLlmUltravox_S2S extends Task {
|
|||||||
|
|
||||||
await this.awaitTaskDone();
|
await this.awaitTaskDone();
|
||||||
|
|
||||||
|
await this.hangupCall();
|
||||||
|
|
||||||
/* note: the parent llm verb started the span, which is why this is necessary */
|
/* note: the parent llm verb started the span, which is why this is necessary */
|
||||||
await this.parent.performAction(this.results);
|
await this.parent.performAction(this.results);
|
||||||
|
|
||||||
@@ -200,6 +222,8 @@ class TaskLlmUltravox_S2S extends Task {
|
|||||||
this._api(cs.ep, [cs.ep.uuid, SessionDelete])
|
this._api(cs.ep, [cs.ep.uuid, SessionDelete])
|
||||||
.catch((err) => this.logger.info({err}, 'TaskLlmUltravox_S2S:kill - error deleting session'));
|
.catch((err) => this.logger.info({err}, 'TaskLlmUltravox_S2S:kill - error deleting session'));
|
||||||
|
|
||||||
|
this.hangupCall();
|
||||||
|
|
||||||
this.notifyTaskDone();
|
this.notifyTaskDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user