siera_cloudagent_python/cloudagent/
oob.rs

1use crate::agent::CloudAgentPython;
2use async_trait::async_trait;
3use serde_json::json;
4use siera_agent::error::Result;
5use siera_agent::modules::oob::{
6    OobConnection, OobConnectionCreateInvitationOptions, OobConnectionCreateInvitationResponse,
7    OobConnectionReceiveInvitationOptions, OobModule,
8};
9
10#[async_trait]
11impl OobModule for CloudAgentPython {
12    async fn create_invitation(
13        &self,
14        options: OobConnectionCreateInvitationOptions,
15    ) -> Result<OobConnectionCreateInvitationResponse> {
16        let url = self.create_url(&["out-of-band", "create-invitation"])?;
17        let mut query: Vec<(&str, String)> = vec![];
18
19        if options.multi_use {
20            query.push(("multi_use", true.to_string()));
21        }
22        if options.auto_accept {
23            query.push(("auto_accept", true.to_string()));
24        }
25        if let Some(alias) = &options.alias {
26            query.push(("alias", alias.clone()));
27        }
28
29        let body = Some(json!({
30            "handshake_protocols": [
31                options.handshake_protocol,
32            ]
33        }));
34
35        self.post::<OobConnectionCreateInvitationResponse>(url, Some(query), body)
36            .await
37    }
38    async fn receive_invitation(
39        &self,
40        invitation: OobConnectionReceiveInvitationOptions,
41    ) -> Result<OobConnection> {
42        let url = self.create_url(&["out-of-band", "receive-invitation"])?;
43
44        self.post(url, None, Some(serde_json::to_value(invitation)?))
45            .await
46    }
47}