rustigram_api/methods/
inline.rs1use rustigram_types::inline::{InlineQueryResultsButton, PreparedInlineMessage, SentWebAppMessage};
2
3use crate::client::BotClient;
4use rustigram_types::inline::InlineQueryResult;
5use serde::Serialize;
6use std::future::{Future, IntoFuture};
7use std::pin::Pin;
8
9#[derive(Serialize)]
10struct AnswerInlineQueryParams {
11 inline_query_id: String,
12 results: Vec<InlineQueryResult>,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 cache_time: Option<u32>,
15 #[serde(skip_serializing_if = "Option::is_none")]
16 is_personal: Option<bool>,
17 #[serde(skip_serializing_if = "Option::is_none")]
18 next_offset: Option<String>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 button: Option<InlineQueryResultsButton>,
21}
22
23pub struct AnswerInlineQuery {
25 client: BotClient,
26 params: AnswerInlineQueryParams,
27}
28impl AnswerInlineQuery {
29 pub(crate) fn new(
30 client: BotClient,
31 inline_query_id: impl Into<String>,
32 results: Vec<InlineQueryResult>,
33 ) -> Self {
34 Self {
35 client,
36 params: AnswerInlineQueryParams {
37 inline_query_id: inline_query_id.into(),
38 results,
39 cache_time: None,
40 is_personal: None,
41 next_offset: None,
42 button: None,
43 },
44 }
45 }
46 pub fn cache_time(mut self, secs: u32) -> Self {
48 self.params.cache_time = Some(secs);
49 self
50 }
51 pub fn is_personal(mut self, v: bool) -> Self {
53 self.params.is_personal = Some(v);
54 self
55 }
56 pub fn next_offset(mut self, o: impl Into<String>) -> Self {
58 self.params.next_offset = Some(o.into());
59 self
60 }
61 pub fn button(mut self, v: InlineQueryResultsButton) -> Self {
63 self.params.button = Some(v);
64 self
65 }
66}
67impl IntoFuture for AnswerInlineQuery {
68 type Output = crate::error::Result<bool>;
69 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
70 fn into_future(self) -> Self::IntoFuture {
71 Box::pin(async move {
72 self.client
73 .post_json("answerInlineQuery", &self.params)
74 .await
75 })
76 }
77}
78
79#[derive(Serialize)]
82struct AnswerWebAppQueryParams {
83 web_app_query_id: String,
84 result: InlineQueryResult,
85}
86
87pub struct AnswerWebAppQuery {
93 client: BotClient,
94 params: AnswerWebAppQueryParams,
95}
96
97impl AnswerWebAppQuery {
98 pub(crate) fn new(
99 client: BotClient,
100 web_app_query_id: impl Into<String>,
101 result: InlineQueryResult,
102 ) -> Self {
103 Self {
104 client,
105 params: AnswerWebAppQueryParams {
106 web_app_query_id: web_app_query_id.into(),
107 result,
108 },
109 }
110 }
111}
112
113impl IntoFuture for AnswerWebAppQuery {
114 type Output = crate::error::Result<SentWebAppMessage>;
115 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
116 fn into_future(self) -> Self::IntoFuture {
117 Box::pin(async move {
118 self.client
119 .post_json("answerWebAppQuery", &self.params)
120 .await
121 })
122 }
123}
124
125#[derive(Serialize)]
128struct SavePreparedInlineMessageParams {
129 user_id: i64,
130 result: InlineQueryResult,
131 #[serde(skip_serializing_if = "Option::is_none")]
132 allow_user_chats: Option<bool>,
133 #[serde(skip_serializing_if = "Option::is_none")]
134 allow_bot_chats: Option<bool>,
135 #[serde(skip_serializing_if = "Option::is_none")]
136 allow_group_chats: Option<bool>,
137 #[serde(skip_serializing_if = "Option::is_none")]
138 allow_channel_chats: Option<bool>,
139}
140
141pub struct SavePreparedInlineMessage {
146 client: BotClient,
147 params: SavePreparedInlineMessageParams,
148}
149
150impl SavePreparedInlineMessage {
151 pub(crate) fn new(client: BotClient, user_id: i64, result: InlineQueryResult) -> Self {
152 Self {
153 client,
154 params: SavePreparedInlineMessageParams {
155 user_id,
156 result,
157 allow_user_chats: None,
158 allow_bot_chats: None,
159 allow_group_chats: None,
160 allow_channel_chats: None,
161 },
162 }
163 }
164 pub fn allow_user_chats(mut self, v: bool) -> Self {
166 self.params.allow_user_chats = Some(v);
167 self
168 }
169 pub fn allow_bot_chats(mut self, v: bool) -> Self {
171 self.params.allow_bot_chats = Some(v);
172 self
173 }
174 pub fn allow_group_chats(mut self, v: bool) -> Self {
176 self.params.allow_group_chats = Some(v);
177 self
178 }
179 pub fn allow_channel_chats(mut self, v: bool) -> Self {
181 self.params.allow_channel_chats = Some(v);
182 self
183 }
184}
185
186impl IntoFuture for SavePreparedInlineMessage {
187 type Output = crate::error::Result<PreparedInlineMessage>;
188 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
189 fn into_future(self) -> Self::IntoFuture {
190 Box::pin(async move {
191 self.client
192 .post_json("savePreparedInlineMessage", &self.params)
193 .await
194 })
195 }
196}
197
198#[derive(Serialize)]
201struct AnswerGuestQueryParams {
202 guest_query_id: String,
203 result: rustigram_types::inline::InlineQueryResult,
204}
205
206pub struct AnswerGuestQuery {
211 client: crate::client::BotClient,
212 params: AnswerGuestQueryParams,
213}
214
215impl AnswerGuestQuery {
216 pub(crate) fn new(
217 client: crate::client::BotClient,
218 guest_query_id: impl Into<String>,
219 result: rustigram_types::inline::InlineQueryResult,
220 ) -> Self {
221 Self {
222 client,
223 params: AnswerGuestQueryParams {
224 guest_query_id: guest_query_id.into(),
225 result,
226 },
227 }
228 }
229}
230
231impl std::future::IntoFuture for AnswerGuestQuery {
232 type Output = crate::error::Result<rustigram_types::inline::SentGuestMessage>;
233 type IntoFuture = std::pin::Pin<Box<dyn std::future::Future<Output = Self::Output> + Send>>;
234 fn into_future(self) -> Self::IntoFuture {
235 Box::pin(async move {
236 self.client
237 .post_json("answerGuestQuery", &self.params)
238 .await
239 })
240 }
241}