Skip to main content

rustigram_api/methods/
inline.rs

1use 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
21/// Builder for the [`answerInlineQuery`](https://core.telegram.org/bots/api#answerinlinequery) method.
22pub 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    /// Sets how many seconds the results may be cached on the client (default 300).
45    pub fn cache_time(mut self, secs: u32) -> Self {
46        self.params.cache_time = Some(secs);
47        self
48    }
49    /// Makes the results personal to the user — disables shared caching.
50    pub fn is_personal(mut self, v: bool) -> Self {
51        self.params.is_personal = Some(v);
52        self
53    }
54    /// Sets the offset for pagination when there are more results available.
55    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}