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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
use crate::client::Bot;
use serde::Serialize;
/// Sends a gift to the given user or channel chat. The gift can't be converted to Telegram Stars by the receiver. Returns `true` on success.
/// # Documentation
/// <https://core.telegram.org/bots/api#sendgift>
/// # Returns
/// - `bool`
#[derive(Clone, Debug, Serialize)]
pub struct SendGift {
/// Required if `chat_id` is not specified. Unique identifier of the target user who will receive the gift.
#[serde(skip_serializing_if = "Option::is_none")]
pub user_id: Option<i64>,
/// Required if `user_id` is not specified. Unique identifier for the chat or username of the channel (in the format @username) that will receive the gift.
#[serde(skip_serializing_if = "Option::is_none")]
pub chat_id: Option<crate::types::ChatIdKind>,
/// Identifier of the gift; limited gifts can't be sent to channel chats
pub gift_id: Box<str>,
/// Pass `true` to pay for the gift upgrade from the bot's balance, thereby making the upgrade free for the receiver
#[serde(skip_serializing_if = "Option::is_none")]
pub pay_for_upgrade: Option<bool>,
/// Text that will be shown along with the gift; 0-128 characters
#[serde(skip_serializing_if = "Option::is_none")]
pub text: Option<Box<str>>,
/// Mode for parsing entities in the text. See formatting options for more details. Entities other than `bold`, `italic`, `underline`, `strikethrough`, `spoiler`, `custom_emoji`, and `date_time` are ignored.
#[serde(skip_serializing_if = "Option::is_none")]
pub text_parse_mode: Option<Box<str>>,
/// A JSON-serialized list of special entities that appear in the gift text. It can be specified instead of `text_parse_mode`. Entities other than `bold`, `italic`, `underline`, `strikethrough`, `spoiler`, `custom_emoji`, and `date_time` are ignored.
#[serde(skip_serializing_if = "Option::is_none")]
pub text_entities: Option<Box<[crate::types::MessageEntity]>>,
}
impl SendGift {
/// Creates a new `SendGift`.
///
/// # Arguments
/// * `gift_id` - Identifier of the gift; limited gifts can't be sent to channel chats
///
/// # Notes
/// Use builder methods to set optional fields.
#[must_use]
pub fn new<T0: Into<Box<str>>>(gift_id: T0) -> Self {
Self {
user_id: None,
chat_id: None,
gift_id: gift_id.into(),
pay_for_upgrade: None,
text: None,
text_parse_mode: None,
text_entities: None,
}
}
/// Required if `chat_id` is not specified. Unique identifier of the target user who will receive the gift.
#[must_use]
pub fn user_id<T: Into<i64>>(mut self, val: T) -> Self {
self.user_id = Some(val.into());
self
}
/// Required if `chat_id` is not specified. Unique identifier of the target user who will receive the gift.
#[must_use]
pub fn user_id_option<T: Into<i64>>(mut self, val: Option<T>) -> Self {
self.user_id = val.map(Into::into);
self
}
/// Required if `user_id` is not specified. Unique identifier for the chat or username of the channel (in the format @username) that will receive the gift.
#[must_use]
pub fn chat_id<T: Into<crate::types::ChatIdKind>>(mut self, val: T) -> Self {
self.chat_id = Some(val.into());
self
}
/// Required if `user_id` is not specified. Unique identifier for the chat or username of the channel (in the format @username) that will receive the gift.
#[must_use]
pub fn chat_id_option<T: Into<crate::types::ChatIdKind>>(mut self, val: Option<T>) -> Self {
self.chat_id = val.map(Into::into);
self
}
/// Identifier of the gift; limited gifts can't be sent to channel chats
#[must_use]
pub fn gift_id<T: Into<Box<str>>>(mut self, val: T) -> Self {
self.gift_id = val.into();
self
}
/// Pass `true` to pay for the gift upgrade from the bot's balance, thereby making the upgrade free for the receiver
#[must_use]
pub fn pay_for_upgrade<T: Into<bool>>(mut self, val: T) -> Self {
self.pay_for_upgrade = Some(val.into());
self
}
/// Pass `true` to pay for the gift upgrade from the bot's balance, thereby making the upgrade free for the receiver
#[must_use]
pub fn pay_for_upgrade_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.pay_for_upgrade = val.map(Into::into);
self
}
/// Text that will be shown along with the gift; 0-128 characters
#[must_use]
pub fn text<T: Into<Box<str>>>(mut self, val: T) -> Self {
self.text = Some(val.into());
self
}
/// Text that will be shown along with the gift; 0-128 characters
#[must_use]
pub fn text_option<T: Into<Box<str>>>(mut self, val: Option<T>) -> Self {
self.text = val.map(Into::into);
self
}
/// Mode for parsing entities in the text. See formatting options for more details. Entities other than `bold`, `italic`, `underline`, `strikethrough`, `spoiler`, `custom_emoji`, and `date_time` are ignored.
#[must_use]
pub fn text_parse_mode<T: Into<Box<str>>>(mut self, val: T) -> Self {
self.text_parse_mode = Some(val.into());
self
}
/// Mode for parsing entities in the text. See formatting options for more details. Entities other than `bold`, `italic`, `underline`, `strikethrough`, `spoiler`, `custom_emoji`, and `date_time` are ignored.
#[must_use]
pub fn text_parse_mode_option<T: Into<Box<str>>>(mut self, val: Option<T>) -> Self {
self.text_parse_mode = val.map(Into::into);
self
}
/// A JSON-serialized list of special entities that appear in the gift text. It can be specified instead of `text_parse_mode`. Entities other than `bold`, `italic`, `underline`, `strikethrough`, `spoiler`, `custom_emoji`, and `date_time` are ignored.
///
/// # Notes
/// Adds multiple elements.
#[must_use]
pub fn text_entities<
TItem: Into<crate::types::MessageEntity>,
T: IntoIterator<Item = TItem>,
>(
mut self,
val: T,
) -> Self {
self.text_entities = Some(
self.text_entities
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(val.into_iter().map(Into::into))
.collect(),
);
self
}
/// A JSON-serialized list of special entities that appear in the gift text. It can be specified instead of `text_parse_mode`. Entities other than `bold`, `italic`, `underline`, `strikethrough`, `spoiler`, `custom_emoji`, and `date_time` are ignored.
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn text_entity<T: Into<crate::types::MessageEntity>>(mut self, val: T) -> Self {
self.text_entities = Some(
self.text_entities
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(Some(val.into()))
.collect(),
);
self
}
/// A JSON-serialized list of special entities that appear in the gift text. It can be specified instead of `text_parse_mode`. Entities other than `bold`, `italic`, `underline`, `strikethrough`, `spoiler`, `custom_emoji`, and `date_time` are ignored.
///
/// # Notes
/// Adds multiple elements.
#[must_use]
pub fn text_entities_option<
TItem: Into<crate::types::MessageEntity>,
T: IntoIterator<Item = TItem>,
>(
mut self,
val: Option<T>,
) -> Self {
self.text_entities = val.map(|v| v.into_iter().map(Into::into).collect());
self
}
}
impl super::TelegramMethod for SendGift {
type Method = Self;
type Return = bool;
fn build_request<Client>(self, _bot: &Bot<Client>) -> super::Request<Self::Method> {
super::Request::new("sendGift", self, None)
}
}