telegram_bot_raw/requests/
answer_inline_query.rs1use std::ops::Not;
2
3use crate::requests::*;
4use crate::types::*;
5
6#[derive(Serialize, Debug)]
7pub struct AnswerInlineQuery {
8 inline_query_id: InlineQueryId,
9 results: Vec<InlineQueryResult>,
10 #[serde(skip_serializing_if = "Option::is_none")]
11 cache_time: Option<Integer>,
12 #[serde(skip_serializing_if = "Not::not")]
13 is_personal: bool,
14 #[serde(skip_serializing_if = "Option::is_none")]
15 next_offset: Option<String>,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 switch_pm_text: Option<String>,
18 #[serde(skip_serializing_if = "Option::is_none")]
19 switch_pm_parameter: Option<String>,
20}
21
22impl Request for AnswerInlineQuery {
23 type Type = JsonRequestType<Self>;
24 type Response = JsonTrueToUnitResponse;
25
26 fn serialize(&self) -> Result<HttpRequest, Error> {
27 Self::Type::serialize(RequestUrl::method("answerInlineQuery"), self)
28 }
29}
30
31pub trait CanAnswerInlineQuery {
32 fn answer(self, results: Vec<InlineQueryResult>) -> AnswerInlineQuery;
33}
34
35impl<T> CanAnswerInlineQuery for T
36where
37 T: Into<InlineQueryId>,
38{
39 fn answer(self, results: Vec<InlineQueryResult>) -> AnswerInlineQuery {
40 AnswerInlineQuery::new(self.into(), results)
41 }
42}
43
44impl AnswerInlineQuery {
45 pub fn new(
46 inline_query_id: InlineQueryId,
47 results: Vec<InlineQueryResult>,
48 ) -> AnswerInlineQuery {
49 AnswerInlineQuery {
50 inline_query_id,
51 results,
52 cache_time: None,
53 is_personal: false,
54 next_offset: None,
55 switch_pm_text: None,
56 switch_pm_parameter: None,
57 }
58 }
59
60 pub fn add_inline_result<T: Into<InlineQueryResult>>(&mut self, result: T) {
61 self.results.push(result.into());
62 }
63
64 pub fn cache_time(&mut self, cache_time: Integer) -> &mut Self {
65 self.cache_time = Some(cache_time);
66 self
67 }
68
69 pub fn is_personal(&mut self) -> &mut Self {
70 self.is_personal = true;
71 self
72 }
73
74 pub fn next_offset(&mut self, next_offset: String) -> &mut Self {
75 self.next_offset = Some(next_offset);
76 self
77 }
78
79 pub fn switch_pm_text(&mut self, switch_pm_text: String) -> &mut Self {
80 self.switch_pm_text = Some(switch_pm_text);
81 self
82 }
83
84 pub fn switch_pm_parameter(&mut self, switch_pm_parameter: String) -> &mut Self {
85 self.switch_pm_parameter = Some(switch_pm_parameter);
86 self
87 }
88}