1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use serde::{Deserialize, Serialize};
/// This object represents an incoming callback query from a callback button in an inline keyboard. If the button that originated the query was attached to a message sent by the bot, the field message will be present. If the button was attached to a message sent via the bot (in inline mode), the field `inline_message_id` will be present. Exactly one of the fields data or `game_short_name` will be present.
/// # Documentation
/// <https://core.telegram.org/bots/api#callbackquery>
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CallbackQuery {
/// Unique identifier for this query
pub id: Box<str>,
/// Sender
pub from: Box<crate::types::User>,
/// Message sent by the bot with the callback button that originated the query
#[serde(skip_serializing_if = "Option::is_none")]
pub message: Option<Box<crate::types::MaybeInaccessibleMessage>>,
/// Identifier of the message sent via the bot in inline mode, that originated the query.
#[serde(skip_serializing_if = "Option::is_none")]
pub inline_message_id: Option<Box<str>>,
/// Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.
pub chat_instance: Box<str>,
/// Data associated with the callback button. Be aware that the message originated the query can contain no callback buttons with this data.
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<Box<str>>,
/// Short name of a Game to be returned, serves as the unique identifier for the game
#[serde(skip_serializing_if = "Option::is_none")]
pub game_short_name: Option<Box<str>>,
}
impl CallbackQuery {
/// Creates a new `CallbackQuery`.
///
/// # Arguments
/// * `id` - Unique identifier for this query
/// * `from` - Sender
/// * `chat_instance` - Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.
///
/// # Notes
/// Use builder methods to set optional fields.
#[must_use]
pub fn new<T0: Into<Box<str>>, T1: Into<crate::types::User>, T2: Into<Box<str>>>(
id: T0,
from: T1,
chat_instance: T2,
) -> Self {
Self {
id: id.into(),
from: Box::new(from.into()),
message: None,
inline_message_id: None,
chat_instance: chat_instance.into(),
data: None,
game_short_name: None,
}
}
/// Unique identifier for this query
#[must_use]
pub fn id<T: Into<Box<str>>>(mut self, val: T) -> Self {
self.id = val.into();
self
}
/// Sender
#[must_use]
pub fn from<T: Into<crate::types::User>>(mut self, val: T) -> Self {
self.from = Box::new(val.into());
self
}
/// Message sent by the bot with the callback button that originated the query
#[must_use]
pub fn message<T: Into<crate::types::MaybeInaccessibleMessage>>(mut self, val: T) -> Self {
self.message = Some(Box::new(val.into()));
self
}
/// Message sent by the bot with the callback button that originated the query
#[must_use]
pub fn message_option<T: Into<crate::types::MaybeInaccessibleMessage>>(
mut self,
val: Option<T>,
) -> Self {
self.message = val.map(|val| Box::new(val.into()));
self
}
/// Identifier of the message sent via the bot in inline mode, that originated the query.
#[must_use]
pub fn inline_message_id<T: Into<Box<str>>>(mut self, val: T) -> Self {
self.inline_message_id = Some(val.into());
self
}
/// Identifier of the message sent via the bot in inline mode, that originated the query.
#[must_use]
pub fn inline_message_id_option<T: Into<Box<str>>>(mut self, val: Option<T>) -> Self {
self.inline_message_id = val.map(Into::into);
self
}
/// Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.
#[must_use]
pub fn chat_instance<T: Into<Box<str>>>(mut self, val: T) -> Self {
self.chat_instance = val.into();
self
}
/// Data associated with the callback button. Be aware that the message originated the query can contain no callback buttons with this data.
#[must_use]
pub fn data<T: Into<Box<str>>>(mut self, val: T) -> Self {
self.data = Some(val.into());
self
}
/// Data associated with the callback button. Be aware that the message originated the query can contain no callback buttons with this data.
#[must_use]
pub fn data_option<T: Into<Box<str>>>(mut self, val: Option<T>) -> Self {
self.data = val.map(Into::into);
self
}
/// Short name of a Game to be returned, serves as the unique identifier for the game
#[must_use]
pub fn game_short_name<T: Into<Box<str>>>(mut self, val: T) -> Self {
self.game_short_name = Some(val.into());
self
}
/// Short name of a Game to be returned, serves as the unique identifier for the game
#[must_use]
pub fn game_short_name_option<T: Into<Box<str>>>(mut self, val: Option<T>) -> Self {
self.game_short_name = val.map(Into::into);
self
}
}