Skip to main content

neptunium_http/endpoints/webhooks/
create_webhook.rs

1use bon::Builder;
2use neptunium_model::{
3    guild::webhook::Webhook,
4    id::{Id, marker::ChannelMarker},
5};
6use reqwest::Method;
7use serde::Serialize;
8
9use crate::{endpoints::Endpoint, request::Request};
10
11#[derive(Builder, Clone, Debug)]
12pub struct CreateWebhook {
13    pub channel_id: Id<ChannelMarker>,
14    /// The name of the webhook.
15    pub name: String,
16    /// The avatar image as a base64-encoded data URI.
17    pub avatar: Option<String>,
18}
19
20impl Endpoint for CreateWebhook {
21    type Response = Webhook;
22
23    fn into_request(self) -> crate::request::Request {
24        #[derive(Serialize)]
25        struct CreateWebhookBody {
26            name: String,
27            #[serde(skip_serializing_if = "Option::is_none")]
28            avatar: Option<String>,
29        }
30
31        let body = CreateWebhookBody {
32            name: self.name,
33            avatar: self.avatar,
34        };
35
36        Request::builder()
37            .method(Method::POST)
38            .body(serde_json::to_string(&body).unwrap())
39            .path(format!("/channels/{}/webhooks", self.channel_id))
40            .build()
41    }
42}