ferrisgram/methods/
send_message.rs1#![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 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 #[serde(skip_serializing_if = "Option::is_none")]
26 pub business_connection_id: Option<String>,
27 pub chat_id: i64,
29 #[serde(skip_serializing_if = "Option::is_none")]
31 pub message_thread_id: Option<i64>,
32 pub text: String,
34 #[serde(skip_serializing_if = "Option::is_none")]
36 pub parse_mode: Option<String>,
37 #[serde(skip_serializing_if = "Option::is_none")]
39 pub entities: Option<Vec<MessageEntity>>,
40 #[serde(skip_serializing_if = "Option::is_none")]
42 pub link_preview_options: Option<LinkPreviewOptions>,
43 #[serde(skip_serializing_if = "Option::is_none")]
45 pub disable_notification: Option<bool>,
46 #[serde(skip_serializing_if = "Option::is_none")]
48 pub protect_content: Option<bool>,
49 #[serde(skip_serializing_if = "Option::is_none")]
51 pub message_effect_id: Option<String>,
52 #[serde(skip_serializing_if = "Option::is_none")]
54 pub reply_parameters: Option<ReplyParameters>,
55 #[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}