conogram/methods/
answer_inline_query.rs

1use std::{
2    future::{Future, IntoFuture},
3    pin::Pin,
4};
5
6use serde::Serialize;
7
8use crate::{
9    api::API,
10    entities::{
11        inline_query_result::InlineQueryResult,
12        inline_query_results_button::InlineQueryResultsButton,
13    },
14    errors::ConogramError,
15    impl_into_future,
16    request::RequestT,
17    utils::deserialize_utils::is_false,
18};
19
20#[derive(Debug, Clone, Serialize)]
21pub struct AnswerInlineQueryParams {
22    pub inline_query_id: String,
23    pub results: Vec<InlineQueryResult>,
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub cache_time: Option<i64>,
26    #[serde(default, skip_serializing_if = "is_false")]
27    pub is_personal: bool,
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub next_offset: Option<String>,
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub button: Option<InlineQueryResultsButton>,
32}
33
34impl_into_future!(AnswerInlineQueryRequest<'a>);
35
36///Use this method to send answers to an inline query. On success, *True* is returned.  
37///No more than **50** results per query are allowed.
38#[derive(Clone)]
39pub struct AnswerInlineQueryRequest<'a> {
40    api: &'a API,
41    params: AnswerInlineQueryParams,
42}
43
44impl<'a> RequestT for AnswerInlineQueryRequest<'a> {
45    type ParamsType = AnswerInlineQueryParams;
46    type ReturnType = bool;
47    fn get_name() -> &'static str {
48        "answerInlineQuery"
49    }
50    fn get_api_ref(&self) -> &API {
51        self.api
52    }
53    fn get_params_ref(&self) -> &Self::ParamsType {
54        &self.params
55    }
56    fn is_multipart() -> bool {
57        false
58    }
59}
60impl<'a> AnswerInlineQueryRequest<'a> {
61    pub fn new(
62        api: &'a API,
63        inline_query_id: impl Into<String>,
64        results: impl IntoIterator<Item = impl Into<InlineQueryResult>>,
65    ) -> Self {
66        Self {
67            api,
68            params: AnswerInlineQueryParams {
69                inline_query_id: inline_query_id.into(),
70                results: results.into_iter().map(Into::into).collect(),
71                cache_time: Option::default(),
72                is_personal: bool::default(),
73                next_offset: Option::default(),
74                button: Option::default(),
75            },
76        }
77    }
78
79    ///Unique identifier for the answered query
80    #[must_use]
81    pub fn inline_query_id(mut self, inline_query_id: impl Into<String>) -> Self {
82        self.params.inline_query_id = inline_query_id.into();
83        self
84    }
85
86    ///A JSON-serialized array of results for the inline query
87    #[must_use]
88    pub fn results(
89        mut self,
90        results: impl IntoIterator<Item = impl Into<InlineQueryResult>>,
91    ) -> Self {
92        self.params.results = results.into_iter().map(Into::into).collect();
93        self
94    }
95
96    ///The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.
97    #[must_use]
98    pub fn cache_time(mut self, cache_time: impl Into<i64>) -> Self {
99        self.params.cache_time = Some(cache_time.into());
100        self
101    }
102
103    ///Pass *True* if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query.
104    #[must_use]
105    pub fn is_personal(mut self, is_personal: impl Into<bool>) -> Self {
106        self.params.is_personal = is_personal.into();
107        self
108    }
109
110    ///Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don't support pagination. Offset length can't exceed 64 bytes.
111    #[must_use]
112    pub fn next_offset(mut self, next_offset: impl Into<String>) -> Self {
113        self.params.next_offset = Some(next_offset.into());
114        self
115    }
116
117    ///A JSON-serialized object describing a button to be shown above inline query results
118    #[must_use]
119    pub fn button(mut self, button: impl Into<InlineQueryResultsButton>) -> Self {
120        self.params.button = Some(button.into());
121        self
122    }
123}
124
125impl API {
126    ///Use this method to send answers to an inline query. On success, *True* is returned.  
127    ///No more than **50** results per query are allowed.
128    pub fn answer_inline_query(
129        &self,
130        inline_query_id: impl Into<String>,
131        results: impl IntoIterator<Item = impl Into<InlineQueryResult>>,
132    ) -> AnswerInlineQueryRequest {
133        AnswerInlineQueryRequest::new(self, inline_query_id, results)
134    }
135}
136
137// Divider: all content below this line will be preserved after code regen