Skip to main content

conogram/methods/
set_message_reaction.rs

1use std::{
2    future::{Future, IntoFuture},
3    pin::Pin,
4};
5
6use serde::Serialize;
7
8use crate::{
9    api::API,
10    entities::{misc::chat_id::ChatId, reaction_type::ReactionType},
11    errors::ConogramError,
12    impl_into_future,
13    request::RequestT,
14    utils::deserialize_utils::is_false,
15};
16
17#[derive(Debug, Clone, Serialize)]
18pub struct SetMessageReactionParams {
19    pub chat_id: ChatId,
20    pub message_id: i64,
21    #[serde(skip_serializing_if = "Vec::is_empty")]
22    pub reaction: Vec<ReactionType>,
23    #[serde(default, skip_serializing_if = "is_false")]
24    pub is_big: bool,
25}
26
27impl_into_future!(SetMessageReactionRequest<'a>);
28
29///Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns *True* on success.
30#[derive(Clone)]
31pub struct SetMessageReactionRequest<'a> {
32    api: &'a API,
33    params: SetMessageReactionParams,
34}
35
36impl<'a> RequestT for SetMessageReactionRequest<'a> {
37    type ParamsType = SetMessageReactionParams;
38    type ReturnType = bool;
39    fn get_name() -> &'static str {
40        "setMessageReaction"
41    }
42    fn get_api_ref(&self) -> &API {
43        self.api
44    }
45    fn get_params_ref(&self) -> &Self::ParamsType {
46        &self.params
47    }
48    fn is_multipart() -> bool {
49        false
50    }
51}
52impl<'a> SetMessageReactionRequest<'a> {
53    pub fn new(api: &'a API, chat_id: impl Into<ChatId>, message_id: impl Into<i64>) -> Self {
54        Self {
55            api,
56            params: SetMessageReactionParams {
57                chat_id: chat_id.into(),
58                message_id: message_id.into(),
59                reaction: Vec::default(),
60                is_big: bool::default(),
61            },
62        }
63    }
64
65    ///Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
66    #[must_use]
67    pub fn chat_id(mut self, chat_id: impl Into<ChatId>) -> Self {
68        self.params.chat_id = chat_id.into();
69        self
70    }
71
72    ///Identifier of the target message. If the message belongs to a media group, the reaction is set to the first non-deleted message in the group instead.
73    #[must_use]
74    pub fn message_id(mut self, message_id: impl Into<i64>) -> Self {
75        self.params.message_id = message_id.into();
76        self
77    }
78
79    ///A JSON-serialized list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators. Paid reactions can't be used by bots.
80    #[must_use]
81    pub fn reaction(mut self, reaction: impl IntoIterator<Item = impl Into<ReactionType>>) -> Self {
82        self.params.reaction = reaction.into_iter().map(Into::into).collect();
83        self
84    }
85
86    ///Pass *True* to set the reaction with a big animation
87    #[must_use]
88    pub fn is_big(mut self, is_big: impl Into<bool>) -> Self {
89        self.params.is_big = is_big.into();
90        self
91    }
92}
93
94impl API {
95    ///Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns *True* on success.
96    pub fn set_message_reaction(
97        &self,
98        chat_id: impl Into<ChatId>,
99        message_id: impl Into<i64>,
100    ) -> SetMessageReactionRequest {
101        SetMessageReactionRequest::new(self, chat_id, message_id)
102    }
103}
104
105// Divider: all content below this line will be preserved after code regen