Skip to main content

twilight_http/request/channel/webhook/
get_webhook_message.rs

1#[cfg(not(target_os = "wasi"))]
2use crate::response::{Response, ResponseFuture};
3use crate::{
4    client::Client,
5    error::Error,
6    request::{Request, TryIntoRequest},
7    routing::Route,
8};
9use std::future::IntoFuture;
10use twilight_model::{
11    channel::Message,
12    id::{
13        Id,
14        marker::{ChannelMarker, MessageMarker, WebhookMarker},
15    },
16};
17
18/// Get a webhook message by webhook ID, token, and message ID.
19#[must_use = "requests must be configured and executed"]
20pub struct GetWebhookMessage<'a> {
21    http: &'a Client,
22    message_id: Id<MessageMarker>,
23    thread_id: Option<Id<ChannelMarker>>,
24    token: &'a str,
25    webhook_id: Id<WebhookMarker>,
26}
27
28impl<'a> GetWebhookMessage<'a> {
29    pub(crate) const fn new(
30        http: &'a Client,
31        webhook_id: Id<WebhookMarker>,
32        token: &'a str,
33        message_id: Id<MessageMarker>,
34    ) -> Self {
35        Self {
36            http,
37            message_id,
38            thread_id: None,
39            token,
40            webhook_id,
41        }
42    }
43
44    /// Get a message in a thread belonging to the channel instead of the
45    /// channel itself.
46    pub const fn thread_id(mut self, thread_id: Id<ChannelMarker>) -> Self {
47        self.thread_id.replace(thread_id);
48
49        self
50    }
51}
52
53#[cfg(not(target_os = "wasi"))]
54impl IntoFuture for GetWebhookMessage<'_> {
55    type Output = Result<Response<Message>, Error>;
56
57    type IntoFuture = ResponseFuture<Message>;
58
59    fn into_future(self) -> Self::IntoFuture {
60        let http = self.http;
61
62        match self.try_into_request() {
63            Ok(request) => http.request(request),
64            Err(source) => ResponseFuture::error(source),
65        }
66    }
67}
68
69impl TryIntoRequest for GetWebhookMessage<'_> {
70    fn try_into_request(self) -> Result<Request, Error> {
71        Request::builder(&Route::GetWebhookMessage {
72            message_id: self.message_id.get(),
73            thread_id: self.thread_id.map(Id::get),
74            token: self.token,
75            webhook_id: self.webhook_id.get(),
76        })
77        .use_authorization_token(false)
78        .build()
79    }
80}