1use crate::error::HttpError;
2use crate::HttpClient;
3use serde::Serialize;
4use titanium_model::{Message, Snowflake, Webhook};
5
6impl HttpClient {
7 pub async fn create_webhook(
9 &self,
10 channel_id: Snowflake,
11 name: &str,
12 avatar: Option<&str>, ) -> Result<Webhook<'static>, HttpError> {
14 #[derive(Serialize)]
15 struct CreateWebhook<'a> {
16 name: &'a str,
17 avatar: Option<&'a str>,
18 }
19
20 let route = format!("/channels/{}/webhooks", channel_id);
21 self.post(&route, CreateWebhook { name, avatar }).await
22 }
23
24 pub async fn get_channel_webhooks(
26 &self,
27 channel_id: Snowflake,
28 ) -> Result<Vec<Webhook<'static>>, HttpError> {
29 let route = format!("/channels/{}/webhooks", channel_id);
30 self.get(&route).await
31 }
32
33 pub async fn get_guild_webhooks(
35 &self,
36 guild_id: Snowflake,
37 ) -> Result<Vec<Webhook<'static>>, HttpError> {
38 let route = format!("/guilds/{}/webhooks", guild_id);
39 self.get(&route).await
40 }
41
42 pub async fn execute_webhook(
47 &self,
48 webhook_id: Snowflake,
49 webhook_token: &str,
50 params: &titanium_model::builder::ExecuteWebhook,
51 ) -> Result<Option<Message<'static>>, HttpError> {
52 let route = format!("/webhooks/{}/{}", webhook_id, webhook_token);
53 self.post_with_query(&route, params, &[("wait", "true")])
55 .await
56 }
57}
58
59