titanium_http/
interaction.rs

1use crate::error::HttpError;
2use crate::HttpClient;
3use serde::Serialize;
4use titanium_model::{InteractionResponse, Message, Snowflake};
5
6impl HttpClient {
7    /// Create a response to an Interaction.
8    ///
9    /// This is the initial response to an interaction (Slash Command, Button, etc.).
10    /// You must respond within 3 seconds, or use `InteractionCallbackType::DeferredChannelMessageWithSource`.
11    pub async fn create_interaction_response(
12        &self,
13        interaction_id: Snowflake,
14        token: &str,
15        response: &InteractionResponse<'_>,
16    ) -> Result<(), HttpError> {
17        let route = format!("/interactions/{}/{}/callback", interaction_id, token);
18        self.post(&route, response).await
19    }
20
21    /// Get the original response message.
22    pub async fn get_original_interaction_response(
23        &self,
24        application_id: Snowflake,
25        token: &str,
26    ) -> Result<Message<'static>, HttpError> {
27        let route = format!("/webhooks/{}/{}/messages/@original", application_id, token);
28        self.get(&route).await
29    }
30
31    /// Edit the original response message.
32    ///
33    /// This is used to update the message after a DEFER response.
34    pub async fn edit_original_interaction_response<B: Serialize>(
35        &self,
36        application_id: Snowflake,
37        token: &str,
38        body: B,
39    ) -> Result<Message<'static>, HttpError> {
40        let route = format!("/webhooks/{}/{}/messages/@original", application_id, token);
41        self.patch(&route, body).await
42    }
43
44    /// Delete the original response message.
45    pub async fn delete_original_interaction_response(
46        &self,
47        application_id: Snowflake,
48        token: &str,
49    ) -> Result<(), HttpError> {
50        let route = format!("/webhooks/{}/{}/messages/@original", application_id, token);
51        self.delete(&route).await
52    }
53
54    /// Create a followup message.
55    ///
56    /// Used to send additional messages after the initial response.
57    pub async fn create_followup_message<B: Serialize>(
58        &self,
59        application_id: Snowflake,
60        token: &str,
61        body: B,
62    ) -> Result<Message<'static>, HttpError> {
63        let route = format!("/webhooks/{}/{}", application_id, token);
64        // "wait=true" ensures we get the Message object back
65        self.post_with_query(&route, body, &[("wait", "true")])
66            .await
67    }
68}