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