Skip to main content

proto_blue_api/generated/app/bsky/feed/
sendInteractions.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: app.bsky.feed.sendInteractions
3
4use serde::{Deserialize, Serialize};
5
6/// Send information about interactions with feed items back to the feed generator that served them.
7/// XRPC Procedure: app.bsky.feed.sendInteractions
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Input {
11    pub interactions: Vec<crate::app::bsky::feed::defs::Interaction>,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct Output {
17}
18
19/// Errors a `call()` on this method can return.
20#[derive(Debug, thiserror::Error)]
21pub enum CallError {
22    #[error("{0}")]
23    Xrpc(proto_blue_xrpc::XrpcError),
24    #[error(transparent)]
25    Transport(#[from] proto_blue_xrpc::Error),
26    #[error(transparent)]
27    Json(#[from] serde_json::Error),
28}
29
30fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
31    CallError::Xrpc(err)
32}
33
34/// Execute the procedure.
35pub async fn call(
36    client: &proto_blue_xrpc::XrpcClient,
37    input: &Input,
38    opts: Option<&proto_blue_xrpc::CallOptions>,
39) -> Result<Output, CallError> {
40    let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
41    let body = proto_blue_xrpc::XrpcBody::Json(serde_json::to_value(input)?);
42    let response = match client.procedure("app.bsky.feed.sendInteractions", qp_ref, Some(body), opts).await {
43        Ok(r) => r,
44        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
45        Err(e) => return Err(CallError::Transport(e)),
46    };
47    Ok(serde_json::from_value(response.data)?)
48}
49
50/// Register a typed handler for this procedure on an [`XrpcServer`].
51#[cfg(feature = "server")]
52pub fn register<F, Fut>(
53server: proto_blue_xrpc::XrpcServer,
54handler: F,
55) -> proto_blue_xrpc::XrpcServer
56where
57    F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
58    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
59{
60    let handler = std::sync::Arc::new(handler);
61    server.procedure("app.bsky.feed.sendInteractions", move |ctx| {
62        let handler = handler.clone();
63        async move {
64            let input = match ctx.json_body()? {
65                Some(v) => Some(serde_json::from_value::<Input>(v).map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InvalidRequest, format!("input deserialize: {e}")))?),
66                None => None,
67            };
68            let out = handler(ctx, input).await?;
69            let value = serde_json::to_value(&out)
70                .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
71            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
72        }
73    })
74}
75