Skip to content

Commit 60e5b23

Browse files
author
janligudzinski
committed
add accept/reject/refer SIP calls to v1 client
1 parent af2b94d commit 60e5b23

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

src/v1/api.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::v1::audio::{
77
AudioTranslationRequest, AudioTranslationResponse,
88
};
99
use crate::v1::batch::{BatchResponse, CreateBatchRequest, ListBatchResponse};
10+
use crate::v1::calls::{AcceptCallRequest, ReferCallRequest};
1011
use crate::v1::chat_completion::{ChatCompletionRequest, ChatCompletionResponse};
1112
use crate::v1::common;
1213
use crate::v1::completion::{CompletionRequest, CompletionResponse};
@@ -796,6 +797,32 @@ impl OpenAIClient {
796797
self.delete(&format!("models/{model_id}")).await
797798
}
798799

800+
pub async fn accept_call(
801+
&mut self,
802+
call_id: &str,
803+
accept: AcceptCallRequest,
804+
) -> Result<(), APIError> {
805+
self.post::<()>(&format!("realtime/calls/{call_id}/accept"), &accept)
806+
.await?;
807+
Ok(())
808+
}
809+
810+
pub async fn reject_call(&mut self, call_id: &str) -> Result<(), APIError> {
811+
self.post::<()>(&format!("realtime/calls/{call_id}/reject"), &())
812+
.await?;
813+
Ok(())
814+
}
815+
816+
pub async fn refer_call(
817+
&mut self,
818+
call_id: &str,
819+
refer: ReferCallRequest,
820+
) -> Result<(), APIError> {
821+
self.post::<()>(&format!("realtime/calls/{call_id}/refer"), &refer)
822+
.await?;
823+
Ok(())
824+
}
825+
799826
fn build_url_with_preserved_query(&self, path: &str) -> Result<String, url::ParseError> {
800827
let (base, query_opt) = match self.api_endpoint.split_once('?') {
801828
Some((b, q)) => (b.trim_end_matches('/'), Some(q)),

src/v1/calls.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
/// Used to start a realtime session based on an incoming call.
4+
/// Note that this is poorly documented by OpenAI with the only example data given in https://platform.openai.com/docs/guides/realtime-sip#handle-the-webhook and these may not be all the possible fields.
5+
#[derive(Debug, Serialize, Deserialize, Clone)]
6+
pub struct AcceptCallRequest {
7+
/// This is *always* `realtime`.
8+
#[serde(rename = "type")]
9+
pub session_type: String,
10+
pub instructions: String,
11+
pub model: String,
12+
}
13+
14+
/// Used to redirect a call to another number. Per https://platform.openai.com/docs/guides/realtime-sip#handle-the-webhook the Tel-URI scheme may be used.
15+
#[derive(Debug, Serialize, Deserialize, Clone)]
16+
pub struct ReferCallRequest {
17+
/// The URI to redirect the call to, for example `tel:+14152909007`
18+
pub target_uri: String,
19+
}

src/v1/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub mod types;
44

55
pub mod audio;
66
pub mod batch;
7+
pub mod calls;
78
pub mod chat_completion;
89
pub mod completion;
910
pub mod edit;

0 commit comments

Comments
 (0)