Skip to main content

rust_tg_bot_raw/bot/
other_content.rs

1use super::{push_opt, push_opt_str, Bot, ChatId, Result};
2use crate::request::request_parameter::RequestParameter;
3use crate::types::{input_checklist, message, message_entity, reply, suggested_post};
4
5#[allow(dead_code)]
6impl Bot {
7    // ======================================================================
8    // Sending other content
9    // ======================================================================
10
11    /// Sends a point on the map. Internal raw method used by builder APIs.
12    ///
13    /// Calls the Telegram `sendLocation` API method.
14    pub async fn send_location_raw(
15        &self,
16        chat_id: ChatId,
17        latitude: f64,
18        longitude: f64,
19        horizontal_accuracy: Option<f64>,
20        live_period: Option<i64>,
21        heading: Option<i64>,
22        proximity_alert_radius: Option<i64>,
23        disable_notification: Option<bool>,
24        protect_content: Option<bool>,
25        reply_parameters: Option<reply::ReplyParameters>,
26        reply_markup: Option<serde_json::Value>,
27        message_thread_id: Option<i64>,
28        business_connection_id: Option<&str>,
29        message_effect_id: Option<&str>,
30        allow_paid_broadcast: Option<bool>,
31        direct_messages_topic_id: Option<i64>,
32        suggested_post_parameters: Option<suggested_post::SuggestedPostParameters>,
33    ) -> Result<message::Message> {
34        let mut params = vec![
35            RequestParameter::new("chat_id", serde_json::to_value(&chat_id)?),
36            RequestParameter::new("latitude", serde_json::to_value(latitude)?),
37            RequestParameter::new("longitude", serde_json::to_value(longitude)?),
38        ];
39        push_opt(&mut params, "horizontal_accuracy", &horizontal_accuracy)?;
40        push_opt(&mut params, "live_period", &live_period)?;
41        push_opt(&mut params, "heading", &heading)?;
42        push_opt(
43            &mut params,
44            "proximity_alert_radius",
45            &proximity_alert_radius,
46        )?;
47        push_opt(&mut params, "disable_notification", &disable_notification)?;
48        push_opt(&mut params, "protect_content", &protect_content)?;
49        push_opt(&mut params, "reply_parameters", &reply_parameters)?;
50        push_opt(&mut params, "reply_markup", &reply_markup)?;
51        push_opt(&mut params, "message_thread_id", &message_thread_id)?;
52        push_opt_str(
53            &mut params,
54            "business_connection_id",
55            business_connection_id,
56        );
57        push_opt_str(&mut params, "message_effect_id", message_effect_id);
58        push_opt(&mut params, "allow_paid_broadcast", &allow_paid_broadcast)?;
59        push_opt(
60            &mut params,
61            "direct_messages_topic_id",
62            &direct_messages_topic_id,
63        )?;
64        push_opt(
65            &mut params,
66            "suggested_post_parameters",
67            &suggested_post_parameters,
68        )?;
69        self.do_post("sendLocation", params).await
70    }
71
72    /// Sends information about a venue. Internal raw method used by builder APIs.
73    ///
74    /// Calls the Telegram `sendVenue` API method.
75    pub async fn send_venue_raw(
76        &self,
77        chat_id: ChatId,
78        latitude: f64,
79        longitude: f64,
80        title: &str,
81        address: &str,
82        foursquare_id: Option<&str>,
83        foursquare_type: Option<&str>,
84        google_place_id: Option<&str>,
85        google_place_type: Option<&str>,
86        disable_notification: Option<bool>,
87        protect_content: Option<bool>,
88        reply_parameters: Option<reply::ReplyParameters>,
89        reply_markup: Option<serde_json::Value>,
90        message_thread_id: Option<i64>,
91        business_connection_id: Option<&str>,
92        message_effect_id: Option<&str>,
93        allow_paid_broadcast: Option<bool>,
94        direct_messages_topic_id: Option<i64>,
95        suggested_post_parameters: Option<suggested_post::SuggestedPostParameters>,
96    ) -> Result<message::Message> {
97        let mut params = vec![
98            RequestParameter::new("chat_id", serde_json::to_value(&chat_id)?),
99            RequestParameter::new("latitude", serde_json::to_value(latitude)?),
100            RequestParameter::new("longitude", serde_json::to_value(longitude)?),
101            RequestParameter::new("title", serde_json::Value::String(title.to_owned())),
102            RequestParameter::new("address", serde_json::Value::String(address.to_owned())),
103        ];
104        push_opt_str(&mut params, "foursquare_id", foursquare_id);
105        push_opt_str(&mut params, "foursquare_type", foursquare_type);
106        push_opt_str(&mut params, "google_place_id", google_place_id);
107        push_opt_str(&mut params, "google_place_type", google_place_type);
108        push_opt(&mut params, "disable_notification", &disable_notification)?;
109        push_opt(&mut params, "protect_content", &protect_content)?;
110        push_opt(&mut params, "reply_parameters", &reply_parameters)?;
111        push_opt(&mut params, "reply_markup", &reply_markup)?;
112        push_opt(&mut params, "message_thread_id", &message_thread_id)?;
113        push_opt_str(
114            &mut params,
115            "business_connection_id",
116            business_connection_id,
117        );
118        push_opt_str(&mut params, "message_effect_id", message_effect_id);
119        push_opt(&mut params, "allow_paid_broadcast", &allow_paid_broadcast)?;
120        push_opt(
121            &mut params,
122            "direct_messages_topic_id",
123            &direct_messages_topic_id,
124        )?;
125        push_opt(
126            &mut params,
127            "suggested_post_parameters",
128            &suggested_post_parameters,
129        )?;
130        self.do_post("sendVenue", params).await
131    }
132
133    /// Sends phone contacts. Internal raw method used by builder APIs.
134    ///
135    /// Calls the Telegram `sendContact` API method.
136    pub async fn send_contact_raw(
137        &self,
138        chat_id: ChatId,
139        phone_number: &str,
140        first_name: &str,
141        last_name: Option<&str>,
142        vcard: Option<&str>,
143        disable_notification: Option<bool>,
144        protect_content: Option<bool>,
145        reply_parameters: Option<reply::ReplyParameters>,
146        reply_markup: Option<serde_json::Value>,
147        message_thread_id: Option<i64>,
148        business_connection_id: Option<&str>,
149        message_effect_id: Option<&str>,
150        allow_paid_broadcast: Option<bool>,
151        direct_messages_topic_id: Option<i64>,
152        suggested_post_parameters: Option<suggested_post::SuggestedPostParameters>,
153    ) -> Result<message::Message> {
154        let mut params = vec![
155            RequestParameter::new("chat_id", serde_json::to_value(&chat_id)?),
156            RequestParameter::new(
157                "phone_number",
158                serde_json::Value::String(phone_number.to_owned()),
159            ),
160            RequestParameter::new(
161                "first_name",
162                serde_json::Value::String(first_name.to_owned()),
163            ),
164        ];
165        push_opt_str(&mut params, "last_name", last_name);
166        push_opt_str(&mut params, "vcard", vcard);
167        push_opt(&mut params, "disable_notification", &disable_notification)?;
168        push_opt(&mut params, "protect_content", &protect_content)?;
169        push_opt(&mut params, "reply_parameters", &reply_parameters)?;
170        push_opt(&mut params, "reply_markup", &reply_markup)?;
171        push_opt(&mut params, "message_thread_id", &message_thread_id)?;
172        push_opt_str(
173            &mut params,
174            "business_connection_id",
175            business_connection_id,
176        );
177        push_opt_str(&mut params, "message_effect_id", message_effect_id);
178        push_opt(&mut params, "allow_paid_broadcast", &allow_paid_broadcast)?;
179        push_opt(
180            &mut params,
181            "direct_messages_topic_id",
182            &direct_messages_topic_id,
183        )?;
184        push_opt(
185            &mut params,
186            "suggested_post_parameters",
187            &suggested_post_parameters,
188        )?;
189        self.do_post("sendContact", params).await
190    }
191
192    /// Sends a native poll. Internal raw method used by builder APIs.
193    ///
194    /// Calls the Telegram `sendPoll` API method.
195    pub async fn send_poll_raw(
196        &self,
197        chat_id: ChatId,
198        question: &str,
199        options: Vec<serde_json::Value>,
200        is_anonymous: Option<bool>,
201        poll_type: Option<&str>,
202        allows_multiple_answers: Option<bool>,
203        correct_option_id: Option<i64>,
204        explanation: Option<&str>,
205        explanation_parse_mode: Option<&str>,
206        explanation_entities: Option<Vec<message_entity::MessageEntity>>,
207        open_period: Option<i64>,
208        close_date: Option<i64>,
209        is_closed: Option<bool>,
210        disable_notification: Option<bool>,
211        protect_content: Option<bool>,
212        reply_parameters: Option<reply::ReplyParameters>,
213        reply_markup: Option<serde_json::Value>,
214        message_thread_id: Option<i64>,
215        business_connection_id: Option<&str>,
216        question_parse_mode: Option<&str>,
217        question_entities: Option<Vec<message_entity::MessageEntity>>,
218        message_effect_id: Option<&str>,
219        allow_paid_broadcast: Option<bool>,
220        direct_messages_topic_id: Option<i64>,
221        suggested_post_parameters: Option<suggested_post::SuggestedPostParameters>,
222    ) -> Result<message::Message> {
223        let mut params = vec![
224            RequestParameter::new("chat_id", serde_json::to_value(&chat_id)?),
225            RequestParameter::new("question", serde_json::Value::String(question.to_owned())),
226            RequestParameter::new("options", serde_json::to_value(&options)?),
227        ];
228        push_opt(&mut params, "is_anonymous", &is_anonymous)?;
229        push_opt_str(&mut params, "type", poll_type);
230        push_opt(
231            &mut params,
232            "allows_multiple_answers",
233            &allows_multiple_answers,
234        )?;
235        push_opt(&mut params, "correct_option_id", &correct_option_id)?;
236        push_opt_str(&mut params, "explanation", explanation);
237        push_opt_str(
238            &mut params,
239            "explanation_parse_mode",
240            explanation_parse_mode,
241        );
242        push_opt(&mut params, "explanation_entities", &explanation_entities)?;
243        push_opt(&mut params, "open_period", &open_period)?;
244        push_opt(&mut params, "close_date", &close_date)?;
245        push_opt(&mut params, "is_closed", &is_closed)?;
246        push_opt(&mut params, "disable_notification", &disable_notification)?;
247        push_opt(&mut params, "protect_content", &protect_content)?;
248        push_opt(&mut params, "reply_parameters", &reply_parameters)?;
249        push_opt(&mut params, "reply_markup", &reply_markup)?;
250        push_opt(&mut params, "message_thread_id", &message_thread_id)?;
251        push_opt_str(
252            &mut params,
253            "business_connection_id",
254            business_connection_id,
255        );
256        push_opt_str(&mut params, "question_parse_mode", question_parse_mode);
257        push_opt(&mut params, "question_entities", &question_entities)?;
258        push_opt_str(&mut params, "message_effect_id", message_effect_id);
259        push_opt(&mut params, "allow_paid_broadcast", &allow_paid_broadcast)?;
260        push_opt(
261            &mut params,
262            "direct_messages_topic_id",
263            &direct_messages_topic_id,
264        )?;
265        push_opt(
266            &mut params,
267            "suggested_post_parameters",
268            &suggested_post_parameters,
269        )?;
270        self.do_post("sendPoll", params).await
271    }
272
273    /// Sends an animated emoji that will display a random value. Internal raw method.
274    ///
275    /// Calls the Telegram `sendDice` API method.
276    pub async fn send_dice_raw(
277        &self,
278        chat_id: ChatId,
279        emoji: Option<&str>,
280        disable_notification: Option<bool>,
281        protect_content: Option<bool>,
282        reply_parameters: Option<reply::ReplyParameters>,
283        reply_markup: Option<serde_json::Value>,
284        message_thread_id: Option<i64>,
285        business_connection_id: Option<&str>,
286        message_effect_id: Option<&str>,
287        allow_paid_broadcast: Option<bool>,
288        direct_messages_topic_id: Option<i64>,
289        suggested_post_parameters: Option<suggested_post::SuggestedPostParameters>,
290    ) -> Result<message::Message> {
291        let mut params = vec![RequestParameter::new(
292            "chat_id",
293            serde_json::to_value(&chat_id)?,
294        )];
295        push_opt_str(&mut params, "emoji", emoji);
296        push_opt(&mut params, "disable_notification", &disable_notification)?;
297        push_opt(&mut params, "protect_content", &protect_content)?;
298        push_opt(&mut params, "reply_parameters", &reply_parameters)?;
299        push_opt(&mut params, "reply_markup", &reply_markup)?;
300        push_opt(&mut params, "message_thread_id", &message_thread_id)?;
301        push_opt_str(
302            &mut params,
303            "business_connection_id",
304            business_connection_id,
305        );
306        push_opt_str(&mut params, "message_effect_id", message_effect_id);
307        push_opt(&mut params, "allow_paid_broadcast", &allow_paid_broadcast)?;
308        push_opt(
309            &mut params,
310            "direct_messages_topic_id",
311            &direct_messages_topic_id,
312        )?;
313        push_opt(
314            &mut params,
315            "suggested_post_parameters",
316            &suggested_post_parameters,
317        )?;
318        self.do_post("sendDice", params).await
319    }
320
321    /// Tells the user that something is happening on the bot's side. Internal raw method.
322    ///
323    /// Calls the Telegram `sendChatAction` API method.
324    pub async fn send_chat_action_raw(
325        &self,
326        chat_id: ChatId,
327        action: &str,
328        message_thread_id: Option<i64>,
329        business_connection_id: Option<&str>,
330    ) -> Result<bool> {
331        let mut params = vec![
332            RequestParameter::new("chat_id", serde_json::to_value(&chat_id)?),
333            RequestParameter::new("action", serde_json::Value::String(action.to_owned())),
334        ];
335        push_opt(&mut params, "message_thread_id", &message_thread_id)?;
336        push_opt_str(
337            &mut params,
338            "business_connection_id",
339            business_connection_id,
340        );
341        self.do_post("sendChatAction", params).await
342    }
343
344    /// Use this method to send a checklist message on behalf of a business account.
345    ///
346    /// Calls the Telegram `sendChecklist` API method.
347    pub async fn send_checklist_raw(
348        &self,
349        business_connection_id: &str,
350        chat_id: i64,
351        checklist: input_checklist::InputChecklist,
352        disable_notification: Option<bool>,
353        protect_content: Option<bool>,
354        message_effect_id: Option<&str>,
355        reply_parameters: Option<reply::ReplyParameters>,
356        reply_markup: Option<serde_json::Value>,
357    ) -> Result<message::Message> {
358        let mut params = vec![
359            RequestParameter::new(
360                "business_connection_id",
361                serde_json::Value::String(business_connection_id.to_owned()),
362            ),
363            RequestParameter::new("chat_id", serde_json::to_value(chat_id)?),
364            RequestParameter::new("checklist", serde_json::to_value(&checklist)?),
365        ];
366        push_opt(&mut params, "disable_notification", &disable_notification)?;
367        push_opt(&mut params, "protect_content", &protect_content)?;
368        push_opt_str(&mut params, "message_effect_id", message_effect_id);
369        push_opt(&mut params, "reply_parameters", &reply_parameters)?;
370        push_opt(&mut params, "reply_markup", &reply_markup)?;
371        self.do_post("sendChecklist", params).await
372    }
373}