rtdlib/types/
inline_query_results.rs

1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9/// Represents the results of the inline query. Use sendInlineQueryResultMessage to send the result of the query
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct InlineQueryResults {
12  #[doc(hidden)]
13  #[serde(rename(serialize = "@type", deserialize = "@type"))]
14  td_name: String,
15  #[doc(hidden)]
16  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
17  extra: Option<String>,
18  /// Unique identifier of the inline query
19  inline_query_id: isize,
20  /// The offset for the next request. If empty, there are no more results
21  next_offset: String,
22  /// Results of the query
23  results: Vec<InlineQueryResult>,
24  /// If non-empty, this text must be shown on the button, which opens a private chat with the bot and sends the bot a start message with the switch_pm_parameter
25  switch_pm_text: String,
26  /// Parameter for the bot start message
27  switch_pm_parameter: String,
28  
29}
30
31impl RObject for InlineQueryResults {
32  #[doc(hidden)] fn td_name(&self) -> &'static str { "inlineQueryResults" }
33  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
34  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
35}
36
37
38
39impl InlineQueryResults {
40  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
41  pub fn builder() -> RTDInlineQueryResultsBuilder {
42    let mut inner = InlineQueryResults::default();
43    inner.td_name = "inlineQueryResults".to_string();
44    inner.extra = Some(Uuid::new_v4().to_string());
45    RTDInlineQueryResultsBuilder { inner }
46  }
47
48  pub fn inline_query_id(&self) -> isize { self.inline_query_id }
49
50  pub fn next_offset(&self) -> &String { &self.next_offset }
51
52  pub fn results(&self) -> &Vec<InlineQueryResult> { &self.results }
53
54  pub fn switch_pm_text(&self) -> &String { &self.switch_pm_text }
55
56  pub fn switch_pm_parameter(&self) -> &String { &self.switch_pm_parameter }
57
58}
59
60#[doc(hidden)]
61pub struct RTDInlineQueryResultsBuilder {
62  inner: InlineQueryResults
63}
64
65impl RTDInlineQueryResultsBuilder {
66  pub fn build(&self) -> InlineQueryResults { self.inner.clone() }
67
68   
69  pub fn inline_query_id(&mut self, inline_query_id: isize) -> &mut Self {
70    self.inner.inline_query_id = inline_query_id;
71    self
72  }
73
74   
75  pub fn next_offset<T: AsRef<str>>(&mut self, next_offset: T) -> &mut Self {
76    self.inner.next_offset = next_offset.as_ref().to_string();
77    self
78  }
79
80   
81  pub fn results(&mut self, results: Vec<InlineQueryResult>) -> &mut Self {
82    self.inner.results = results;
83    self
84  }
85
86   
87  pub fn switch_pm_text<T: AsRef<str>>(&mut self, switch_pm_text: T) -> &mut Self {
88    self.inner.switch_pm_text = switch_pm_text.as_ref().to_string();
89    self
90  }
91
92   
93  pub fn switch_pm_parameter<T: AsRef<str>>(&mut self, switch_pm_parameter: T) -> &mut Self {
94    self.inner.switch_pm_parameter = switch_pm_parameter.as_ref().to_string();
95    self
96  }
97
98}
99
100impl AsRef<InlineQueryResults> for InlineQueryResults {
101  fn as_ref(&self) -> &InlineQueryResults { self }
102}
103
104impl AsRef<InlineQueryResults> for RTDInlineQueryResultsBuilder {
105  fn as_ref(&self) -> &InlineQueryResults { &self.inner }
106}
107
108
109