Skip to main content

rust_tg_bot_raw/bot/
inline_methods.rs

1use super::{push_opt, push_opt_str, Bot, Result};
2use crate::request::request_parameter::RequestParameter;
3use crate::types::sent_web_app_message;
4
5#[allow(dead_code)]
6impl Bot {
7    // ======================================================================
8    // Callback & inline queries
9    // ======================================================================
10
11    /// Answers a callback query. Internal raw method used by builder APIs.
12    ///
13    /// Calls the Telegram `answerCallbackQuery` API method.
14    pub async fn answer_callback_query_raw(
15        &self,
16        callback_query_id: &str,
17        text: Option<&str>,
18        show_alert: Option<bool>,
19        url: Option<&str>,
20        cache_time: Option<i64>,
21    ) -> Result<bool> {
22        let mut params = vec![RequestParameter::new(
23            "callback_query_id",
24            serde_json::Value::String(callback_query_id.to_owned()),
25        )];
26        push_opt_str(&mut params, "text", text);
27        push_opt(&mut params, "show_alert", &show_alert)?;
28        push_opt_str(&mut params, "url", url);
29        push_opt(&mut params, "cache_time", &cache_time)?;
30        self.do_post("answerCallbackQuery", params).await
31    }
32
33    /// Answers an inline query. Internal raw method used by builder APIs.
34    ///
35    /// Calls the Telegram `answerInlineQuery` API method.
36    pub async fn answer_inline_query_raw(
37        &self,
38        inline_query_id: &str,
39        results: Vec<serde_json::Value>,
40        cache_time: Option<i64>,
41        is_personal: Option<bool>,
42        next_offset: Option<&str>,
43        button: Option<serde_json::Value>,
44    ) -> Result<bool> {
45        let mut params = vec![
46            RequestParameter::new(
47                "inline_query_id",
48                serde_json::Value::String(inline_query_id.to_owned()),
49            ),
50            RequestParameter::new("results", serde_json::to_value(&results)?),
51        ];
52        push_opt(&mut params, "cache_time", &cache_time)?;
53        push_opt(&mut params, "is_personal", &is_personal)?;
54        push_opt_str(&mut params, "next_offset", next_offset);
55        push_opt(&mut params, "button", &button)?;
56        self.do_post("answerInlineQuery", params).await
57    }
58
59    /// Use this method to store a message that can be sent by a user of a Mini App.
60    ///
61    /// Calls the Telegram `savePreparedInlineMessage` API method.
62    pub async fn save_prepared_inline_message_raw(
63        &self,
64        user_id: i64,
65        result: serde_json::Value,
66        allow_user_chats: Option<bool>,
67        allow_bot_chats: Option<bool>,
68        allow_group_chats: Option<bool>,
69        allow_channel_chats: Option<bool>,
70    ) -> Result<serde_json::Value> {
71        let mut params = vec![
72            RequestParameter::new("user_id", serde_json::to_value(user_id)?),
73            RequestParameter::new("result", result),
74        ];
75        push_opt(&mut params, "allow_user_chats", &allow_user_chats)?;
76        push_opt(&mut params, "allow_bot_chats", &allow_bot_chats)?;
77        push_opt(&mut params, "allow_group_chats", &allow_group_chats)?;
78        push_opt(&mut params, "allow_channel_chats", &allow_channel_chats)?;
79        self.do_post("savePreparedInlineMessage", params).await
80    }
81
82    /// Use this method to set the result of an interaction with a Web App.
83    ///
84    /// Calls the Telegram `answerWebAppQuery` API method.
85    pub async fn answer_web_app_query_raw(
86        &self,
87        web_app_query_id: &str,
88        result: serde_json::Value,
89    ) -> Result<sent_web_app_message::SentWebAppMessage> {
90        let params = vec![
91            RequestParameter::new(
92                "web_app_query_id",
93                serde_json::Value::String(web_app_query_id.to_owned()),
94            ),
95            RequestParameter::new("result", result),
96        ];
97        self.do_post("answerWebAppQuery", params).await
98    }
99}