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