ferrisgram/methods/
send_message.rs

1// WARNING: THIS CODE IS AUTOGENERATED.
2// DO NOT EDIT!!!
3
4#![allow(clippy::too_many_arguments)]
5use serde::Serialize;
6
7use crate::error::Result;
8use crate::types::Message;
9use crate::types::{InlineKeyboardMarkup, LinkPreviewOptions, MessageEntity, ReplyParameters};
10use crate::Bot;
11
12impl Bot {
13    /// Use this method to send text messages. On success, the sent Message is returned.
14    /// <https://core.telegram.org/bots/api#sendmessage>
15    pub fn send_message(&self, chat_id: i64, text: String) -> SendMessageBuilder {
16        SendMessageBuilder::new(self, chat_id, text)
17    }
18}
19
20#[derive(Serialize)]
21pub struct SendMessageBuilder<'a> {
22    #[serde(skip)]
23    bot: &'a Bot,
24    /// Unique identifier of the business connection on behalf of which the message will be sent
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub business_connection_id: Option<String>,
27    /// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
28    pub chat_id: i64,
29    /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub message_thread_id: Option<i64>,
32    /// Text of the message to be sent, 1-4096 characters after entities parsing
33    pub text: String,
34    /// Mode for parsing entities in the message text. See formatting options for more details.
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub parse_mode: Option<String>,
37    /// A JSON-serialized list of special entities that appear in message text, which can be specified instead of parse_mode
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub entities: Option<Vec<MessageEntity>>,
40    /// Link preview generation options for the message
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub link_preview_options: Option<LinkPreviewOptions>,
43    /// Sends the message silently. Users will receive a notification with no sound.
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub disable_notification: Option<bool>,
46    /// Protects the contents of the sent message from forwarding and saving
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub protect_content: Option<bool>,
49    /// Unique identifier of the message effect to be added to the message; for private chats only
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub message_effect_id: Option<String>,
52    /// Description of the message to reply to
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub reply_parameters: Option<ReplyParameters>,
55    /// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub reply_markup: Option<InlineKeyboardMarkup>,
58}
59
60impl<'a> SendMessageBuilder<'a> {
61    pub fn new(bot: &'a Bot, chat_id: i64, text: String) -> Self {
62        Self {
63            bot,
64            business_connection_id: None,
65            chat_id,
66            message_thread_id: None,
67            text,
68            parse_mode: None,
69            entities: None,
70            link_preview_options: None,
71            disable_notification: None,
72            protect_content: None,
73            message_effect_id: None,
74            reply_parameters: None,
75            reply_markup: None,
76        }
77    }
78
79    pub fn business_connection_id(mut self, business_connection_id: String) -> Self {
80        self.business_connection_id = Some(business_connection_id);
81        self
82    }
83
84    pub fn chat_id(mut self, chat_id: i64) -> Self {
85        self.chat_id = chat_id;
86        self
87    }
88
89    pub fn message_thread_id(mut self, message_thread_id: i64) -> Self {
90        self.message_thread_id = Some(message_thread_id);
91        self
92    }
93
94    pub fn text(mut self, text: String) -> Self {
95        self.text = text;
96        self
97    }
98
99    pub fn parse_mode(mut self, parse_mode: String) -> Self {
100        self.parse_mode = Some(parse_mode);
101        self
102    }
103
104    pub fn entities(mut self, entities: Vec<MessageEntity>) -> Self {
105        self.entities = Some(entities);
106        self
107    }
108
109    pub fn link_preview_options(mut self, link_preview_options: LinkPreviewOptions) -> Self {
110        self.link_preview_options = Some(link_preview_options);
111        self
112    }
113
114    pub fn disable_notification(mut self, disable_notification: bool) -> Self {
115        self.disable_notification = Some(disable_notification);
116        self
117    }
118
119    pub fn protect_content(mut self, protect_content: bool) -> Self {
120        self.protect_content = Some(protect_content);
121        self
122    }
123
124    pub fn message_effect_id(mut self, message_effect_id: String) -> Self {
125        self.message_effect_id = Some(message_effect_id);
126        self
127    }
128
129    pub fn reply_parameters(mut self, reply_parameters: ReplyParameters) -> Self {
130        self.reply_parameters = Some(reply_parameters);
131        self
132    }
133
134    pub fn reply_markup(mut self, reply_markup: InlineKeyboardMarkup) -> Self {
135        self.reply_markup = Some(reply_markup);
136        self
137    }
138
139    pub async fn send(self) -> Result<Message> {
140        let form = serde_json::to_value(&self)?;
141        self.bot.get("sendMessage", Some(&form)).await
142    }
143}