Skip to main content

matrix_bot_sdk/
clients.rs

1use reqwest::Method;
2use serde_json::Value;
3use url::Url;
4
5use crate::http::MatrixHttp;
6
7#[derive(Clone)]
8pub struct PantalaimonClient {
9    http: MatrixHttp,
10    access_token: String,
11}
12
13impl PantalaimonClient {
14    pub fn new(base_url: Url, access_token: impl Into<String>) -> Self {
15        Self {
16            http: MatrixHttp::new(base_url),
17            access_token: access_token.into(),
18        }
19    }
20
21    pub async fn health(&self) -> anyhow::Result<Value> {
22        self.http
23            .send_json(Method::GET, "/health", Some(&self.access_token), None)
24            .await
25    }
26}
27
28#[derive(Clone)]
29pub struct IdentityClient {
30    http: MatrixHttp,
31    access_token: String,
32}
33
34impl IdentityClient {
35    pub fn new(base_url: Url, access_token: impl Into<String>) -> Self {
36        Self {
37            http: MatrixHttp::new(base_url),
38            access_token: access_token.into(),
39        }
40    }
41
42    pub async fn lookup_3pid(&self, medium: &str, address: &str) -> anyhow::Result<Value> {
43        let endpoint = format!("/_matrix/identity/v2/lookup?medium={medium}&address={address}");
44        self.http
45            .send_json(Method::GET, &endpoint, Some(&self.access_token), None)
46            .await
47    }
48}
49
50#[derive(Clone)]
51pub struct MatrixContentScannerClient {
52    http: MatrixHttp,
53    access_token: String,
54}
55
56impl MatrixContentScannerClient {
57    pub fn new(base_url: Url, access_token: impl Into<String>) -> Self {
58        Self {
59            http: MatrixHttp::new(base_url),
60            access_token: access_token.into(),
61        }
62    }
63
64    pub async fn scan_event(&self, event: Value) -> anyhow::Result<Value> {
65        self.http
66            .send_json(
67                Method::POST,
68                "/_matrix/client/unstable/org.example.content_scanner/scan",
69                Some(&self.access_token),
70                Some(&event),
71            )
72            .await
73    }
74}