Merge branch 'dev' into useful_functions

This commit is contained in:
Temirkhan Myrzamadi 2020-02-03 17:14:59 +06:00 committed by GitHub
commit 0077b99ef6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
85 changed files with 2745 additions and 2058 deletions

124
CODE_STYLE.md Normal file
View file

@ -0,0 +1,124 @@
# Code style
This is a description of a coding style that every contributor must follow. Please, read the whole document before you start pushing code.
## Generics
Generics are always written with `where`.
Bad:
```rust
pub fn new<N: Into<String>,
T: Into<String>,
P: Into<InputFile>,
E: Into<String>>
(user_id: i32, name: N, title: T, png_sticker: P, emojis: E) -> Self { ... }
```
Good:
```rust
pub fn new<N, T, P, E>(user_id: i32, name: N, title: T, png_sticker: P, emojis: E) -> Self
where
N: Into<String>,
T: Into<String>,
P: Into<InputFile>,
E: Into<String> { ... }
```
## Comments
1. Comments must describe what your code does and mustn't describe how your code does it and bla-bla-bla. Be sure that your comments follow the grammar, including punctuation, the first capital letter and so on.
Bad:
```rust
/// this function make request to telegram
pub fn make_request(url: &str) -> String { ... }
```
Good:
```rust
/// This function makes a request to Telegram.
pub fn make_request(url: &str) -> String { ... }
```
2. Also, link resources in your comments when possible:
```rust
/// Download a file from Telegram.
///
/// `path` can be obtained from the [`Bot::get_file`].
///
/// To download into [`AsyncWrite`] (e.g. [`tokio::fs::File`]), see
/// [`Bot::download_file`].
///
/// [`Bot::get_file`]: crate::bot::Bot::get_file
/// [`AsyncWrite`]: tokio::io::AsyncWrite
/// [`tokio::fs::File`]: tokio::fs::File
/// [`Bot::download_file`]: crate::Bot::download_file
#[cfg(feature = "unstable-stream")]
pub async fn download_file_stream(
&self,
path: &str,
) -> Result<impl Stream<Item = Result<Bytes, reqwest::Error>>, reqwest::Error>
{
download_file_stream(&self.client, &self.token, path).await
}
```
## Use Self where possible
Bad:
```rust
impl ErrorKind {
fn print(&self) {
ErrorKind::Io => println!("Io"),
ErrorKind::Network => println!("Network"),
ErrorKind::Json => println!("Json"),
}
}
```
Good:
```rust
impl ErrorKind {
fn print(&self) {
Self::Io => println!("Io"),
Self::Network => println!("Network"),
Self::Json => println!("Json"),
}
}
```
<details>
<summary>More examples</summary>
Bad:
```rust
impl<'a> AnswerCallbackQuery<'a> {
pub(crate) fn new<C>(bot: &'a Bot, callback_query_id: C) -> AnswerCallbackQuery<'a>
where
C: Into<String>, { ... }
```
Good:
```rust
impl<'a> AnswerCallbackQuery<'a> {
pub(crate) fn new<C>(bot: &'a Bot, callback_query_id: C) -> Self
where
C: Into<String>, { ... }
```
</details>
## Naming
1. Avoid unnecessary duplication (`Message::message_id` -> `Message::id` using `#[serde(rename = "message_id")]`).
2. Use a generic parameter name `S` for streams, `Fut` for futures, `F` for functions (where possible).
## Deriving
1. Derive `Copy`, `Eq`, `Hash`, `PartialEq`, `Clone`, `Debug` for public types when possible (note: if the default `Debug` implementation is weird, you should manually implement it by yourself).
2. Derive `Default` when there is an algorithm to get a default value for your type.
## Misc
1. Use `Into<...>` only where there exists at least one conversion **and** it will be logically to use.

View file

@ -12,16 +12,18 @@ serde = { version = "1.0.101", features = ["derive"] }
tokio = { version = "0.2.6", features = ["full"] } tokio = { version = "0.2.6", features = ["full"] }
tokio-util = { version = "0.2.0", features = ["full"] } tokio-util = { version = "0.2.0", features = ["full"] }
reqwest = { version = "0.10", features = ["json", "stream"] } reqwest = { version = "0.10", features = ["json", "stream", "native-tls-vendored"] }
log = "0.4.8" log = "0.4.8"
bytes = "0.5.3" bytes = "0.5.3"
mime = "0.3.16"
derive_more = "0.99.2" derive_more = "0.99.2"
thiserror = "1.0.9" thiserror = "1.0.9"
async-trait = "0.1.22" async-trait = "0.1.22"
duang = "0.1.2"
futures = "0.3.1" futures = "0.3.1"
pin-project = "0.4.6" pin-project = "0.4.6"
serde_with_macros = "1.0.1" serde_with_macros = "1.0.1"
either = "1.5.3" either = "1.5.3"
mime = "0.3.16"
teloxide-macros = { path = "teloxide-macros" } teloxide-macros = { path = "teloxide-macros" }

34
examples/ping_pong_bot.rs Normal file
View file

@ -0,0 +1,34 @@
use futures::stream::StreamExt;
use teloxide::{
dispatching::{
chat::{ChatUpdate, ChatUpdateKind, Dispatcher},
update_listeners::polling_default,
SessionState,
},
requests::Request,
Bot,
};
#[tokio::main]
async fn main() {
let bot = &Bot::new("1061598315:AAErEDodTsrqD3UxA_EvFyEfXbKA6DT25G0");
let mut updater = Box::pin(polling_default(bot));
let handler = |_, upd: ChatUpdate| async move {
if let ChatUpdateKind::Message(m) = upd.kind {
let msg = bot.send_message(m.chat.id, "pong");
msg.send().await.unwrap();
}
SessionState::Continue(())
};
let mut dp = Dispatcher::<'_, (), _>::new(handler);
println!("Starting the message handler.");
loop {
let u = updater.next().await.unwrap();
match u {
Err(e) => eprintln!("Error: {}", e),
Ok(u) => {
let _ = dp.dispatch(u).await;
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -4,14 +4,15 @@ use tokio::io::AsyncWrite;
use ::{bytes::Bytes, tokio::stream::Stream}; use ::{bytes::Bytes, tokio::stream::Stream};
#[cfg(feature = "unstable-stream")] #[cfg(feature = "unstable-stream")]
use crate::network::download_file_stream; use crate::net::download_file_stream;
use crate::{bot::Bot, network::download_file, DownloadError}; use crate::{bot::Bot, net::download_file, DownloadError};
impl Bot { impl Bot {
/// Download a file from Telegram into `destination`. /// Download a file from Telegram into `destination`.
/// `path` can be obtained from [`get_file`] method.
/// ///
/// For downloading as Stream of Chunks see [`download_file_stream`]. /// `path` can be obtained from [`Bot::get_file`].
///
/// To download as a stream of chunks, see [`Bot::download_file_stream`].
/// ///
/// ## Examples /// ## Examples
/// ///
@ -30,8 +31,8 @@ impl Bot {
/// # Ok(()) } /// # Ok(()) }
/// ``` /// ```
/// ///
/// [`get_file`]: crate::Bot::get_file /// [`Bot::get_file`]: crate::Bot::get_file
/// [`download_file_stream`]: crate::Bot::download_file_stream /// [`Bot::download_file_stream`]: crate::Bot::download_file_stream
pub async fn download_file<D>( pub async fn download_file<D>(
&self, &self,
path: &str, path: &str,
@ -45,15 +46,15 @@ impl Bot {
/// Download a file from Telegram. /// Download a file from Telegram.
/// ///
/// `path` can be obtained from the [`get_file`] method. /// `path` can be obtained from the [`Bot::get_file`].
/// ///
/// For downloading into [`AsyncWrite`] (e.g. [`tokio::fs::File`]) /// To download into [`AsyncWrite`] (e.g. [`tokio::fs::File`]), see
/// see [`download_file`]. /// [`Bot::download_file`].
/// ///
/// [`get_file`]: crate::bot::Bot::get_file /// [`Bot::get_file`]: crate::bot::Bot::get_file
/// [`AsyncWrite`]: tokio::io::AsyncWrite /// [`AsyncWrite`]: tokio::io::AsyncWrite
/// [`tokio::fs::File`]: tokio::fs::File /// [`tokio::fs::File`]: tokio::fs::File
/// [`download_file`]: crate::Bot::download_file /// [`Bot::download_file`]: crate::Bot::download_file
#[cfg(feature = "unstable-stream")] #[cfg(feature = "unstable-stream")]
pub async fn download_file_stream( pub async fn download_file_stream(
&self, &self,

View file

@ -1,110 +0,0 @@
use crate::{dispatching::Filter, types::Message};
pub struct CommandFilter {
command: String,
}
impl Filter<Message> for CommandFilter {
fn test(&self, value: &Message) -> bool {
match value.text() {
Some(text) => match text.split_whitespace().next() {
Some(command) => self.command == command,
None => false,
},
None => false,
}
}
}
impl CommandFilter {
pub fn new<T>(command: T) -> Self
where
T: Into<String>,
{
Self {
command: '/'.to_string() + &command.into(),
}
}
pub fn with_prefix<T>(command: T, prefix: T) -> Self
where
T: Into<String>,
{
Self {
command: prefix.into() + &command.into(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::types::{
Chat, ChatKind, ForwardKind, MediaKind, MessageKind, Sender, User,
};
#[test]
fn commands_are_equal() {
let filter = CommandFilter::new("command".to_string());
let message = create_message_with_text("/command".to_string());
assert!(filter.test(&message));
}
#[test]
fn commands_are_not_equal() {
let filter = CommandFilter::new("command".to_string());
let message =
create_message_with_text("/not_equal_command".to_string());
assert_eq!(filter.test(&message), false);
}
#[test]
fn command_have_args() {
let filter = CommandFilter::new("command".to_string());
let message =
create_message_with_text("/command arg1 arg2".to_string());
assert!(filter.test(&message));
}
#[test]
fn message_have_only_whitespace() {
let filter = CommandFilter::new("command".to_string());
let message = create_message_with_text(" ".to_string());
assert_eq!(filter.test(&message), false);
}
fn create_message_with_text(text: String) -> Message {
Message {
id: 0,
date: 0,
chat: Chat {
id: 0,
kind: ChatKind::Private {
type_: (),
username: None,
first_name: None,
last_name: None,
},
photo: None,
},
kind: MessageKind::Common {
from: Sender::User(User {
id: 0,
is_bot: false,
first_name: "".to_string(),
last_name: None,
username: None,
language_code: None,
}),
forward_kind: ForwardKind::Origin {
reply_to_message: None,
},
edit_date: None,
media_kind: MediaKind::Text {
text,
entities: vec![],
},
reply_markup: None,
},
}
}
}

View file

@ -1,379 +0,0 @@
/// Filter that determines that particular event
/// is suitable for particular handler.
pub trait Filter<T> {
/// Passes (return true) if event is suitable (otherwise return false)
fn test(&self, value: &T) -> bool;
}
/// ```
/// use teloxide::dispatching::filters::Filter;
///
/// let closure = |i: &i32| -> bool { *i >= 42 };
/// assert!(closure.test(&42));
/// assert!(closure.test(&100));
///
/// assert_eq!(closure.test(&41), false);
/// assert_eq!(closure.test(&0), false);
/// ```
impl<T, F: Fn(&T) -> bool> Filter<T> for F {
fn test(&self, value: &T) -> bool {
(self)(value)
}
}
/// ```
/// use teloxide::dispatching::filters::Filter;
///
/// assert!(true.test(&()));
/// assert_eq!(false.test(&()), false);
/// ```
impl<T> Filter<T> for bool {
fn test(&self, _: &T) -> bool {
*self
}
}
/// And filter.
///
/// Passes if both underlying filters pass.
///
/// **NOTE**: if one of filters don't pass
/// it is **not** guaranteed that other will be executed.
///
/// ## Examples
/// ```
/// use teloxide::dispatching::filters::{And, Filter};
///
/// // Note: bool can be treated as `Filter` that always return self.
/// assert_eq!(And::new(true, false).test(&()), false);
/// assert_eq!(And::new(true, false).test(&()), false);
/// assert!(And::new(true, true).test(&()));
/// assert!(And::new(true, And::new(|_: &()| true, true)).test(&()));
/// ```
#[derive(Debug, Clone, Copy)]
pub struct And<A, B>(A, B);
impl<A, B> And<A, B> {
pub fn new(a: A, b: B) -> Self {
And(a, b)
}
}
impl<T, A, B> Filter<T> for And<A, B>
where
A: Filter<T>,
B: Filter<T>,
{
fn test(&self, value: &T) -> bool {
self.0.test(value) && self.1.test(value)
}
}
/// Alias for [`And::new`]
///
/// ## Examples
/// ```
/// use teloxide::dispatching::filters::{and, Filter};
///
/// assert!(and(true, true).test(&()));
/// assert_eq!(and(true, false).test(&()), false);
/// ```
///
/// [`And::new`]: crate::dispatching::filters::And::new
pub fn and<A, B>(a: A, b: B) -> And<A, B> {
And::new(a, b)
}
/// Or filter.
///
/// Passes if at least one underlying filters passes.
///
/// **NOTE**: if one of filters passes
/// it is **not** guaranteed that other will be executed.
///
/// ## Examples
/// ```
/// use teloxide::dispatching::filters::{Filter, Or};
///
/// // Note: bool can be treated as `Filter` that always return self.
/// assert!(Or::new(true, false).test(&()));
/// assert!(Or::new(false, true).test(&()));
/// assert!(Or::new(false, Or::new(|_: &()| true, false)).test(&()));
/// assert_eq!(Or::new(false, false).test(&()), false);
/// ```
#[derive(Debug, Clone, Copy)]
pub struct Or<A, B>(A, B);
impl<A, B> Or<A, B> {
pub fn new(a: A, b: B) -> Self {
Or(a, b)
}
}
impl<T, A, B> Filter<T> for Or<A, B>
where
A: Filter<T>,
B: Filter<T>,
{
fn test(&self, value: &T) -> bool {
self.0.test(value) || self.1.test(value)
}
}
/// Alias for [`Or::new`]
///
/// ## Examples
/// ```
/// use teloxide::dispatching::filters::{or, Filter};
///
/// assert!(or(true, false).test(&()));
/// assert_eq!(or(false, false).test(&()), false);
/// ```
///
/// [`Or::new`]: crate::dispatching::filters::Or::new
pub fn or<A, B>(a: A, b: B) -> Or<A, B> {
Or::new(a, b)
}
/// Not filter.
///
/// Passes if underlying filter don't pass.
///
/// ## Examples
/// ```
/// use teloxide::dispatching::filters::{Filter, Not};
///
/// // Note: bool can be treated as `Filter` that always return self.
/// assert!(Not::new(false).test(&()));
/// assert_eq!(Not::new(true).test(&()), false);
/// ```
#[derive(Debug, Clone, Copy)]
pub struct Not<A>(A);
impl<A> Not<A> {
pub fn new(a: A) -> Self {
Not(a)
}
}
impl<T, A> Filter<T> for Not<A>
where
A: Filter<T>,
{
fn test(&self, value: &T) -> bool {
!self.0.test(value)
}
}
/// Alias for [`Not::new`]
///
/// ## Examples
/// ```
/// use teloxide::dispatching::filters::{not, Filter};
///
/// assert!(not(false).test(&()));
/// assert_eq!(not(true).test(&()), false);
/// ```
///
/// [`Not::new`]: crate::dispatching::filters::Not::new
pub fn not<A>(a: A) -> Not<A> {
Not::new(a)
}
/// Return [filter] that passes if and only if all of the given filters passes.
///
/// **NOTE**: if one of filters don't pass
/// it is **not** guaranteed that other will be executed.
///
/// ## Examples
/// ```
/// use teloxide::{all, dispatching::filters::Filter};
///
/// assert!(all![true].test(&()));
/// assert!(all![true, true].test(&()));
/// assert!(all![true, true, true].test(&()));
///
/// assert_eq!(all![false].test(&()), false);
/// assert_eq!(all![true, false].test(&()), false);
/// assert_eq!(all![false, true].test(&()), false);
/// assert_eq!(all![false, false].test(&()), false);
/// ```
///
/// [filter]: crate::dispatching::filters::Filter
#[macro_export]
macro_rules! all {
($one:expr) => { $one };
($head:expr, $($tail:tt)+) => {
$crate::dispatching::filters::And::new(
$head,
$crate::all!($($tail)+)
)
};
}
/// Return [filter] that passes if any of the given filters passes.
///
/// **NOTE**: if one of filters passes
/// it is **not** guaranteed that other will be executed.
///
/// ## Examples
/// ```
/// use teloxide::{any, dispatching::filters::Filter};
///
/// assert!(any![true].test(&()));
/// assert!(any![true, true].test(&()));
/// assert!(any![false, true].test(&()));
/// assert!(any![true, false, true].test(&()));
///
/// assert_eq!(any![false].test(&()), false);
/// assert_eq!(any![false, false].test(&()), false);
/// assert_eq!(any![false, false, false].test(&()), false);
/// ```
///
/// [filter]: crate::dispatching::filters::Filter
#[macro_export]
macro_rules! any {
($one:expr) => { $one };
($head:expr, $($tail:tt)+) => {
$crate::dispatching::filters::Or::new(
$head,
$crate::all!($($tail)+)
)
};
}
/// Simple wrapper around `Filter` that adds `|` and `&` operators.
///
/// ## Examples
/// ```
/// use teloxide::dispatching::filters::{f, And, Filter, Or, F};
///
/// let flt1 = |i: &i32| -> bool { *i > 17 };
/// let flt2 = |i: &i32| -> bool { *i < 42 };
/// let flt3 = |i: &i32| -> bool { *i % 2 == 0 };
///
/// let and = f(flt1) & flt2;
/// assert!(and.test(&19)); // both filters pass
///
/// assert_eq!(and.test(&50), false); // `flt2` doesn't pass
/// assert_eq!(and.test(&16), false); // `flt1` doesn't pass
///
/// let or = f(flt1) | flt3;
/// assert!(or.test(&19)); // `flt1` passes
/// assert!(or.test(&16)); // `flt2` passes
/// assert!(or.test(&20)); // both pass
///
/// assert_eq!(or.test(&17), false); // both don't pass
///
/// // Note: only first filter in chain should be wrapped in `f(...)`
/// let complicated: F<Or<And<_, _>, _>> = f(flt1) & flt2 | flt3;
/// assert!(complicated.test(&2)); // `flt3` passes
/// assert!(complicated.test(&21)); // `flt1` and `flt2` pass
///
/// assert_eq!(complicated.test(&15), false); // `flt1` and `flt3` don't pass
/// assert_eq!(complicated.test(&43), false); // `flt2` and `flt3` don't pass
/// ```
pub struct F<A>(A);
/// Constructor fn for [F]
///
/// [F]: crate::dispatching::filters::F;
pub fn f<A>(a: A) -> F<A> {
F(a)
}
impl<T, A> Filter<T> for F<A>
where
A: Filter<T>,
{
fn test(&self, value: &T) -> bool {
self.0.test(value)
}
}
impl<A, B> std::ops::BitAnd<B> for F<A> {
type Output = F<And<A, B>>;
fn bitand(self, other: B) -> Self::Output {
f(and(self.0, other))
}
}
impl<A, B> std::ops::BitOr<B> for F<A> {
type Output = F<Or<A, B>>;
fn bitor(self, other: B) -> Self::Output {
f(or(self.0, other))
}
}
/* workaround for `E0207` compiler error */
/// Extensions for filters
pub trait FilterExt<T> {
/// Alias for [`Not::new`]
///
/// ## Examples
/// ```
/// use teloxide::dispatching::filters::{Filter, FilterExt};
///
/// let flt = |i: &i32| -> bool { *i > 0 };
/// let flt = flt.not();
/// assert!(flt.test(&-1));
/// assert_eq!(flt.test(&1), false);
/// ```
///
/// [`Not::new`]: crate::dispatching::filters::Not::new
fn not(self) -> Not<Self>
where
Self: Sized,
{
Not::new(self)
}
/// Alias for [`And::new`]
///
/// ## Examples
/// ```
/// use teloxide::dispatching::filters::{Filter, FilterExt};
///
/// let flt = |i: &i32| -> bool { *i > 0 };
/// let flt = flt.and(|i: &i32| *i < 42);
///
/// assert!(flt.test(&1));
/// assert_eq!(flt.test(&-1), false);
/// assert_eq!(flt.test(&43), false);
/// ```
///
/// [`Not::new`]: crate::dispatching::filters::And::new
fn and<B>(self, other: B) -> And<Self, B>
where
Self: Sized,
{
And::new(self, other)
}
/// Alias for [`Or::new`]
///
/// ## Examples
/// ```
/// use teloxide::dispatching::filters::{Filter, FilterExt};
///
/// let flt = |i: &i32| -> bool { *i < 0 };
/// let flt = flt.or(|i: &i32| *i > 42);
///
/// assert!(flt.test(&-1));
/// assert!(flt.test(&43));
/// assert_eq!(flt.test(&17), false);
/// ```
///
/// [`Not::new`]: crate::dispatching::filters::Or::new
fn or<B>(self, other: B) -> Or<Self, B>
where
Self: Sized,
{
Or::new(self, other)
}
}
// All methods implemented via defaults
impl<T, F> FilterExt<T> for F where F: Filter<T> {}

View file

@ -1,100 +0,0 @@
use crate::{dispatching::Filter, types::Message};
/// Filter which compare caption of media with another text.
/// Returns true if the caption of media is equal to another text, otherwise
/// false.
///
/// NOTE: filter compares only caption of media, does not compare text of
/// message!
///
/// If you want to compare text of message use
/// [MessageTextFilter]
///
/// If you want to compare text and caption use
/// [MessageTextCaptionFilter]
///
/// [MessageTextFilter]: crate::dispatching::filters::MessageTextFilter
/// [MessageTextCaptionFilter]:
/// crate::dispatching::filters::MessageTextCaptionFilter
pub struct MessageCaptionFilter {
text: String,
}
impl Filter<Message> for MessageCaptionFilter {
fn test(&self, value: &Message) -> bool {
match value.caption() {
Some(caption) => self.text == caption,
None => false,
}
}
}
impl MessageCaptionFilter {
pub fn new<T>(text: T) -> Self
where
T: Into<String>,
{
Self { text: text.into() }
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::types::{
Chat, ChatKind, ForwardKind, MediaKind, MessageKind, Sender, User,
};
#[test]
fn captions_are_equal() {
let filter = MessageCaptionFilter::new("caption".to_string());
let message = create_message_with_caption("caption".to_string());
assert!(filter.test(&message));
}
#[test]
fn captions_are_not_equal() {
let filter = MessageCaptionFilter::new("caption".to_string());
let message =
create_message_with_caption("not equal caption".to_string());
assert_eq!(filter.test(&message), false);
}
fn create_message_with_caption(caption: String) -> Message {
Message {
id: 0,
date: 0,
chat: Chat {
id: 0,
kind: ChatKind::Private {
type_: (),
username: None,
first_name: None,
last_name: None,
},
photo: None,
},
kind: MessageKind::Common {
from: Sender::User(User {
id: 0,
is_bot: false,
first_name: "".to_string(),
last_name: None,
username: None,
language_code: None,
}),
forward_kind: ForwardKind::Origin {
reply_to_message: None,
},
edit_date: None,
media_kind: MediaKind::Photo {
photo: vec![],
caption: Some(caption),
caption_entities: vec![],
media_group_id: None,
},
reply_markup: None,
},
}
}
}

View file

@ -1,95 +0,0 @@
use crate::{dispatching::Filter, types::Message};
/// Filter which compare message text with another text.
/// Returns true if the message text is equal to another text, otherwise false.
///
/// NOTE: filter compares only text message, does not compare caption of media!
///
/// If you want to compare caption use
/// [MessageCaptionFilter]
///
/// If you want to compare text and caption use
/// [MessageTextCaptionFilter]
///
/// [MessageCaptionFilter]: crate::dispatching::filters::MessageCaptionFilter
/// [MessageTextCaptionFilter]:
/// crate::dispatching::filters::MessageTextCaptionFilter
pub struct MessageTextFilter {
text: String,
}
impl Filter<Message> for MessageTextFilter {
fn test(&self, value: &Message) -> bool {
match value.text() {
Some(text) => self.text == text,
None => false,
}
}
}
impl MessageTextFilter {
pub fn new<T>(text: T) -> Self
where
T: Into<String>,
{
Self { text: text.into() }
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::types::{
Chat, ChatKind, ForwardKind, MediaKind, MessageKind, Sender, User,
};
#[test]
fn texts_are_equal() {
let filter = MessageTextFilter::new("text");
let message = create_message_with_text("text".to_string());
assert!(filter.test(&message));
}
#[test]
fn texts_are_not_equal() {
let filter = MessageTextFilter::new("text");
let message = create_message_with_text("not equal text".to_string());
assert_eq!(filter.test(&message), false);
}
fn create_message_with_text(text: String) -> Message {
Message {
id: 0,
date: 0,
chat: Chat {
id: 0,
kind: ChatKind::Private {
type_: (),
username: None,
first_name: None,
last_name: None,
},
photo: None,
},
kind: MessageKind::Common {
from: Sender::User(User {
id: 0,
is_bot: false,
first_name: "".to_string(),
last_name: None,
username: None,
language_code: None,
}),
forward_kind: ForwardKind::Origin {
reply_to_message: None,
},
edit_date: None,
media_kind: MediaKind::Text {
text,
entities: vec![],
},
reply_markup: None,
},
}
}
}

View file

@ -1,152 +0,0 @@
use crate::{dispatching::Filter, types::Message};
/// Filter which compare message text or caption of media with another text.
/// Returns true if the message text or caption of media is equal to another
/// text, otherwise false.
///
/// NOTE: filter compares text of message or if it is not exists, compares
/// caption of the message!
///
/// If you want to compare only caption use
/// [MessageCaptionFilter]
///
/// If you want to compare only text use
/// [MessageTextFilter]
///
/// [MessageCaptionFilter]: crate::dispatching::filters::MessageCaptionFilter
/// [MessageTextFilter]: crate::dispatching::filters::MessageTextFilter
pub struct MessageTextCaptionFilter {
text: String,
}
impl Filter<Message> for MessageTextCaptionFilter {
fn test(&self, value: &Message) -> bool {
match value.text() {
Some(text) => self.text == text,
None => match value.caption() {
Some(caption) => self.text == caption,
None => false,
},
}
}
}
impl MessageTextCaptionFilter {
pub fn new<T>(text: T) -> Self
where
T: Into<String>,
{
Self { text: text.into() }
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::types::{
Chat, ChatKind, ForwardKind, MediaKind, MessageKind, Sender, User,
};
#[test]
fn texts_are_equal() {
let filter = MessageTextCaptionFilter::new("text");
let message = create_message_with_text("text".to_string());
assert!(filter.test(&message));
}
#[test]
fn texts_are_not_equal() {
let filter = MessageTextCaptionFilter::new("text");
let message = create_message_with_text("not equal text".to_string());
assert_eq!(filter.test(&message), false);
}
fn create_message_with_text(text: String) -> Message {
Message {
id: 0,
date: 0,
chat: Chat {
id: 0,
kind: ChatKind::Private {
type_: (),
username: None,
first_name: None,
last_name: None,
},
photo: None,
},
kind: MessageKind::Common {
from: Sender::User(User {
id: 0,
is_bot: false,
first_name: "".to_string(),
last_name: None,
username: None,
language_code: None,
}),
forward_kind: ForwardKind::Origin {
reply_to_message: None,
},
edit_date: None,
media_kind: MediaKind::Text {
text,
entities: vec![],
},
reply_markup: None,
},
}
}
#[test]
fn captions_are_equal() {
let filter = MessageTextCaptionFilter::new("caption".to_string());
let message = create_message_with_caption("caption".to_string());
assert!(filter.test(&message));
}
#[test]
fn captions_are_not_equal() {
let filter = MessageTextCaptionFilter::new("caption".to_string());
let message =
create_message_with_caption("not equal caption".to_string());
assert_eq!(filter.test(&message), false);
}
fn create_message_with_caption(caption: String) -> Message {
Message {
id: 0,
date: 0,
chat: Chat {
id: 0,
kind: ChatKind::Private {
type_: (),
username: None,
first_name: None,
last_name: None,
},
photo: None,
},
kind: MessageKind::Common {
from: Sender::User(User {
id: 0,
is_bot: false,
first_name: "".to_string(),
last_name: None,
username: None,
language_code: None,
}),
forward_kind: ForwardKind::Origin {
reply_to_message: None,
},
edit_date: None,
media_kind: MediaKind::Photo {
photo: vec![],
caption: Some(caption),
caption_entities: vec![],
media_group_id: None,
},
reply_markup: None,
},
}
}
}

View file

@ -1,15 +0,0 @@
//! Filters of messages.
pub use main::*;
pub use command::*;
pub use message_caption::*;
pub use message_text::*;
pub use message_text_caption::*;
mod main;
mod command;
mod message_caption;
mod message_text;
mod message_text_caption;

View file

@ -8,9 +8,7 @@ pub enum DispatchResult {
} }
pub mod chat; pub mod chat;
pub mod filters;
mod handler; mod handler;
pub mod update_listeners; pub mod update_listeners;
pub use filters::Filter;
pub use handler::*; pub use handler::*;

View file

@ -8,7 +8,7 @@ pub use bot::Bot;
pub use errors::{ApiErrorKind, DownloadError, RequestError}; pub use errors::{ApiErrorKind, DownloadError, RequestError};
mod errors; mod errors;
mod network; mod net;
mod bot; mod bot;
pub mod dispatching; pub mod dispatching;

View file

@ -1,33 +1,23 @@
use crate::{ use crate::{
network, net,
requests::form_builder::FormBuilder, requests::form_builder::FormBuilder,
types::{InputFile, MaskPosition, True}, types::{InputFile, MaskPosition, True},
Bot, Bot,
}; };
use super::BotWrapper;
use crate::requests::{Request, ResponseResult}; use crate::requests::{Request, ResponseResult};
/// Use this method to add a new sticker to a set created by the bot. Returns /// Use this method to add a new sticker to a set created by the bot.
/// True on success. ///
#[derive(Debug, Clone)] /// [The official docs](https://core.telegram.org/bots/api#addstickertoset).
#[derive(PartialEq, Debug, Clone)]
pub struct AddStickerToSet<'a> { pub struct AddStickerToSet<'a> {
bot: &'a Bot, bot: BotWrapper<'a>,
/// User identifier of sticker set owner
user_id: i32, user_id: i32,
/// Sticker set name
name: String, name: String,
/// Png image with the sticker, must be up to 512 kilobytes in size,
/// dimensions must not exceed 512px, and either width or height must be
/// exactly 512px. Pass a file_id as a String to send a file that already
/// exists on the Telegram servers, pass an HTTP URL as a String for
/// Telegram to get a file from the Internet, or upload a new one using
/// multipart/form-data. More info on Sending Files »
png_sticker: InputFile, png_sticker: InputFile,
/// One or more emoji corresponding to the sticker
emojis: String, emojis: String,
/// A JSON-serialized object for position where the mask should be placed
/// on faces
mask_position: Option<MaskPosition>, mask_position: Option<MaskPosition>,
} }
@ -36,7 +26,7 @@ impl Request for AddStickerToSet<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_multipart( net::request_multipart(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"addStickerToSet", "addStickerToSet",
@ -70,7 +60,7 @@ impl<'a> AddStickerToSet<'a> {
E: Into<String>, E: Into<String>,
{ {
Self { Self {
bot, bot: BotWrapper(bot),
user_id, user_id,
name: name.into(), name: name.into(),
png_sticker, png_sticker,
@ -79,11 +69,13 @@ impl<'a> AddStickerToSet<'a> {
} }
} }
/// User identifier of sticker set owner.
pub fn user_id(mut self, val: i32) -> Self { pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val; self.user_id = val;
self self
} }
/// Sticker set name.
pub fn name<T>(mut self, val: T) -> Self pub fn name<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -92,11 +84,24 @@ impl<'a> AddStickerToSet<'a> {
self self
} }
/// **Png** image with the sticker, must be up to 512 kilobytes in size,
/// dimensions must not exceed 512px, and either width or height must be
/// exactly 512px.
///
/// Pass [`InputFile::File`] to send a file that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
pub fn png_sticker(mut self, val: InputFile) -> Self { pub fn png_sticker(mut self, val: InputFile) -> Self {
self.png_sticker = val; self.png_sticker = val;
self self
} }
/// One or more emoji corresponding to the sticker.
pub fn emojis<T>(mut self, val: T) -> Self pub fn emojis<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -105,6 +110,8 @@ impl<'a> AddStickerToSet<'a> {
self self
} }
/// A JSON-serialized object for position where the mask should be placed on
/// faces.
pub fn mask_position(mut self, val: MaskPosition) -> Self { pub fn mask_position(mut self, val: MaskPosition) -> Self {
self.mask_position = Some(val); self.mask_position = Some(val);
self self

View file

@ -1,42 +1,31 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::True, types::True,
Bot, Bot,
}; };
/// Use this method to send answers to callback queries sent from inline /// Use this method to send answers to callback queries sent from [inline
/// keyboards. The answer will be displayed to the user as a notification at the /// keyboards].
/// top of the chat screen or as an alert. On success, True is ///
/// returned.Alternatively, the user can be redirected to the specified Game /// The answer will be displayed to the user as a notification at
/// URL. For this option to work, you must first create a game for your bot via /// the top of the chat screen or as an alert.
/// @Botfather and accept the terms. Otherwise, you may use links like ///
/// t.me/your_bot?start=XXXX that open your bot with a parameter. /// [The official docs](https://core.telegram.org/bots/api#answercallbackquery).
///
/// [inline keyboards]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct AnswerCallbackQuery<'a> { pub struct AnswerCallbackQuery<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the query to be answered
callback_query_id: String, callback_query_id: String,
/// Text of the notification. If not specified, nothing will be shown to
/// the user, 0-200 characters
text: Option<String>, text: Option<String>,
/// If true, an alert will be shown by the client instead of a notification
/// at the top of the chat screen. Defaults to false.
show_alert: Option<bool>, show_alert: Option<bool>,
/// URL that will be opened by the user's client. If you have created a
/// Game and accepted the conditions via @Botfather, specify the URL that
/// opens your game note that this will only work if the query comes from
/// a callback_game button.Otherwise, you may use links like
/// t.me/your_bot?start=XXXX that open your bot with a parameter.
url: Option<String>, url: Option<String>,
/// The maximum amount of time in seconds that the result of the callback
/// query may be cached client-side. Telegram apps will support caching
/// starting in version 3.14. Defaults to 0.
cache_time: Option<i32>, cache_time: Option<i32>,
} }
@ -45,7 +34,7 @@ impl Request for AnswerCallbackQuery<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"answerCallbackQuery", "answerCallbackQuery",
@ -62,7 +51,7 @@ impl<'a> AnswerCallbackQuery<'a> {
{ {
let callback_query_id = callback_query_id.into(); let callback_query_id = callback_query_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
callback_query_id, callback_query_id,
text: None, text: None,
show_alert: None, show_alert: None,
@ -71,6 +60,7 @@ impl<'a> AnswerCallbackQuery<'a> {
} }
} }
/// Unique identifier for the query to be answered.
pub fn callback_query_id<T>(mut self, val: T) -> Self pub fn callback_query_id<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -79,6 +69,8 @@ impl<'a> AnswerCallbackQuery<'a> {
self self
} }
/// Text of the notification. If not specified, nothing will be shown to the
/// user, 0-200 characters.
pub fn text<T>(mut self, val: T) -> Self pub fn text<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -87,11 +79,24 @@ impl<'a> AnswerCallbackQuery<'a> {
self self
} }
/// If `true`, an alert will be shown by the client instead of a
/// notification at the top of the chat screen. Defaults to `false`.
pub fn show_alert(mut self, val: bool) -> Self { pub fn show_alert(mut self, val: bool) -> Self {
self.show_alert = Some(val); self.show_alert = Some(val);
self self
} }
/// URL that will be opened by the user's client. If you have created a
/// [`Game`] and accepted the conditions via [@Botfather], specify the
/// URL that opens your game note that this will only work if the
/// query comes from a [`callback_game`] button.
///
/// Otherwise, you may use links like `t.me/your_bot?start=XXXX` that open
/// your bot with a parameter.
///
/// [@Botfather]: https://t.me/botfather
/// [`callback_game`]: crate::types::InlineKeyboardButton
/// [`Game`]: crate::types::Game
pub fn url<T>(mut self, val: T) -> Self pub fn url<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -100,6 +105,9 @@ impl<'a> AnswerCallbackQuery<'a> {
self self
} }
/// The maximum amount of time in seconds that the result of the callback
/// query may be cached client-side. Telegram apps will support caching
/// starting in version 3.14. Defaults to 0.
pub fn cache_time(mut self, val: i32) -> Self { pub fn cache_time(mut self, val: i32) -> Self {
self.cache_time = Some(val); self.cache_time = Some(val);
self self

View file

@ -1,51 +1,29 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{InlineQueryResult, True}, types::{InlineQueryResult, True},
Bot, Bot,
}; };
/// Use this method to send answers to an inline query. On success, True is /// Use this method to send answers to an inline query.
/// returned.No more than 50 results per query are allowed. ///
/// No more than **50** results per query are allowed.
///
/// [The official docs](https://core.telegram.org/bots/api#answerinlinequery).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(PartialEq, Debug, Clone, Serialize)]
pub struct AnswerInlineQuery<'a> { pub struct AnswerInlineQuery<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the answered query
inline_query_id: String, inline_query_id: String,
/// A JSON-serialized array of results for the inline query
results: Vec<InlineQueryResult>, results: Vec<InlineQueryResult>,
/// The maximum amount of time in seconds that the result of the inline
/// query may be cached on the server. Defaults to 300.
cache_time: Option<i32>, cache_time: Option<i32>,
/// 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
is_personal: Option<bool>, is_personal: Option<bool>,
/// 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 dont support pagination. Offset length cant
/// exceed 64 bytes.
next_offset: Option<String>, next_offset: Option<String>,
/// If passed, clients will display a button with specified text that
/// switches the user to a private chat with the bot and sends the bot a
/// start message with the parameter switch_pm_parameter
switch_pm_text: Option<String>, switch_pm_text: Option<String>,
/// Deep-linking parameter for the /start message sent to the bot when user
/// presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and -
/// are allowed.Example: An inline bot that sends YouTube videos can ask
/// the user to connect the bot to their YouTube account to adapt search
/// results accordingly. To do this, it displays a Connect your YouTube
/// account button above the results, or even before showing any. The user
/// presses the button, switches to a private chat with the bot and, in
/// doing so, passes a start parameter that instructs the bot to return an
/// oauth link. Once done, the bot can offer a switch_inline button so that
/// the user can easily return to the chat where they wanted to use the
/// bot's inline capabilities.
switch_pm_parameter: Option<String>, switch_pm_parameter: Option<String>,
} }
@ -54,7 +32,7 @@ impl Request for AnswerInlineQuery<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"answerInlineQuery", "answerInlineQuery",
@ -77,7 +55,7 @@ impl<'a> AnswerInlineQuery<'a> {
let inline_query_id = inline_query_id.into(); let inline_query_id = inline_query_id.into();
let results = results.into(); let results = results.into();
Self { Self {
bot, bot: BotWrapper(bot),
inline_query_id, inline_query_id,
results, results,
cache_time: None, cache_time: None,
@ -88,6 +66,7 @@ impl<'a> AnswerInlineQuery<'a> {
} }
} }
/// Unique identifier for the answered query.
pub fn inline_query_id<T>(mut self, val: T) -> Self pub fn inline_query_id<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -96,6 +75,7 @@ impl<'a> AnswerInlineQuery<'a> {
self self
} }
/// A JSON-serialized array of results for the inline query.
pub fn results<T>(mut self, val: T) -> Self pub fn results<T>(mut self, val: T) -> Self
where where
T: Into<Vec<InlineQueryResult>>, T: Into<Vec<InlineQueryResult>>,
@ -104,17 +84,31 @@ impl<'a> AnswerInlineQuery<'a> {
self self
} }
/// The maximum amount of time in seconds that the result of the inline
/// query may be cached on the server.
///
/// Defaults to 300.
pub fn cache_time(mut self, val: i32) -> Self { pub fn cache_time(mut self, val: i32) -> Self {
self.cache_time = Some(val); self.cache_time = Some(val);
self self
} }
/// 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.
#[allow(clippy::wrong_self_convention)] #[allow(clippy::wrong_self_convention)]
pub fn is_personal(mut self, val: bool) -> Self { pub fn is_personal(mut self, val: bool) -> Self {
self.is_personal = Some(val); self.is_personal = Some(val);
self self
} }
/// 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 dont
/// support pagination. Offset length cant exceed 64 bytes.
pub fn next_offset<T>(mut self, val: T) -> Self pub fn next_offset<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -123,6 +117,12 @@ impl<'a> AnswerInlineQuery<'a> {
self self
} }
/// If passed, clients will display a button with specified text that
/// switches the user to a private chat with the bot and sends the bot a
/// start message with the parameter [`switch_pm_parameter`].
///
/// [`switch_pm_parameter`]:
/// crate::requests::AnswerInlineQuery::switch_pm_parameter
pub fn switch_pm_text<T>(mut self, val: T) -> Self pub fn switch_pm_text<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -131,6 +131,22 @@ impl<'a> AnswerInlineQuery<'a> {
self self
} }
/// [Deep-linking] parameter for the /start message sent to the bot when
/// user presses the switch button. 1-64 characters, only `A-Z`, `a-z`,
/// `0-9`, `_` and `-` are allowed.
///
/// Example: An inline bot that sends YouTube videos can ask the user to
/// connect the bot to their YouTube account to adapt search results
/// accordingly. To do this, it displays a Connect your YouTube account
/// button above the results, or even before showing any. The user presses
/// the button, switches to a private chat with the bot and, in doing so,
/// passes a start parameter that instructs the bot to return an oauth link.
/// Once done, the bot can offer a [`switch_inline`] button so that the user
/// can easily return to the chat where they wanted to use the bot's
/// inline capabilities.
///
/// [Deep-linking]: https://core.telegram.org/bots#deep-linking
/// [`switch_inline`]: crate::types::InlineKeyboardMarkup
pub fn switch_pm_parameter<T>(mut self, val: T) -> Self pub fn switch_pm_parameter<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,

View file

@ -1,35 +1,29 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::True, types::True,
Bot, Bot,
}; };
/// Once the user has confirmed their payment and shipping details, the Bot API /// Once the user has confirmed their payment and shipping details, the Bot API
/// sends the final confirmation in the form of an Update with the field /// sends the final confirmation in the form of an [`Update`] with the field
/// pre_checkout_query. Use this method to respond to such pre-checkout queries. /// `pre_checkout_query`. Use this method to respond to such pre-checkout
/// On success, True is returned. Note: The Bot API must receive an answer /// queries. Note: The Bot API must receive an answer within 10 seconds after
/// within 10 seconds after the pre-checkout query was sent. /// the pre-checkout query was sent.
///
/// [The official docs](https://core.telegram.org/bots/api#answerprecheckoutquery).
///
/// [`Update`]: crate::types::Update
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct AnswerPreCheckoutQuery<'a> { pub struct AnswerPreCheckoutQuery<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the query to be answered
pre_checkout_query_id: String, pre_checkout_query_id: String,
/// Specify True if everything is alright (goods are available, etc.) and
/// the bot is ready to proceed with the order. Use False if there are any
/// problems.
ok: bool, ok: bool,
/// Required if ok is False. Error message in human readable form that
/// explains the reason for failure to proceed with the checkout (e.g.
/// "Sorry, somebody just bought the last of our amazing black T-shirts
/// while you were busy filling out your payment details. Please choose a
/// different color or garment!"). Telegram will display this message to
/// the user.
error_message: Option<String>, error_message: Option<String>,
} }
@ -38,7 +32,7 @@ impl Request for AnswerPreCheckoutQuery<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"answerPreCheckoutQuery", "answerPreCheckoutQuery",
@ -59,13 +53,14 @@ impl<'a> AnswerPreCheckoutQuery<'a> {
{ {
let pre_checkout_query_id = pre_checkout_query_id.into(); let pre_checkout_query_id = pre_checkout_query_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
pre_checkout_query_id, pre_checkout_query_id,
ok, ok,
error_message: None, error_message: None,
} }
} }
/// Unique identifier for the query to be answered.
pub fn pre_checkout_query_id<T>(mut self, val: T) -> Self pub fn pre_checkout_query_id<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -74,11 +69,21 @@ impl<'a> AnswerPreCheckoutQuery<'a> {
self self
} }
/// Specify `true` if everything is alright (goods are available, etc.) and
/// the bot is ready to proceed with the order. Use False if there are any
/// problems.
pub fn ok(mut self, val: bool) -> Self { pub fn ok(mut self, val: bool) -> Self {
self.ok = val; self.ok = val;
self self
} }
/// Required if ok is `false`. Error message in human readable form that
/// explains the reason for failure to proceed with the checkout (e.g.
/// "Sorry, somebody just bought the last of our amazing black T-shirts
/// while you were busy filling out your payment details. Please choose a
/// different color or garment!").
///
/// Telegram will display this message to the user.
pub fn error_message<T>(mut self, val: T) -> Self pub fn error_message<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,

View file

@ -1,35 +1,28 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ShippingOption, True}, types::{ShippingOption, True},
Bot, Bot,
}; };
/// If you sent an invoice requesting a shipping address and the parameter /// If you sent an invoice requesting a shipping address and the parameter
/// is_flexible was specified, the Bot API will send an Update with a /// `is_flexible` was specified, the Bot API will send an [`Update`] with a
/// shipping_query field to the bot. Use this method to reply to shipping /// shipping_query field to the bot. Use this method to reply to shipping
/// queries. On success, True is returned. /// queries.
///
/// [The official docs](https://core.telegram.org/bots/api#answershippingquery).
///
/// [`Update`]: crate::types::Update
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct AnswerShippingQuery<'a> { pub struct AnswerShippingQuery<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the query to be answered
shipping_query_id: String, shipping_query_id: String,
/// Specify True if delivery to the specified address is possible and False
/// if there are any problems (for example, if delivery to the specified
/// address is not possible)
ok: bool, ok: bool,
/// Required if ok is True. A JSON-serialized array of available shipping
/// options.
shipping_options: Option<Vec<ShippingOption>>, shipping_options: Option<Vec<ShippingOption>>,
/// Required if ok is False. Error message in human readable form that
/// explains why it is impossible to complete the order (e.g. "Sorry,
/// delivery to your desired address is unavailable'). Telegram will
/// display this message to the user.
error_message: Option<String>, error_message: Option<String>,
} }
@ -38,7 +31,7 @@ impl Request for AnswerShippingQuery<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"answerShippingQuery", "answerShippingQuery",
@ -55,7 +48,7 @@ impl<'a> AnswerShippingQuery<'a> {
{ {
let shipping_query_id = shipping_query_id.into(); let shipping_query_id = shipping_query_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
shipping_query_id, shipping_query_id,
ok, ok,
shipping_options: None, shipping_options: None,
@ -63,6 +56,7 @@ impl<'a> AnswerShippingQuery<'a> {
} }
} }
/// Unique identifier for the query to be answered.
pub fn shipping_query_id<T>(mut self, val: T) -> Self pub fn shipping_query_id<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -71,11 +65,16 @@ impl<'a> AnswerShippingQuery<'a> {
self self
} }
/// Specify `true` if delivery to the specified address is possible and
/// `false` if there are any problems (for example, if delivery to the
/// specified address is not possible).
pub fn ok(mut self, val: bool) -> Self { pub fn ok(mut self, val: bool) -> Self {
self.ok = val; self.ok = val;
self self
} }
/// Required if ok is `true`. A JSON-serialized array of available shipping
/// options.
pub fn shipping_options<T>(mut self, val: T) -> Self pub fn shipping_options<T>(mut self, val: T) -> Self
where where
T: Into<Vec<ShippingOption>>, T: Into<Vec<ShippingOption>>,
@ -84,6 +83,11 @@ impl<'a> AnswerShippingQuery<'a> {
self self
} }
/// Required if ok is `false`. Error message in human readable form that
/// explains why it is impossible to complete the order (e.g. "Sorry,
/// delivery to your desired address is unavailable').
///
/// Telegram will display this message to the user.
pub fn error_message<T>(mut self, val: T) -> Self pub fn error_message<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,

View file

@ -0,0 +1,33 @@
use crate::Bot;
use std::ops::Deref;
/// A wrapper that implements `Clone`, Copy, `PartialEq`, `Eq`, `Debug`, but
/// performs no copying, cloning and comparison.
///
/// Used in the requests bodies.
#[derive(Debug)]
pub struct BotWrapper<'a>(pub &'a Bot);
impl PartialEq for BotWrapper<'_> {
fn eq(&self, other: &BotWrapper<'_>) -> bool {
self.0.token() == other.0.token()
}
}
impl Eq for BotWrapper<'_> {}
impl<'a> Clone for BotWrapper<'a> {
fn clone(&self) -> BotWrapper<'a> {
Self(self.0)
}
}
impl Copy for BotWrapper<'_> {}
impl Deref for BotWrapper<'_> {
type Target = Bot;
fn deref(&self) -> &Bot {
&self.0
}
}

View file

@ -1,39 +1,24 @@
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{form_builder::FormBuilder, Request, ResponseResult}, requests::{form_builder::FormBuilder, Request, ResponseResult},
types::{InputFile, MaskPosition, True}, types::{InputFile, MaskPosition, True},
Bot, Bot,
}; };
/// Use this method to create new sticker set owned by a user. The bot will be /// Use this method to create new sticker set owned by a user. The bot will be
/// able to edit the created sticker set. Returns True on success. /// able to edit the created sticker set.
#[derive(Debug, Clone)] ///
/// [The official docs](https://core.telegram.org/bots/api#createnewstickerset).
#[derive(PartialEq, Debug, Clone)]
pub struct CreateNewStickerSet<'a> { pub struct CreateNewStickerSet<'a> {
bot: &'a Bot, bot: BotWrapper<'a>,
/// User identifier of created sticker set owner
user_id: i32, user_id: i32,
/// Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g.,
/// animals). Can contain only english letters, digits and underscores.
/// Must begin with a letter, can't contain consecutive underscores and
/// must end in “_by_<bot username>”. <bot_username> is case insensitive.
/// 1-64 characters.
name: String, name: String,
/// Sticker set title, 1-64 characters
title: String, title: String,
/// Png image with the sticker, must be up to 512 kilobytes in size,
/// dimensions must not exceed 512px, and either width or height must be
/// exactly 512px. Pass a file_id as a String to send a file that already
/// exists on the Telegram servers, pass an HTTP URL as a String for
/// Telegram to get a file from the Internet, or upload a new one using
/// multipart/form-data. More info on Sending Files »
png_sticker: InputFile, png_sticker: InputFile,
/// One or more emoji corresponding to the sticker
emojis: String, emojis: String,
/// Pass True, if a set of mask stickers should be created
contains_masks: Option<bool>, contains_masks: Option<bool>,
/// A JSON-serialized object for position where the mask should be placed
/// on faces
mask_position: Option<MaskPosition>, mask_position: Option<MaskPosition>,
} }
@ -42,7 +27,7 @@ impl Request for CreateNewStickerSet<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_multipart( net::request_multipart(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"createNewStickerSet", "createNewStickerSet",
@ -82,7 +67,7 @@ impl<'a> CreateNewStickerSet<'a> {
E: Into<String>, E: Into<String>,
{ {
Self { Self {
bot, bot: BotWrapper(bot),
user_id, user_id,
name: name.into(), name: name.into(),
title: title.into(), title: title.into(),
@ -93,11 +78,18 @@ impl<'a> CreateNewStickerSet<'a> {
} }
} }
/// User identifier of created sticker set owner.
pub fn user_id(mut self, val: i32) -> Self { pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val; self.user_id = val;
self self
} }
/// Short name of sticker set, to be used in `t.me/addstickers/` URLs (e.g.,
/// animals). Can contain only english letters, digits and underscores.
///
/// Must begin with a letter, can't contain consecutive underscores and must
/// end in `_by_<bot username>`. `<bot_username>` is case insensitive.
/// 1-64 characters.
pub fn name<T>(mut self, val: T) -> Self pub fn name<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -106,6 +98,7 @@ impl<'a> CreateNewStickerSet<'a> {
self self
} }
/// Sticker set title, 1-64 characters.
pub fn title<T>(mut self, val: T) -> Self pub fn title<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -114,11 +107,24 @@ impl<'a> CreateNewStickerSet<'a> {
self self
} }
/// **Png** image with the sticker, must be up to 512 kilobytes in size,
/// dimensions must not exceed 512px, and either width or height must be
/// exactly 512px.
///
/// Pass [`InputFile::File`] to send a file that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
pub fn png_sticker(mut self, val: InputFile) -> Self { pub fn png_sticker(mut self, val: InputFile) -> Self {
self.png_sticker = val; self.png_sticker = val;
self self
} }
/// One or more emoji corresponding to the sticker.
pub fn emojis<T>(mut self, val: T) -> Self pub fn emojis<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -127,11 +133,14 @@ impl<'a> CreateNewStickerSet<'a> {
self self
} }
/// Pass `true`, if a set of mask stickers should be created.
pub fn contains_masks(mut self, val: bool) -> Self { pub fn contains_masks(mut self, val: bool) -> Self {
self.contains_masks = Some(val); self.contains_masks = Some(val);
self self
} }
/// A JSON-serialized object for position where the mask should be placed on
/// faces.
pub fn mask_position(mut self, val: MaskPosition) -> Self { pub fn mask_position(mut self, val: MaskPosition) -> Self {
self.mask_position = Some(val); self.mask_position = Some(val);
self self

View file

@ -1,7 +1,8 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, True}, types::{ChatId, True},
Bot, Bot,
@ -9,15 +10,14 @@ use crate::{
/// Use this method to delete a chat photo. Photos can't be changed for private /// Use this method to delete a chat photo. Photos can't be changed for private
/// chats. The bot must be an administrator in the chat for this to work and /// chats. The bot must be an administrator in the chat for this to work and
/// must have the appropriate admin rights. Returns True on success. /// must have the appropriate admin rights.
///
/// [The official docs](https://core.telegram.org/bots/api#deletechatphoto).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct DeleteChatPhoto<'a> { pub struct DeleteChatPhoto<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
} }
@ -26,7 +26,7 @@ impl Request for DeleteChatPhoto<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"deleteChatPhoto", "deleteChatPhoto",
@ -42,9 +42,14 @@ impl<'a> DeleteChatPhoto<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { bot, chat_id } Self {
bot: BotWrapper(bot),
chat_id,
}
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,

View file

@ -1,25 +1,28 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, True}, types::{ChatId, True},
Bot, Bot,
}; };
/// Use this method to delete a group sticker set from a supergroup. The bot /// Use this method to delete a group sticker set from a supergroup.
/// must be an administrator in the chat for this to work and must have the ///
/// appropriate admin rights. Use the field can_set_sticker_set optionally /// The bot must be an administrator in the chat for this to work and must have
/// returned in getChat requests to check if the bot can use this method. /// the appropriate admin rights. Use the field `can_set_sticker_set` optionally
/// Returns True on success. /// returned in [`Bot::get_chat`] requests to check if the bot can use this
/// method.
///
/// [The official docs](https://core.telegram.org/bots/api#deletechatstickerset).
///
/// [`Bot::get_chat`]: crate::Bot::get_chat
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct DeleteChatStickerSet<'a> { pub struct DeleteChatStickerSet<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format @supergroupusername)
chat_id: ChatId, chat_id: ChatId,
} }
@ -28,7 +31,7 @@ impl Request for DeleteChatStickerSet<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"deleteChatStickerSet", "deleteChatStickerSet",
@ -44,9 +47,14 @@ impl<'a> DeleteChatStickerSet<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { bot, chat_id } Self {
bot: BotWrapper(bot),
chat_id,
}
} }
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format `@supergroupusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,

View file

@ -1,31 +1,34 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, True}, types::{ChatId, True},
Bot, Bot,
}; };
/// Use this method to delete a message, including service messages, with the /// Use this method to delete a message, including service messages.
/// following limitations:- A message can only be deleted if it was sent less ///
/// than 48 hours ago.- Bots can delete outgoing messages in private chats, /// The limitations are:
/// groups, and supergroups.- Bots can delete incoming messages in private /// - A message can only be deleted if it was sent less than 48 hours ago.
/// chats.- Bots granted can_post_messages permissions can delete outgoing /// - Bots can delete outgoing messages in private chats, groups, and
/// messages in channels.- If the bot is an administrator of a group, it can /// supergroups.
/// delete any message there.- If the bot has can_delete_messages permission in /// - Bots can delete incoming messages in private chats.
/// a supergroup or a channel, it can delete any message there.Returns True on /// - Bots granted can_post_messages permissions can delete outgoing messages
/// success. /// in channels.
/// - If the bot is an administrator of a group, it can delete any message
/// there.
/// - If the bot has can_delete_messages permission in a supergroup or a
/// channel, it can delete any message there.
///
/// [The official docs](https://core.telegram.org/bots/api#deletemessage).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct DeleteMessage<'a> { pub struct DeleteMessage<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Identifier of the message to delete
message_id: i32, message_id: i32,
} }
@ -34,7 +37,7 @@ impl Request for DeleteMessage<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"deleteMessage", "deleteMessage",
@ -51,12 +54,14 @@ impl<'a> DeleteMessage<'a> {
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
message_id, message_id,
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -65,6 +70,7 @@ impl<'a> DeleteMessage<'a> {
self self
} }
/// Identifier of the message to delete.
pub fn message_id(mut self, val: i32) -> Self { pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val; self.message_id = val;
self self

View file

@ -1,21 +1,21 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::True, types::True,
Bot, Bot,
}; };
/// Use this method to delete a sticker from a set created by the bot. Returns /// Use this method to delete a sticker from a set created by the bot.
/// True on success. ///
/// [The official docs](https://core.telegram.org/bots/api#deletestickerfromset).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct DeleteStickerFromSet<'a> { pub struct DeleteStickerFromSet<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// File identifier of the sticker
sticker: String, sticker: String,
} }
@ -24,7 +24,7 @@ impl Request for DeleteStickerFromSet<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"deleteStickerFromSet", "deleteStickerFromSet",
@ -40,9 +40,13 @@ impl<'a> DeleteStickerFromSet<'a> {
S: Into<String>, S: Into<String>,
{ {
let sticker = sticker.into(); let sticker = sticker.into();
Self { bot, sticker } Self {
bot: BotWrapper(bot),
sticker,
}
} }
/// File identifier of the sticker.
pub fn sticker<T>(mut self, val: T) -> Self pub fn sticker<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,

View file

@ -1,27 +1,33 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::True, types::True,
Bot, Bot,
}; };
/// Use this method to remove webhook integration if you decide to switch back /// Use this method to remove webhook integration if you decide to switch back
/// to getUpdates. Returns True on success. Requires no parameters. /// to [Bot::get_updates].
///
/// [The official docs](https://core.telegram.org/bots/api#deletewebhook).
///
/// [Bot::get_updates]: crate::Bot::get_updates
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Copy, Eq, PartialEq, Debug, Clone, Serialize)]
pub struct DeleteWebhook<'a> { pub struct DeleteWebhook<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl Request for DeleteWebhook<'_> { impl Request for DeleteWebhook<'_> {
type Output = True; type Output = True;
#[allow(clippy::trivially_copy_pass_by_ref)]
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"deleteWebhook", "deleteWebhook",
@ -33,6 +39,8 @@ impl Request for DeleteWebhook<'_> {
impl<'a> DeleteWebhook<'a> { impl<'a> DeleteWebhook<'a> {
pub(crate) fn new(bot: &'a Bot) -> Self { pub(crate) fn new(bot: &'a Bot) -> Self {
Self { bot } Self {
bot: BotWrapper(bot),
}
} }
} }

View file

@ -1,30 +1,31 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message, ParseMode}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message, ParseMode},
Bot, Bot,
}; };
/// Use this method to edit captions of messages. On success, if edited message /// Use this method to edit captions of messages.
/// is sent by the bot, the edited Message is returned, otherwise True is ///
/// returned. /// On success, if edited message is sent by the bot, the edited [`Message`] is
/// returned, otherwise [`True`] is returned.
///
/// [The official docs](https://core.telegram.org/bots/api#editmessagecaption).
///
/// [`Message`]: crate::types::Message
/// [`True`]: crate::types::True
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct EditMessageCaption<'a> { pub struct EditMessageCaption<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
#[serde(flatten)] #[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage, chat_or_inline_message: ChatOrInlineMessage,
/// New caption of the message
caption: Option<String>, caption: Option<String>,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in the media caption.
parse_mode: Option<ParseMode>, parse_mode: Option<ParseMode>,
/// A JSON-serialized object for an inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>, reply_markup: Option<InlineKeyboardMarkup>,
} }
@ -33,7 +34,7 @@ impl Request for EditMessageCaption<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"editMessageCaption", "editMessageCaption",
@ -49,7 +50,7 @@ impl<'a> EditMessageCaption<'a> {
chat_or_inline_message: ChatOrInlineMessage, chat_or_inline_message: ChatOrInlineMessage,
) -> Self { ) -> Self {
Self { Self {
bot, bot: BotWrapper(bot),
chat_or_inline_message, chat_or_inline_message,
caption: None, caption: None,
parse_mode: None, parse_mode: None,
@ -62,6 +63,7 @@ impl<'a> EditMessageCaption<'a> {
self self
} }
/// New caption of the message.
pub fn caption<T>(mut self, val: T) -> Self pub fn caption<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -70,11 +72,21 @@ impl<'a> EditMessageCaption<'a> {
self self
} }
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, val: ParseMode) -> Self { pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val); self.parse_mode = Some(val);
self self
} }
/// A JSON-serialized object for an [inline keyboard].
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,30 +1,33 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message},
Bot, Bot,
}; };
/// Use this method to edit live location messages. A location can be edited /// Use this method to edit live location messages.
/// until its live_period expires or editing is explicitly disabled by a call to ///
/// stopMessageLiveLocation. On success, if the edited message was sent by the /// A location can be edited until its live_period expires or editing is
/// bot, the edited Message is returned, otherwise True is returned. /// explicitly disabled by a call to stopMessageLiveLocation. On success, if the
/// edited message was sent by the bot, the edited [`Message`] is returned,
/// otherwise [`True`] is returned.
///
/// [The official docs](https://core.telegram.org/bots/api#editmessagelivelocation).
///
/// [`Message`]: crate::types::Message
/// [`True`]: crate::types::True
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(PartialEq, Debug, Clone, Serialize)]
pub struct EditMessageLiveLocation<'a> { pub struct EditMessageLiveLocation<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
#[serde(flatten)] #[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage, chat_or_inline_message: ChatOrInlineMessage,
/// Latitude of new location
latitude: f32, latitude: f32,
/// Longitude of new location
longitude: f32, longitude: f32,
/// A JSON-serialized object for a new inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>, reply_markup: Option<InlineKeyboardMarkup>,
} }
@ -33,7 +36,7 @@ impl Request for EditMessageLiveLocation<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"editMessageLiveLocation", "editMessageLiveLocation",
@ -51,7 +54,7 @@ impl<'a> EditMessageLiveLocation<'a> {
longitude: f32, longitude: f32,
) -> Self { ) -> Self {
Self { Self {
bot, bot: BotWrapper(bot),
chat_or_inline_message, chat_or_inline_message,
latitude, latitude,
longitude, longitude,
@ -64,16 +67,21 @@ impl<'a> EditMessageLiveLocation<'a> {
self self
} }
/// Latitude of new location.
pub fn latitude(mut self, val: f32) -> Self { pub fn latitude(mut self, val: f32) -> Self {
self.latitude = val; self.latitude = val;
self self
} }
/// Longitude of new location.
pub fn longitude(mut self, val: f32) -> Self { pub fn longitude(mut self, val: f32) -> Self {
self.longitude = val; self.longitude = val;
self self
} }
/// A JSON-serialized object for a new [inline keyboard].
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,26 +1,30 @@
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{form_builder::FormBuilder, Request, ResponseResult}, requests::{form_builder::FormBuilder, Request, ResponseResult},
types::{ChatOrInlineMessage, InlineKeyboardMarkup, InputMedia, Message}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, InputMedia, Message},
Bot, Bot,
}; };
/// Use this method to edit animation, audio, document, photo, or video /// Use this method to edit animation, audio, document, photo, or video
/// messages. If a message is a part of a message album, then it can be edited /// messages.
/// only to a photo or a video. Otherwise, message type can be changed ///
/// arbitrarily. When inline message is edited, new file can't be uploaded. Use /// If a message is a part of a message album, then it can be edited only to a
/// previously uploaded file via its file_id or specify a URL. On success, if /// photo or a video. Otherwise, message type can be changed arbitrarily. When
/// the edited message was sent by the bot, the edited Message is returned, /// inline message is edited, new file can't be uploaded. Use previously
/// otherwise True is returned. /// uploaded file via its `file_id` or specify a URL. On success, if the edited
#[derive(Debug, Clone)] /// message was sent by the bot, the edited [`Message`] is returned,
/// otherwise [`True`] is returned.
///
/// [The official docs](https://core.telegram.org/bots/api#editmessagemedia).
///
/// [`Message`]: crate::types::Message
/// [`True`]: crate::types::True
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct EditMessageMedia<'a> { pub struct EditMessageMedia<'a> {
bot: &'a Bot, bot: BotWrapper<'a>,
chat_or_inline_message: ChatOrInlineMessage, chat_or_inline_message: ChatOrInlineMessage,
/// A JSON-serialized object for a new media content of the message
media: InputMedia, media: InputMedia,
/// A JSON-serialized object for a new inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>, reply_markup: Option<InlineKeyboardMarkup>,
} }
@ -48,7 +52,7 @@ impl Request for EditMessageMedia<'_> {
} }
} }
network::request_multipart( net::request_multipart(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"editMessageMedia", "editMessageMedia",
@ -70,7 +74,7 @@ impl<'a> EditMessageMedia<'a> {
media: InputMedia, media: InputMedia,
) -> Self { ) -> Self {
Self { Self {
bot, bot: BotWrapper(bot),
chat_or_inline_message, chat_or_inline_message,
media, media,
reply_markup: None, reply_markup: None,
@ -82,11 +86,15 @@ impl<'a> EditMessageMedia<'a> {
self self
} }
/// A JSON-serialized object for a new media content of the message.
pub fn media(mut self, val: InputMedia) -> Self { pub fn media(mut self, val: InputMedia) -> Self {
self.media = val; self.media = val;
self self
} }
/// A JSON-serialized object for a new [inline keyboard].
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,25 +1,29 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message},
Bot, Bot,
}; };
/// Use this method to edit only the reply markup of messages. On success, if /// Use this method to edit only the reply markup of messages.
/// edited message is sent by the bot, the edited Message is returned, otherwise ///
/// True is returned. /// On success, if edited message is sent by the bot, the edited [`Message`] is
/// returned, otherwise [`True`] is returned.
///
/// [The official docs](https://core.telegram.org/bots/api#editmessagereplymarkup).
///
/// [`Message`]: crate::types::Message
/// [`True`]: crate::types::True
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct EditMessageReplyMarkup<'a> { pub struct EditMessageReplyMarkup<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
#[serde(flatten)] #[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage, chat_or_inline_message: ChatOrInlineMessage,
/// A JSON-serialized object for an inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>, reply_markup: Option<InlineKeyboardMarkup>,
} }
@ -28,7 +32,7 @@ impl Request for EditMessageReplyMarkup<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"editMessageReplyMarkup", "editMessageReplyMarkup",
@ -44,7 +48,7 @@ impl<'a> EditMessageReplyMarkup<'a> {
chat_or_inline_message: ChatOrInlineMessage, chat_or_inline_message: ChatOrInlineMessage,
) -> Self { ) -> Self {
Self { Self {
bot, bot: BotWrapper(bot),
chat_or_inline_message, chat_or_inline_message,
reply_markup: None, reply_markup: None,
} }
@ -55,6 +59,9 @@ impl<'a> EditMessageReplyMarkup<'a> {
self self
} }
/// A JSON-serialized object for an [inline keyboard].
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,32 +1,32 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message, ParseMode}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message, ParseMode},
Bot, Bot,
}; };
/// Use this method to edit text and game messages. On success, if edited /// Use this method to edit text and game messages.
/// message is sent by the bot, the edited Message is returned, otherwise True ///
/// is returned. /// On success, if edited message is sent by the bot, the edited [`Message`] is
/// returned, otherwise [`True`] is returned.
///
/// [The official docs](https://core.telegram.org/bots/api#editmessagetext).
///
/// [`Message`]: crate::types::Message
/// [`True`]: crate::types::True
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct EditMessageText<'a> { pub struct EditMessageText<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
#[serde(flatten)] #[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage, chat_or_inline_message: ChatOrInlineMessage,
/// New text of the message
text: String, text: String,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in your bot's message.
parse_mode: Option<ParseMode>, parse_mode: Option<ParseMode>,
/// Disables link previews for links in this message
disable_web_page_preview: Option<bool>, disable_web_page_preview: Option<bool>,
/// A JSON-serialized object for an inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>, reply_markup: Option<InlineKeyboardMarkup>,
} }
@ -35,7 +35,7 @@ impl Request for EditMessageText<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"editMessageText", "editMessageText",
@ -55,7 +55,7 @@ impl<'a> EditMessageText<'a> {
T: Into<String>, T: Into<String>,
{ {
Self { Self {
bot, bot: BotWrapper(bot),
chat_or_inline_message, chat_or_inline_message,
text: text.into(), text: text.into(),
parse_mode: None, parse_mode: None,
@ -69,6 +69,7 @@ impl<'a> EditMessageText<'a> {
self self
} }
/// New text of the message.
pub fn text<T>(mut self, val: T) -> Self pub fn text<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -77,16 +78,26 @@ impl<'a> EditMessageText<'a> {
self self
} }
/// Send [Markdown] or [HTML], if you want Telegram apps to show [bold,
/// italic, fixed-width text or inline URLs] in your bot's message.
///
/// [Markdown]: https://core.telegram.org/bots/api#markdown-style
/// [HTML]: https://core.telegram.org/bots/api#html-style
/// [bold, italic, fixed-width text or inline URLs]: https://core.telegram.org/bots/api#formatting-options
pub fn parse_mode(mut self, val: ParseMode) -> Self { pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val); self.parse_mode = Some(val);
self self
} }
/// Disables link previews for links in this message.
pub fn disable_web_page_preview(mut self, val: bool) -> Self { pub fn disable_web_page_preview(mut self, val: bool) -> Self {
self.disable_web_page_preview = Some(val); self.disable_web_page_preview = Some(val);
self self
} }
/// A JSON-serialized object for an [inline keyboard].
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,30 +1,37 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::ChatId, types::ChatId,
Bot, Bot,
}; };
/// Use this method to generate a new invite link for a chat; any previously /// Use this method to generate a new invite link for a chat; any previously
/// generated link is revoked. The bot must be an administrator in the chat for /// generated link is revoked.
/// this to work and must have the appropriate admin rights. Returns the new ///
/// invite link as String on success.Note: Each administrator in a chat /// The bot must be an administrator in the chat for this to work and must have
/// generates their own invite links. Bots can't use invite links generated by /// the appropriate admin rights.
/// other administrators. If you want your bot to work with invite links, it ///
/// will need to generate its own link using exportChatInviteLink after this /// ## Note
/// the link will become available to the bot via the getChat method. If your /// Each administrator in a chat generates their own invite links. Bots can't
/// bot needs to generate a new invite link replacing its previous one, use /// use invite links generated by other administrators. If you want your bot to
/// exportChatInviteLink again. /// work with invite links, it will need to generate its own link using
/// [`Bot::export_chat_invite_link`] after this the link will become available
/// to the bot via the [`Bot::get_chat`] method. If your bot needs to generate a
/// new invite link replacing its previous one, use
/// [`Bot::export_chat_invite_link`] again.
///
/// [The official docs](https://core.telegram.org/bots/api#exportchatinvitelink).
///
/// [`Bot::export_chat_invite_link`]: crate::Bot::export_chat_invite_link
/// [`Bot::get_chat`]: crate::Bot::get_chat
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct ExportChatInviteLink<'a> { pub struct ExportChatInviteLink<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
} }
@ -32,8 +39,9 @@ pub struct ExportChatInviteLink<'a> {
impl Request for ExportChatInviteLink<'_> { impl Request for ExportChatInviteLink<'_> {
type Output = String; type Output = String;
/// Returns the new invite link as `String` on success.
async fn send(&self) -> ResponseResult<String> { async fn send(&self) -> ResponseResult<String> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"exportChatInviteLink", "exportChatInviteLink",
@ -49,9 +57,14 @@ impl<'a> ExportChatInviteLink<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { bot, chat_id } Self {
bot: BotWrapper(bot),
chat_id,
}
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,

View file

@ -1,30 +1,24 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, Message}, types::{ChatId, Message},
Bot, Bot,
}; };
/// Use this method to forward messages of any kind. On success, the sent /// Use this method to forward messages of any kind.
/// Message is returned. ///
/// [`The official docs`](https://core.telegram.org/bots/api#forwardmessage).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct ForwardMessage<'a> { pub struct ForwardMessage<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Unique identifier for the chat where the original message was sent (or
/// channel username in the format @channelusername)
from_chat_id: ChatId, from_chat_id: ChatId,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>, disable_notification: Option<bool>,
/// Message identifier in the chat specified in from_chat_id
message_id: i32, message_id: i32,
} }
@ -33,7 +27,7 @@ impl Request for ForwardMessage<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"forwardMessage", "forwardMessage",
@ -57,7 +51,7 @@ impl<'a> ForwardMessage<'a> {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
let from_chat_id = from_chat_id.into(); let from_chat_id = from_chat_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
from_chat_id, from_chat_id,
message_id, message_id,
@ -65,6 +59,8 @@ impl<'a> ForwardMessage<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -73,6 +69,8 @@ impl<'a> ForwardMessage<'a> {
self self
} }
/// Unique identifier for the chat where the original message was sent (or
/// channel username in the format `@channelusername`).
#[allow(clippy::wrong_self_convention)] #[allow(clippy::wrong_self_convention)]
pub fn from_chat_id<T>(mut self, val: T) -> Self pub fn from_chat_id<T>(mut self, val: T) -> Self
where where
@ -82,11 +80,18 @@ impl<'a> ForwardMessage<'a> {
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self
} }
/// Message identifier in the chat specified in [`from_chat_id`].
///
/// [`from_chat_id`]: ForwardMessage::from_chat_id
pub fn message_id(mut self, val: i32) -> Self { pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val; self.message_id = val;
self self

View file

@ -1,7 +1,8 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{Chat, ChatId}, types::{Chat, ChatId},
Bot, Bot,
@ -9,15 +10,14 @@ use crate::{
/// Use this method to get up to date information about the chat (current name /// Use this method to get up to date information about the chat (current name
/// of the user for one-on-one conversations, current username of a user, group /// of the user for one-on-one conversations, current username of a user, group
/// or channel, etc.). Returns a Chat object on success. /// or channel, etc.).
///
/// [The official docs](https://core.telegram.org/bots/api#getchat).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetChat<'a> { pub struct GetChat<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
} }
@ -26,13 +26,8 @@ impl Request for GetChat<'_> {
type Output = Chat; type Output = Chat;
async fn send(&self) -> ResponseResult<Chat> { async fn send(&self) -> ResponseResult<Chat> {
network::request_json( net::request_json(self.bot.client(), self.bot.token(), "getChat", &self)
self.bot.client(), .await
self.bot.token(),
"getChat",
&self,
)
.await
} }
} }
@ -42,9 +37,14 @@ impl<'a> GetChat<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { bot, chat_id } Self {
bot: BotWrapper(bot),
chat_id,
}
} }
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,

View file

@ -1,25 +1,24 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, ChatMember}, types::{ChatId, ChatMember},
Bot, Bot,
}; };
/// Use this method to get a list of administrators in a chat. On success, /// Use this method to get a list of administrators in a chat.
/// returns an Array of ChatMember objects that contains information about all ///
/// chat administrators except other bots. If the chat is a group or a /// If the chat is a group or a supergroup and no administrators were appointed,
/// supergroup and no administrators were appointed, only the creator will be /// only the creator will be returned.
/// returned. ///
/// [The official docs](https://core.telegram.org/bots/api#getchatadministrators).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetChatAdministrators<'a> { pub struct GetChatAdministrators<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
} }
@ -27,8 +26,10 @@ pub struct GetChatAdministrators<'a> {
impl Request for GetChatAdministrators<'_> { impl Request for GetChatAdministrators<'_> {
type Output = Vec<ChatMember>; type Output = Vec<ChatMember>;
/// On success, returns an array that contains information about all chat
/// administrators except other bots.
async fn send(&self) -> ResponseResult<Vec<ChatMember>> { async fn send(&self) -> ResponseResult<Vec<ChatMember>> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"getChatAdministrators", "getChatAdministrators",
@ -44,9 +45,14 @@ impl<'a> GetChatAdministrators<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { bot, chat_id } Self {
bot: BotWrapper(bot),
chat_id,
}
} }
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,

View file

@ -1,24 +1,22 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, ChatMember}, types::{ChatId, ChatMember},
Bot, Bot,
}; };
/// Use this method to get information about a member of a chat. Returns a /// Use this method to get information about a member of a chat.
/// ChatMember object on success. ///
/// [The official docs](https://core.telegram.org/bots/api#getchatmember).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetChatMember<'a> { pub struct GetChatMember<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Unique identifier of the target user
user_id: i32, user_id: i32,
} }
@ -27,7 +25,7 @@ impl Request for GetChatMember<'_> {
type Output = ChatMember; type Output = ChatMember;
async fn send(&self) -> ResponseResult<ChatMember> { async fn send(&self) -> ResponseResult<ChatMember> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"getChatMember", "getChatMember",
@ -44,12 +42,14 @@ impl<'a> GetChatMember<'a> {
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
user_id, user_id,
} }
} }
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -58,6 +58,7 @@ impl<'a> GetChatMember<'a> {
self self
} }
/// Unique identifier of the target user.
pub fn user_id(mut self, val: i32) -> Self { pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val; self.user_id = val;
self self

View file

@ -1,22 +1,21 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::ChatId, types::ChatId,
Bot, Bot,
}; };
/// Use this method to get the number of members in a chat. Returns Int on /// Use this method to get the number of members in a chat.
/// success. ///
/// [The official docs](https://core.telegram.org/bots/api#getchatmemberscount).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetChatMembersCount<'a> { pub struct GetChatMembersCount<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
} }
@ -25,7 +24,7 @@ impl Request for GetChatMembersCount<'_> {
type Output = i32; type Output = i32;
async fn send(&self) -> ResponseResult<i32> { async fn send(&self) -> ResponseResult<i32> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"getChatMembersCount", "getChatMembersCount",
@ -41,9 +40,14 @@ impl<'a> GetChatMembersCount<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { bot, chat_id } Self {
bot: BotWrapper(bot),
chat_id,
}
} }
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,

View file

@ -1,7 +1,8 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::File, types::File,
Bot, Bot,
@ -12,8 +13,6 @@ use crate::{
/// ///
/// For the moment, bots can download files of up to `20MB` in size. /// For the moment, bots can download files of up to `20MB` in size.
/// ///
/// On success, a [`File`] object is returned.
///
/// The file can then be downloaded via the link /// The file can then be downloaded via the link
/// `https://api.telegram.org/file/bot<token>/<file_path>`, where `<file_path>` /// `https://api.telegram.org/file/bot<token>/<file_path>`, where `<file_path>`
/// is taken from the response. It is guaranteed that the link will be valid /// is taken from the response. It is guaranteed that the link will be valid
@ -24,16 +23,16 @@ use crate::{
/// type. You should save the file's MIME type and name (if available) when the /// type. You should save the file's MIME type and name (if available) when the
/// [`File`] object is received. /// [`File`] object is received.
/// ///
/// [The official docs](https://core.telegram.org/bots/api#getfile).
///
/// [`File`]: crate::types::file /// [`File`]: crate::types::file
/// [`GetFile`]: self::GetFile /// [`GetFile`]: self::GetFile
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetFile<'a> { pub struct GetFile<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
file_id: String,
/// File identifier to get info about
pub file_id: String,
} }
#[async_trait::async_trait] #[async_trait::async_trait]
@ -41,13 +40,8 @@ impl Request for GetFile<'_> {
type Output = File; type Output = File;
async fn send(&self) -> ResponseResult<File> { async fn send(&self) -> ResponseResult<File> {
network::request_json( net::request_json(self.bot.client(), self.bot.token(), "getFile", &self)
self.bot.client(), .await
self.bot.token(),
"getFile",
&self,
)
.await
} }
} }
@ -57,11 +51,12 @@ impl<'a> GetFile<'a> {
F: Into<String>, F: Into<String>,
{ {
Self { Self {
bot, bot: BotWrapper(bot),
file_id: file_id.into(), file_id: file_id.into(),
} }
} }
/// File identifier to get info about.
pub fn file_id<F>(mut self, value: F) -> Self pub fn file_id<F>(mut self, value: F) -> Self
where where
F: Into<String>, F: Into<String>,

View file

@ -1,28 +1,32 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatOrInlineMessage, GameHighScore}, types::{ChatOrInlineMessage, GameHighScore},
Bot, Bot,
}; };
/// Use this method to get data for high score tables. Will return the score of /// Use this method to get data for high score tables.
/// the specified user and several of his neighbors in a game. On success, ///
/// returns an Array of GameHighScore objects.This method will currently return /// Will return the score of the specified user and several of his neighbors in
/// scores for the target user, plus two of his closest neighbors on each side. /// a game.
/// Will also return the top three users if the user and his neighbors are not ///
/// among them. Please note that this behavior is subject to change. /// ## Note
/// This method will currently return scores for the target user, plus two of
/// his closest neighbors on each side. Will also return the top three users if
/// the user and his neighbors are not among them. Please note that this
/// behavior is subject to change.
///
/// [The official docs](https://core.telegram.org/bots/api#getgamehighscores).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetGameHighScores<'a> { pub struct GetGameHighScores<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
#[serde(flatten)] #[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage, chat_or_inline_message: ChatOrInlineMessage,
/// Target user id
user_id: i32, user_id: i32,
} }
@ -31,7 +35,7 @@ impl Request for GetGameHighScores<'_> {
type Output = Vec<GameHighScore>; type Output = Vec<GameHighScore>;
async fn send(&self) -> ResponseResult<Vec<GameHighScore>> { async fn send(&self) -> ResponseResult<Vec<GameHighScore>> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"getGameHighScores", "getGameHighScores",
@ -48,7 +52,7 @@ impl<'a> GetGameHighScores<'a> {
user_id: i32, user_id: i32,
) -> Self { ) -> Self {
Self { Self {
bot, bot: BotWrapper(bot),
chat_or_inline_message, chat_or_inline_message,
user_id, user_id,
} }
@ -59,6 +63,7 @@ impl<'a> GetGameHighScores<'a> {
self self
} }
/// Target user id.
pub fn user_id(mut self, val: i32) -> Self { pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val; self.user_id = val;
self self

View file

@ -1,39 +1,37 @@
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::User, types::User,
Bot, Bot,
}; };
use serde::Serialize; use serde::Serialize;
/// A filter method for testing your bot's auth token. Requires no parameters. /// A simple method for testing your bot's auth token. Requires no parameters.
/// Returns basic information about the bot in form of a [`User`] object.
/// ///
/// [`User`]: crate::types::User /// [The official docs](https://core.telegram.org/bots/api#getme).
#[derive(Debug, Clone, Copy, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Copy, Serialize)]
pub struct GetMe<'a> { pub struct GetMe<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl Request for GetMe<'_> { impl Request for GetMe<'_> {
type Output = User; type Output = User;
/// Returns basic information about the bot.
#[allow(clippy::trivially_copy_pass_by_ref)] #[allow(clippy::trivially_copy_pass_by_ref)]
async fn send(&self) -> ResponseResult<User> { async fn send(&self) -> ResponseResult<User> {
network::request_json( net::request_json(self.bot.client(), self.bot.token(), "getMe", &self)
self.bot.client(), .await
self.bot.token(),
"getMe",
&self,
)
.await
} }
} }
impl<'a> GetMe<'a> { impl<'a> GetMe<'a> {
pub(crate) fn new(bot: &'a Bot) -> Self { pub(crate) fn new(bot: &'a Bot) -> Self {
Self { bot } Self {
bot: BotWrapper(bot),
}
} }
} }

View file

@ -1,21 +1,21 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::StickerSet, types::StickerSet,
Bot, Bot,
}; };
/// Use this method to get a sticker set. On success, a StickerSet object is /// Use this method to get a sticker set.
/// returned. ///
/// [The official docs](https://core.telegram.org/bots/api#getstickerset).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetStickerSet<'a> { pub struct GetStickerSet<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Name of the sticker set
name: String, name: String,
} }
@ -24,7 +24,7 @@ impl Request for GetStickerSet<'_> {
type Output = StickerSet; type Output = StickerSet;
async fn send(&self) -> ResponseResult<StickerSet> { async fn send(&self) -> ResponseResult<StickerSet> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"getStickerSet", "getStickerSet",
@ -40,9 +40,13 @@ impl<'a> GetStickerSet<'a> {
N: Into<String>, N: Into<String>,
{ {
let name = name.into(); let name = name.into();
Self { bot, name } Self {
bot: BotWrapper(bot),
name,
}
} }
/// Name of the sticker set.
pub fn name<T>(mut self, val: T) -> Self pub fn name<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,

View file

@ -1,68 +1,32 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{AllowedUpdate, Update}, types::{AllowedUpdate, Update},
Bot, Bot,
}; };
/// Use this method to receive incoming updates using long polling ([wiki]). /// Use this method to receive incoming updates using long polling ([wiki]).
/// An array ([`Vec`]) of [`Update`]s is returned.
/// ///
/// **Notes:** /// **Notes:**
/// 1. This method will not work if an outgoing webhook is set up. /// 1. This method will not work if an outgoing webhook is set up.
/// 2. In order to avoid getting duplicate updates, /// 2. In order to avoid getting duplicate updates,
/// recalculate offset after each server response. /// recalculate offset after each server response.
/// ///
/// [The official docs](https://core.telegram.org/bots/api#getupdates).
///
/// [wiki]: https://en.wikipedia.org/wiki/Push_technology#Long_polling /// [wiki]: https://en.wikipedia.org/wiki/Push_technology#Long_polling
/// [Update]: crate::types::Update
/// [Vec]: std::alloc::Vec
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetUpdates<'a> { pub struct GetUpdates<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
pub(crate) offset: Option<i32>,
/// Identifier of the first update to be returned. Must be greater by one pub(crate) limit: Option<u8>,
/// than the highest among the identifiers of previously received updates. pub(crate) timeout: Option<u32>,
/// By default, updates starting with the earliest unconfirmed update are pub(crate) allowed_updates: Option<Vec<AllowedUpdate>>,
/// returned. An update is considered confirmed as soon as [`GetUpdates`]
/// is called with an [`offset`] higher than its [`id`]. The negative
/// offset can be specified to retrieve updates starting from `-offset`
/// update from the end of the updates queue. All previous updates will
/// forgotten.
///
/// [`GetUpdates`]: self::GetUpdates
/// [`offset`]: self::GetUpdates::offset
/// [`id`]: crate::types::Update::id
pub offset: Option<i32>,
/// Limits the number of updates to be retrieved.
/// Values between `1`—`100` are accepted. Defaults to `100`.
pub limit: Option<u8>,
/// Timeout in seconds for long polling. Defaults to `0`,
/// i.e. usual short polling. Should be positive, short polling should be
/// used for testing purposes only.
pub timeout: Option<u32>,
/// List the types of updates you want your bot to receive.
/// For example, specify [[`Message`], [`EditedChannelPost`],
/// [`CallbackQuery`]] to only receive updates of these types.
/// See [`AllowedUpdate`] for a complete list of available update types.
///
/// Specify an empty list to receive all updates regardless of type
/// (default). If not specified, the previous setting will be used.
///
/// **Note:**
/// This parameter doesn't affect updates created before the call to the
/// [`GetUpdates`], so unwanted updates may be received for a short period
/// of time.
///
/// [`Message`]: self::AllowedUpdate::Message
/// [`EditedChannelPost`]: self::AllowedUpdate::EditedChannelPost
/// [`CallbackQuery`]: self::AllowedUpdate::CallbackQuery
/// [`AllowedUpdate`]: self::AllowedUpdate
/// [`GetUpdates`]: self::GetUpdates
pub allowed_updates: Option<Vec<AllowedUpdate>>,
} }
#[async_trait::async_trait] #[async_trait::async_trait]
@ -70,7 +34,7 @@ impl Request for GetUpdates<'_> {
type Output = Vec<Update>; type Output = Vec<Update>;
async fn send(&self) -> ResponseResult<Vec<Update>> { async fn send(&self) -> ResponseResult<Vec<Update>> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"getUpdates", "getUpdates",
@ -83,7 +47,7 @@ impl Request for GetUpdates<'_> {
impl<'a> GetUpdates<'a> { impl<'a> GetUpdates<'a> {
pub(crate) fn new(bot: &'a Bot) -> Self { pub(crate) fn new(bot: &'a Bot) -> Self {
Self { Self {
bot, bot: BotWrapper(bot),
offset: None, offset: None,
limit: None, limit: None,
timeout: None, timeout: None,
@ -91,24 +55,63 @@ impl<'a> GetUpdates<'a> {
} }
} }
/// Identifier of the first update to be returned.
///
/// Must be greater by one than the highest among the identifiers of
/// previously received updates. By default, updates starting with the
/// earliest unconfirmed update are returned. An update is considered
/// confirmed as soon as [`GetUpdates`] is called with an [`offset`]
/// higher than its [`id`]. The negative offset can be specified to
/// retrieve updates starting from `-offset` update from the end of the
/// updates queue. All previous updates will forgotten.
///
/// [`GetUpdates`]: self::GetUpdates
/// [`offset`]: self::GetUpdates::offset
/// [`id`]: crate::types::Update::id
pub fn offset(mut self, value: i32) -> Self { pub fn offset(mut self, value: i32) -> Self {
self.offset = Some(value); self.offset = Some(value);
self self
} }
/// Limits the number of updates to be retrieved.
///
/// Values between `1`—`100` are accepted. Defaults to `100`.
pub fn limit(mut self, value: u8) -> Self { pub fn limit(mut self, value: u8) -> Self {
self.limit = Some(value); self.limit = Some(value);
self self
} }
/// Timeout in seconds for long polling.
///
/// Defaults to `0`, i.e. usual short polling. Should be positive, short
/// polling should be used for testing purposes only.
pub fn timeout(mut self, value: u32) -> Self { pub fn timeout(mut self, value: u32) -> Self {
self.timeout = Some(value); self.timeout = Some(value);
self self
} }
/// List the types of updates you want your bot to receive.
///
/// For example, specify [[`Message`], [`EditedChannelPost`],
/// [`CallbackQuery`]] to only receive updates of these types.
/// See [`AllowedUpdate`] for a complete list of available update types.
///
/// Specify an empty list to receive all updates regardless of type
/// (default). If not specified, the previous setting will be used.
///
/// **Note:**
/// This parameter doesn't affect updates created before the call to the
/// [`Bot::get_updates`], so unwanted updates may be received for a short
/// period of time.
///
/// [`Message`]: self::AllowedUpdate::Message
/// [`EditedChannelPost`]: self::AllowedUpdate::EditedChannelPost
/// [`CallbackQuery`]: self::AllowedUpdate::CallbackQuery
/// [`AllowedUpdate`]: self::AllowedUpdate
/// [`Bot::get_updates`]: crate::Bot::get_updates
pub fn allowed_updates<T>(mut self, value: T) -> Self pub fn allowed_updates<T>(mut self, value: T) -> Self
where where
T: Into<Vec<AllowedUpdate>>, // TODO: into or other trait? T: Into<Vec<AllowedUpdate>>,
{ {
self.allowed_updates = Some(value.into()); self.allowed_updates = Some(value.into());
self self

View file

@ -1,27 +1,23 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::UserProfilePhotos, types::UserProfilePhotos,
Bot, Bot,
}; };
/// Use this method to get a list of profile pictures for a user. Returns a /// Use this method to get a list of profile pictures for a user.
/// UserProfilePhotos object. ///
/// [The official docs](https://core.telegram.org/bots/api#getuserprofilephotos).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Copy, Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetUserProfilePhotos<'a> { pub struct GetUserProfilePhotos<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier of the target user
user_id: i32, user_id: i32,
/// Sequential number of the first photo to be returned. By default, all
/// photos are returned.
offset: Option<i32>, offset: Option<i32>,
/// Limits the number of photos to be retrieved. Values between 1—100 are
/// accepted. Defaults to 100.
limit: Option<i32>, limit: Option<i32>,
} }
@ -30,7 +26,7 @@ impl Request for GetUserProfilePhotos<'_> {
type Output = UserProfilePhotos; type Output = UserProfilePhotos;
async fn send(&self) -> ResponseResult<UserProfilePhotos> { async fn send(&self) -> ResponseResult<UserProfilePhotos> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"getUserProfilePhotos", "getUserProfilePhotos",
@ -43,23 +39,30 @@ impl Request for GetUserProfilePhotos<'_> {
impl<'a> GetUserProfilePhotos<'a> { impl<'a> GetUserProfilePhotos<'a> {
pub(crate) fn new(bot: &'a Bot, user_id: i32) -> Self { pub(crate) fn new(bot: &'a Bot, user_id: i32) -> Self {
Self { Self {
bot, bot: BotWrapper(bot),
user_id, user_id,
offset: None, offset: None,
limit: None, limit: None,
} }
} }
/// Unique identifier of the target user.
pub fn user_id(mut self, val: i32) -> Self { pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val; self.user_id = val;
self self
} }
/// Sequential number of the first photo to be returned. By default, all
/// photos are returned.
pub fn offset(mut self, val: i32) -> Self { pub fn offset(mut self, val: i32) -> Self {
self.offset = Some(val); self.offset = Some(val);
self self
} }
/// Limits the number of photos to be retrieved. Values between 1—100 are
/// accepted.
///
/// Defaults to 100.
pub fn limit(mut self, val: i32) -> Self { pub fn limit(mut self, val: i32) -> Self {
self.limit = Some(val); self.limit = Some(val);
self self

View file

@ -1,27 +1,34 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::WebhookInfo, types::WebhookInfo,
Bot, Bot,
}; };
/// Use this method to get current webhook status. Requires no parameters. On /// Use this method to get current webhook status.
/// success, returns a WebhookInfo object. If the bot is using getUpdates, will ///
/// return an object with the url field empty. /// If the bot is using [`Bot::get_updates`], will return an object with the url
#[derive(Debug, Clone, Serialize)] /// field empty.
///
/// [The official docs](https://core.telegram.org/bots/api#getwebhookinfo).
///
/// [`Bot::get_updates`]: crate::Bot::get_updates
#[derive(Copy, Eq, PartialEq, Debug, Clone, Serialize)]
pub struct GetWebhookInfo<'a> { pub struct GetWebhookInfo<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl Request for GetWebhookInfo<'_> { impl Request for GetWebhookInfo<'_> {
type Output = WebhookInfo; type Output = WebhookInfo;
#[allow(clippy::trivially_copy_pass_by_ref)]
async fn send(&self) -> ResponseResult<WebhookInfo> { async fn send(&self) -> ResponseResult<WebhookInfo> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"getWebhookInfo", "getWebhookInfo",
@ -33,6 +40,8 @@ impl Request for GetWebhookInfo<'_> {
impl<'a> GetWebhookInfo<'a> { impl<'a> GetWebhookInfo<'a> {
pub(crate) fn new(bot: &'a Bot) -> Self { pub(crate) fn new(bot: &'a Bot) -> Self {
Self { bot } Self {
bot: BotWrapper(bot),
}
} }
} }

View file

@ -1,31 +1,30 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, True}, types::{ChatId, True},
Bot, Bot,
}; };
/// Use this method to kick a user from a group, a supergroup or a channel. In /// Use this method to kick a user from a group, a supergroup or a channel.
/// the case of supergroups and channels, the user will not be able to return to ///
/// the group on their own using invite links, etc., unless unbanned first. The /// In the case of supergroups and channels, the user will not be able to return
/// bot must be an administrator in the chat for this to work and must have the /// to the group on their own using invite links, etc., unless [unbanned] first.
/// appropriate admin rights. Returns True on success. /// The bot must be an administrator in the chat for this to work and must have
/// the appropriate admin rights.
///
/// [The official docs](https://core.telegram.org/bots/api#kickchatmember).
///
/// [unbanned]: crate::Bot::unban_chat_member
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct KickChatMember<'a> { pub struct KickChatMember<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target group or username of the target
/// supergroup or channel (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Unique identifier of the target user
user_id: i32, user_id: i32,
/// Date when the user will be unbanned, unix time. If user is banned for
/// more than 366 days or less than 30 seconds from the current time they
/// are considered to be banned forever
until_date: Option<i32>, until_date: Option<i32>,
} }
@ -34,7 +33,7 @@ impl Request for KickChatMember<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"kickChatMember", "kickChatMember",
@ -51,13 +50,15 @@ impl<'a> KickChatMember<'a> {
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
user_id, user_id,
until_date: None, until_date: None,
} }
} }
/// Unique identifier for the target group or username of the target
/// supergroup or channel (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -66,11 +67,16 @@ impl<'a> KickChatMember<'a> {
self self
} }
/// Unique identifier of the target user.
pub fn user_id(mut self, val: i32) -> Self { pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val; self.user_id = val;
self self
} }
/// Date when the user will be unbanned, unix time.
///
/// If user is banned for more than 366 days or less than 30 seconds from
/// the current time they are considered to be banned forever.
pub fn until_date(mut self, val: i32) -> Self { pub fn until_date(mut self, val: i32) -> Self {
self.until_date = Some(val); self.until_date = Some(val);
self self

View file

@ -1,22 +1,21 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, True}, types::{ChatId, True},
Bot, Bot,
}; };
/// Use this method for your bot to leave a group, supergroup or channel. /// Use this method for your bot to leave a group, supergroup or channel.
/// Returns True on success. ///
/// [The official docs](https://core.telegram.org/bots/api#leavechat).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct LeaveChat<'a> { pub struct LeaveChat<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
} }
@ -25,7 +24,7 @@ impl Request for LeaveChat<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"leaveChat", "leaveChat",
@ -41,9 +40,14 @@ impl<'a> LeaveChat<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { bot, chat_id } Self {
bot: BotWrapper(bot),
chat_id,
}
} }
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,

View file

@ -130,3 +130,6 @@ pub use stop_poll::*;
pub use unban_chat_member::*; pub use unban_chat_member::*;
pub use unpin_chat_message::*; pub use unpin_chat_message::*;
pub use upload_sticker_file::*; pub use upload_sticker_file::*;
mod bot_wrapper;
use bot_wrapper::BotWrapper;

View file

@ -1,30 +1,27 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, True}, types::{ChatId, True},
Bot, Bot,
}; };
/// Use this method to pin a message in a group, a supergroup, or a channel. The /// Use this method to pin a message in a group, a supergroup, or a channel.
/// bot must be an administrator in the chat for this to work and must have the ///
/// can_pin_messages admin right in the supergroup or can_edit_messages /// The bot must be an administrator in the chat for this to work and must have
/// admin right in the channel. Returns True on success. /// the `can_pin_messages` admin right in the supergroup or `can_edit_messages`
/// admin right in the channel.
///
/// [The official docs](https://core.telegram.org/bots/api#pinchatmessage).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct PinChatMessage<'a> { pub struct PinChatMessage<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Identifier of a message to pin
message_id: i32, message_id: i32,
/// Pass True, if it is not necessary to send a notification to all chat
/// members about the new pinned message. Notifications are always disabled
/// in channels.
disable_notification: Option<bool>, disable_notification: Option<bool>,
} }
@ -33,7 +30,7 @@ impl Request for PinChatMessage<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"pinChatMessage", "pinChatMessage",
@ -50,13 +47,15 @@ impl<'a> PinChatMessage<'a> {
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
message_id, message_id,
disable_notification: None, disable_notification: None,
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -65,11 +64,16 @@ impl<'a> PinChatMessage<'a> {
self self
} }
/// Identifier of a message to pin.
pub fn message_id(mut self, val: i32) -> Self { pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val; self.message_id = val;
self self
} }
/// Pass `true`, if it is not necessary to send a notification to all chat
/// members about the new pinned message.
///
/// Notifications are always disabled in channels.
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self

View file

@ -1,47 +1,34 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, True}, types::{ChatId, True},
Bot, Bot,
}; };
/// Use this method to promote or demote a user in a supergroup or a channel. /// Use this method to promote or demote a user in a supergroup or a channel.
///
/// The bot must be an administrator in the chat for this to work and must have /// The bot must be an administrator in the chat for this to work and must have
/// the appropriate admin rights. Pass False for all boolean parameters to /// the appropriate admin rights. Pass False for all boolean parameters to
/// demote a user. Returns True on success. /// demote a user.
///
/// [The official docs](https://core.telegram.org/bots/api#promotechatmember).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct PromoteChatMember<'a> { pub struct PromoteChatMember<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Unique identifier of the target user
user_id: i32, user_id: i32,
/// Pass True, if the administrator can change chat title, photo and other
/// settings
can_change_info: Option<bool>, can_change_info: Option<bool>,
/// Pass True, if the administrator can create channel posts, channels only
can_post_messages: Option<bool>, can_post_messages: Option<bool>,
/// Pass True, if the administrator can edit messages of other users and
/// can pin messages, channels only
can_edit_messages: Option<bool>, can_edit_messages: Option<bool>,
/// Pass True, if the administrator can delete messages of other users
can_delete_messages: Option<bool>, can_delete_messages: Option<bool>,
/// Pass True, if the administrator can invite new users to the chat
can_invite_users: Option<bool>, can_invite_users: Option<bool>,
/// Pass True, if the administrator can restrict, ban or unban chat members
can_restrict_members: Option<bool>, can_restrict_members: Option<bool>,
/// Pass True, if the administrator can pin messages, supergroups only
can_pin_messages: Option<bool>, can_pin_messages: Option<bool>,
/// Pass True, if the administrator can add new administrators with a
/// subset of his own privileges or demote administrators that he has
/// promoted, directly or indirectly (promoted by administrators that were
/// appointed by him)
can_promote_members: Option<bool>, can_promote_members: Option<bool>,
} }
@ -50,7 +37,7 @@ impl Request for PromoteChatMember<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"promoteChatMember", "promoteChatMember",
@ -67,7 +54,7 @@ impl<'a> PromoteChatMember<'a> {
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
user_id, user_id,
can_change_info: None, can_change_info: None,
@ -81,6 +68,8 @@ impl<'a> PromoteChatMember<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -89,46 +78,62 @@ impl<'a> PromoteChatMember<'a> {
self self
} }
/// Unique identifier of the target user.
pub fn user_id(mut self, val: i32) -> Self { pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val; self.user_id = val;
self self
} }
/// Pass `true`, if the administrator can change chat title, photo and other
/// settings.
pub fn can_change_info(mut self, val: bool) -> Self { pub fn can_change_info(mut self, val: bool) -> Self {
self.can_change_info = Some(val); self.can_change_info = Some(val);
self self
} }
/// Pass `true`, if the administrator can create channel posts, channels
/// only.
pub fn can_post_messages(mut self, val: bool) -> Self { pub fn can_post_messages(mut self, val: bool) -> Self {
self.can_post_messages = Some(val); self.can_post_messages = Some(val);
self self
} }
/// Pass `true`, if the administrator can edit messages of other users and
/// can pin messages, channels only.
pub fn can_edit_messages(mut self, val: bool) -> Self { pub fn can_edit_messages(mut self, val: bool) -> Self {
self.can_edit_messages = Some(val); self.can_edit_messages = Some(val);
self self
} }
/// Pass `true`, if the administrator can delete messages of other users.
pub fn can_delete_messages(mut self, val: bool) -> Self { pub fn can_delete_messages(mut self, val: bool) -> Self {
self.can_delete_messages = Some(val); self.can_delete_messages = Some(val);
self self
} }
/// Pass `true`, if the administrator can invite new users to the chat.
pub fn can_invite_users(mut self, val: bool) -> Self { pub fn can_invite_users(mut self, val: bool) -> Self {
self.can_invite_users = Some(val); self.can_invite_users = Some(val);
self self
} }
/// Pass `true`, if the administrator can restrict, ban or unban chat
/// members.
pub fn can_restrict_members(mut self, val: bool) -> Self { pub fn can_restrict_members(mut self, val: bool) -> Self {
self.can_restrict_members = Some(val); self.can_restrict_members = Some(val);
self self
} }
/// Pass `true`, if the administrator can pin messages, supergroups only.
pub fn can_pin_messages(mut self, val: bool) -> Self { pub fn can_pin_messages(mut self, val: bool) -> Self {
self.can_pin_messages = Some(val); self.can_pin_messages = Some(val);
self self
} }
/// Pass `true`, if the administrator can add new administrators with a
/// subset of his own privileges or demote administrators that he has
/// promoted, directly or indirectly (promoted by administrators that were
/// appointed by him).
pub fn can_promote_members(mut self, val: bool) -> Self { pub fn can_promote_members(mut self, val: bool) -> Self {
self.can_promote_members = Some(val); self.can_promote_members = Some(val);
self self

View file

@ -1,32 +1,28 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, ChatPermissions, True}, types::{ChatId, ChatPermissions, True},
Bot, Bot,
}; };
/// Use this method to restrict a user in a supergroup. The bot must be an /// Use this method to restrict a user in a supergroup.
/// administrator in the supergroup for this to work and must have the ///
/// appropriate admin rights. Pass True for all permissions to lift restrictions /// The bot must be an administrator in the supergroup for this to work and must
/// from a user. Returns True on success. /// have the appropriate admin rights. Pass `true` for all permissions to lift
/// restrictions from a user.
///
/// [The official docs](https://core.telegram.org/bots/api#restrictchatmember).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct RestrictChatMember<'a> { pub struct RestrictChatMember<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format @supergroupusername)
chat_id: ChatId, chat_id: ChatId,
/// Unique identifier of the target user
user_id: i32, user_id: i32,
/// New user permissions
permissions: ChatPermissions, permissions: ChatPermissions,
/// Date when restrictions will be lifted for the user, unix time. If user
/// is restricted for more than 366 days or less than 30 seconds from the
/// current time, they are considered to be restricted forever
until_date: Option<i32>, until_date: Option<i32>,
} }
@ -35,7 +31,7 @@ impl Request for RestrictChatMember<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"restrictChatMember", "restrictChatMember",
@ -57,7 +53,7 @@ impl<'a> RestrictChatMember<'a> {
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
user_id, user_id,
permissions, permissions,
@ -65,6 +61,8 @@ impl<'a> RestrictChatMember<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format `@supergroupusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -73,16 +71,22 @@ impl<'a> RestrictChatMember<'a> {
self self
} }
/// Unique identifier of the target user.
pub fn user_id(mut self, val: i32) -> Self { pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val; self.user_id = val;
self self
} }
/// New user permissions.
pub fn permissions(mut self, val: ChatPermissions) -> Self { pub fn permissions(mut self, val: ChatPermissions) -> Self {
self.permissions = val; self.permissions = val;
self self
} }
/// Date when restrictions will be lifted for the user, unix time.
///
/// If user is restricted for more than 366 days or less than 30 seconds
/// from the current time, they are considered to be restricted forever.
pub fn until_date(mut self, val: i32) -> Self { pub fn until_date(mut self, val: i32) -> Self {
self.until_date = Some(val); self.until_date = Some(val);
self self

View file

@ -1,5 +1,6 @@
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{form_builder::FormBuilder, Request, ResponseResult}, requests::{form_builder::FormBuilder, Request, ResponseResult},
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup}, types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
Bot, Bot,
@ -8,52 +9,23 @@ use crate::{
/// Use this method to send animation files (GIF or H.264/MPEG-4 AVC video /// Use this method to send animation files (GIF or H.264/MPEG-4 AVC video
/// without sound). /// without sound).
/// ///
/// On success, the sent Message is returned.
///
/// Bots can currently send animation files of up to 50 MB in size, this limit /// Bots can currently send animation files of up to 50 MB in size, this limit
/// may be changed in the future. /// may be changed in the future.
#[derive(Debug, Clone)] ///
/// [The official docs](https://core.telegram.org/bots/api#sendanimation).
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendAnimation<'a> { pub struct SendAnimation<'a> {
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`)
pub chat_id: ChatId, pub chat_id: ChatId,
/// Animation to send.
pub animation: InputFile, pub animation: InputFile,
/// Duration of sent animation in seconds
pub duration: Option<u32>, pub duration: Option<u32>,
/// Animation width
pub width: Option<u32>, pub width: Option<u32>,
/// Animation height
pub height: Option<u32>, pub height: Option<u32>,
/// Thumbnail of the file sent; can be ignored if thumbnail generation for
/// the file is supported server-side. The thumbnail should be in JPEG
/// format and less than 200 kB in size. A thumbnails width and height
/// should not exceed 320. Ignored if the file is not uploaded using
/// [`InputFile::File`]. Thumbnails cant be reused and can be only
/// uploaded as a new file, with [`InputFile::File`]
///
/// [`InputFile::File`]: crate::types::InputFile::File
pub thumb: Option<InputFile>, pub thumb: Option<InputFile>,
/// Animation caption, `0`-`1024` characters
pub caption: Option<String>, pub caption: Option<String>,
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub parse_mode: Option<ParseMode>, pub parse_mode: Option<ParseMode>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
pub disable_notification: Option<bool>, pub disable_notification: Option<bool>,
/// If the message is a reply, [id] of the original message
///
/// [id]: crate::types::Message::id
pub reply_to_message_id: Option<i32>, pub reply_to_message_id: Option<i32>,
/// Additional interface options
pub reply_markup: Option<ReplyMarkup>, pub reply_markup: Option<ReplyMarkup>,
} }
@ -62,7 +34,7 @@ impl Request for SendAnimation<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_multipart( net::request_multipart(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendAnimation", "sendAnimation",
@ -101,7 +73,7 @@ impl<'a> SendAnimation<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
Self { Self {
bot, bot: BotWrapper(bot),
chat_id: chat_id.into(), chat_id: chat_id.into(),
animation, animation,
duration: None, duration: None,
@ -116,6 +88,8 @@ impl<'a> SendAnimation<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, value: T) -> Self pub fn chat_id<T>(mut self, value: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -124,24 +98,46 @@ impl<'a> SendAnimation<'a> {
self self
} }
/// Animation to send.
pub fn animation(mut self, val: InputFile) -> Self {
self.animation = val;
self
}
/// Duration of sent animation in seconds.
pub fn duration(mut self, value: u32) -> Self { pub fn duration(mut self, value: u32) -> Self {
self.duration = Some(value); self.duration = Some(value);
self self
} }
/// Animation width.
pub fn width(mut self, value: u32) -> Self { pub fn width(mut self, value: u32) -> Self {
self.width = Some(value); self.width = Some(value);
self self
} }
/// Animation height.
pub fn height(mut self, value: u32) -> Self { pub fn height(mut self, value: u32) -> Self {
self.height = Some(value); self.height = Some(value);
self self
} }
/// Thumbnail of the file sent; can be ignored if thumbnail generation for
/// the file is supported server-side.
///
/// The thumbnail should be in JPEG format and less than 200 kB in size. A
/// thumbnails width and height should not exceed 320. Ignored if the
/// file is not uploaded using [`InputFile::File`]. Thumbnails cant be
/// reused and can be only uploaded as a new file, with
/// [`InputFile::File`].
///
/// [`InputFile::File`]: crate::types::InputFile::File
pub fn thumb(mut self, value: InputFile) -> Self { pub fn thumb(mut self, value: InputFile) -> Self {
self.thumb = Some(value); self.thumb = Some(value);
self self
} }
/// Animation caption, `0`-`1024` characters.
pub fn caption<T>(mut self, value: T) -> Self pub fn caption<T>(mut self, value: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -149,18 +145,35 @@ impl<'a> SendAnimation<'a> {
self.caption = Some(value.into()); self.caption = Some(value.into());
self self
} }
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, value: ParseMode) -> Self { pub fn parse_mode(mut self, value: ParseMode) -> Self {
self.parse_mode = Some(value); self.parse_mode = Some(value);
self self
} }
/// Sends the message silently. Users will receive a notification with no
/// sound.
pub fn disable_notification(mut self, value: bool) -> Self { pub fn disable_notification(mut self, value: bool) -> Self {
self.disable_notification = Some(value); self.disable_notification = Some(value);
self self
} }
/// If the message is a reply, [id] of the original message.
///
/// [id]: crate::types::Message::id
pub fn reply_to_message_id(mut self, value: i32) -> Self { pub fn reply_to_message_id(mut self, value: i32) -> Self {
self.reply_to_message_id = Some(value); self.reply_to_message_id = Some(value);
self self
} }
/// Additional interface options.
pub fn reply_markup<T>(mut self, value: T) -> Self pub fn reply_markup<T>(mut self, value: T) -> Self
where where
T: Into<ReplyMarkup>, T: Into<ReplyMarkup>,

View file

@ -1,55 +1,35 @@
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{form_builder::FormBuilder, Request, ResponseResult}, requests::{form_builder::FormBuilder, Request, ResponseResult},
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup}, types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
Bot, Bot,
}; };
/// Use this method to send audio files, if you want Telegram clients to display /// Use this method to send audio files, if you want Telegram clients to display
/// them in the music player. Your audio must be in the .MP3 or .M4A format. On /// them in the music player.
/// success, the sent Message is returned. Bots can currently send audio files ///
/// of up to 50 MB in size, this limit may be changed in the future.For sending /// Your audio must be in the .MP3 or .M4A format. Bots can currently send audio
/// voice messages, use the sendVoice method instead. /// files of up to 50 MB in size, this limit may be changed in the future.
#[derive(Debug, Clone)] ///
/// For sending voice messages, use the [`Bot::send_voice`] method instead.
///
/// [The official docs](https://core.telegram.org/bots/api#sendaudio).
///
/// [`Bot::send_voice`]: crate::Bot::send_voice
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendAudio<'a> { pub struct SendAudio<'a> {
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Audio file to send. Pass a file_id as String to send an audio file that
/// exists on the Telegram servers (recommended), pass an HTTP URL as a
/// String for Telegram to get an audio file from the Internet, or upload a
/// new one using multipart/form-data. More info on Sending Files »
audio: InputFile, audio: InputFile,
/// Audio caption, 0-1024 characters
caption: Option<String>, caption: Option<String>,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in the media caption.
parse_mode: Option<ParseMode>, parse_mode: Option<ParseMode>,
/// Duration of the audio in seconds
duration: Option<i32>, duration: Option<i32>,
/// Performer
performer: Option<String>, performer: Option<String>,
/// Track name
title: Option<String>, title: Option<String>,
/// Thumbnail of the file sent; can be ignored if thumbnail generation for
/// the file is supported server-side. The thumbnail should be in JPEG
/// format and less than 200 kB in size. A thumbnails width and height
/// should not exceed 320. Ignored if the file is not uploaded using
/// multipart/form-data. Thumbnails cant be reused and can be only
/// uploaded as a new file, so you can pass “attach://<file_attach_name>”
/// if the thumbnail was uploaded using multipart/form-data under
/// <file_attach_name>. More info on Sending Files »
thumb: Option<InputFile>, thumb: Option<InputFile>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>, disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>, reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>, reply_markup: Option<ReplyMarkup>,
} }
@ -58,7 +38,7 @@ impl Request for SendAudio<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_multipart( net::request_multipart(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendAudio", "sendAudio",
@ -97,7 +77,7 @@ impl<'a> SendAudio<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
Self { Self {
bot, bot: BotWrapper(bot),
chat_id: chat_id.into(), chat_id: chat_id.into(),
audio, audio,
caption: None, caption: None,
@ -112,6 +92,8 @@ impl<'a> SendAudio<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -120,11 +102,24 @@ impl<'a> SendAudio<'a> {
self self
} }
/// Audio file to send.
///
/// Pass [`InputFile::File`] to send a file that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
///
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn audio(mut self, val: InputFile) -> Self { pub fn audio(mut self, val: InputFile) -> Self {
self.audio = val; self.audio = val;
self self
} }
/// Audio caption, 0-1024 characters.
pub fn caption<T>(mut self, val: T) -> Self pub fn caption<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -133,16 +128,25 @@ impl<'a> SendAudio<'a> {
self self
} }
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, val: ParseMode) -> Self { pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val); self.parse_mode = Some(val);
self self
} }
/// Duration of the audio in seconds.
pub fn duration(mut self, val: i32) -> Self { pub fn duration(mut self, val: i32) -> Self {
self.duration = Some(val); self.duration = Some(val);
self self
} }
/// Performer.
pub fn performer<T>(mut self, val: T) -> Self pub fn performer<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -151,6 +155,7 @@ impl<'a> SendAudio<'a> {
self self
} }
/// Track name.
pub fn title<T>(mut self, val: T) -> Self pub fn title<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -159,21 +164,44 @@ impl<'a> SendAudio<'a> {
self self
} }
/// Thumbnail of the file sent; can be ignored if thumbnail generation for
/// the file is supported server-side.
///
/// The thumbnail should be in JPEG format and less than 200 kB in size. A
/// thumbnails width and height should not exceed 320. Ignored if the
/// file is not uploaded using `multipart/form-data`. Thumbnails cant
/// be reused and can be only uploaded as a new file, so you can pass
/// `attach://<file_attach_name>` if the thumbnail was uploaded using
/// `multipart/form-data` under `<file_attach_name>`. [More info on
/// Sending Files »].
///
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn thumb(mut self, val: InputFile) -> Self { pub fn thumb(mut self, val: InputFile) -> Self {
self.thumb = Some(val); self.thumb = Some(val);
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self
} }
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self { pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val); self.reply_to_message_id = Some(val);
self self
} }
/// Additional interface options. A JSON-serialized object for an [inline
/// keyboard], [custom reply keyboard], instructions to remove reply
/// keyboard or to force a reply from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self { pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,39 +1,43 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, True}, types::{ChatId, True},
Bot, Bot,
}; };
/// Use this method when you need to tell the user that something is happening /// Use this method when you need to tell the user that something is happening
/// on the bot's side. The status is set for 5 seconds or less (when a message /// on the bot's side.
/// arrives from your bot, Telegram clients clear its typing status). Returns ///
/// True on success.Example: The ImageBot needs some time to process a request /// The status is set for 5 seconds or less (when a message arrives from your
/// and upload the image. Instead of sending a text message along the lines of /// bot, Telegram clients clear its typing status).
/// “Retrieving image, please wait…”, the bot may use sendChatAction with action ///
/// = upload_photo. The user will see a “sending photo” status for the bot.We /// ## Note
/// only recommend using this method when a response from the bot will take a /// Example: The [ImageBot] needs some time to process a request and upload the
/// noticeable amount of time to arrive. /// image. Instead of sending a text message along the lines of “Retrieving
/// image, please wait…”, the bot may use [`Bot::send_chat_action`] with `action
/// = upload_photo`. The user will see a `sending photo` status for the bot.
///
/// We only recommend using this method when a response from the bot will take a
/// **noticeable** amount of time to arrive.
///
/// [ImageBot]: https://t.me/imagebot
/// [`Bot::send_chat_action`]: crate::Bot::send_chat_action
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SendChatAction<'a> { pub struct SendChatAction<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Type of action to broadcast.
action: SendChatActionKind, action: SendChatActionKind,
} }
/// A type of action used in [`SendChatAction`]. /// A type of action used in [`SendChatAction`].
/// ///
/// [`SendChatAction`]: crate::requests::SendChatAction /// [`SendChatAction`]: crate::requests::SendChatAction
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] #[derive(PartialEq, Copy, Clone, Debug, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum SendChatActionKind { pub enum SendChatActionKind {
/// For [text messages](crate::Bot::send_message). /// For [text messages](crate::Bot::send_message).
@ -72,7 +76,7 @@ impl Request for SendChatAction<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendChatAction", "sendChatAction",
@ -92,12 +96,14 @@ impl<'a> SendChatAction<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
Self { Self {
bot, bot: BotWrapper(bot),
chat_id: chat_id.into(), chat_id: chat_id.into(),
action, action,
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -106,6 +112,7 @@ impl<'a> SendChatAction<'a> {
self self
} }
/// Type of action to broadcast.
pub fn action(mut self, val: SendChatActionKind) -> Self { pub fn action(mut self, val: SendChatActionKind) -> Self {
self.action = val; self.action = val;
self self

View file

@ -1,39 +1,28 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, Message, ReplyMarkup}, types::{ChatId, Message, ReplyMarkup},
Bot, Bot,
}; };
/// Use this method to send phone contacts. On success, the sent Message is /// Use this method to send phone contacts.
/// returned. ///
/// [The official docs](https://core.telegram.org/bots/api#sendcontact).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SendContact<'a> { pub struct SendContact<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Contact's phone number
phone_number: String, phone_number: String,
/// Contact's first name
first_name: String, first_name: String,
/// Contact's last name
last_name: Option<String>, last_name: Option<String>,
/// Additional data about the contact in the form of a vCard, 0-2048 bytes
vcard: Option<String>, vcard: Option<String>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>, disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>, reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove keyboard or to
/// force a reply from the user.
reply_markup: Option<ReplyMarkup>, reply_markup: Option<ReplyMarkup>,
} }
@ -42,7 +31,7 @@ impl Request for SendContact<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendContact", "sendContact",
@ -68,7 +57,7 @@ impl<'a> SendContact<'a> {
let phone_number = phone_number.into(); let phone_number = phone_number.into();
let first_name = first_name.into(); let first_name = first_name.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
phone_number, phone_number,
first_name, first_name,
@ -80,6 +69,8 @@ impl<'a> SendContact<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -88,6 +79,7 @@ impl<'a> SendContact<'a> {
self self
} }
/// Contact's phone number.
pub fn phone_number<T>(mut self, val: T) -> Self pub fn phone_number<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -96,6 +88,7 @@ impl<'a> SendContact<'a> {
self self
} }
/// Contact's first name.
pub fn first_name<T>(mut self, val: T) -> Self pub fn first_name<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -104,6 +97,7 @@ impl<'a> SendContact<'a> {
self self
} }
/// Contact's last name.
pub fn last_name<T>(mut self, val: T) -> Self pub fn last_name<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -112,6 +106,10 @@ impl<'a> SendContact<'a> {
self self
} }
/// Additional data about the contact in the form of a [vCard], 0-2048
/// bytes.
///
/// [vCard]: https://en.wikipedia.org/wiki/VCard
pub fn vcard<T>(mut self, val: T) -> Self pub fn vcard<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -120,16 +118,22 @@ impl<'a> SendContact<'a> {
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self
} }
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self { pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val); self.reply_to_message_id = Some(val);
self self
} }
/// Additional interface options.
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self { pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,48 +1,27 @@
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{form_builder::FormBuilder, Request, ResponseResult}, requests::{form_builder::FormBuilder, Request, ResponseResult},
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup}, types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
Bot, Bot,
}; };
/// Use this method to send general files. On success, the sent Message is /// Use this method to send general files.
/// returned. Bots can currently send files of any type of up to 50 MB in size, ///
/// this limit may be changed in the future. /// Bots can currently send files of any type of up to 50 MB in size, this limit
#[derive(Debug, Clone)] /// may be changed in the future.
///
/// [The official docs](https://core.telegram.org/bots/api#senddocument).
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendDocument<'a> { pub struct SendDocument<'a> {
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// File to send. Pass a file_id as String to send a file that exists on
/// the Telegram servers (recommended), pass an HTTP URL as a String for
/// Telegram to get a file from the Internet, or upload a new one using
/// multipart/form-data. More info on Sending Files »
document: InputFile, document: InputFile,
/// Thumbnail of the file sent; can be ignored if thumbnail generation for
/// the file is supported server-side. The thumbnail should be in JPEG
/// format and less than 200 kB in size. A thumbnails width and height
/// should not exceed 320. Ignored if the file is not uploaded using
/// multipart/form-data. Thumbnails cant be reused and can be only
/// uploaded as a new file, so you can pass “attach://<file_attach_name>”
/// if the thumbnail was uploaded using multipart/form-data under
/// <file_attach_name>. More info on Sending Files »
thumb: Option<InputFile>, thumb: Option<InputFile>,
/// Document caption (may also be used when resending documents by
/// file_id), 0-1024 characters
caption: Option<String>, caption: Option<String>,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in the media caption.
parse_mode: Option<ParseMode>, parse_mode: Option<ParseMode>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>, disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>, reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>, reply_markup: Option<ReplyMarkup>,
} }
@ -51,7 +30,7 @@ impl Request for SendDocument<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_multipart( net::request_multipart(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendDocument", "sendDocument",
@ -84,7 +63,7 @@ impl<'a> SendDocument<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
Self { Self {
bot, bot: BotWrapper(bot),
chat_id: chat_id.into(), chat_id: chat_id.into(),
document, document,
thumb: None, thumb: None,
@ -96,6 +75,8 @@ impl<'a> SendDocument<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -104,16 +85,38 @@ impl<'a> SendDocument<'a> {
self self
} }
/// File to send.
///
/// Pass a file_id as String to send a file that exists on the
/// Telegram servers (recommended), pass an HTTP URL as a String for
/// Telegram to get a file from the Internet, or upload a new one using
/// `multipart/form-data`. [More info on Sending Files »].
///
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn document(mut self, val: InputFile) -> Self { pub fn document(mut self, val: InputFile) -> Self {
self.document = val; self.document = val;
self self
} }
/// Thumbnail of the file sent; can be ignored if thumbnail generation for
/// the file is supported server-side.
///
/// The thumbnail should be in JPEG format and less than 200 kB in size. A
/// thumbnails width and height should not exceed 320. Ignored if the
/// file is not uploaded using `multipart/form-data`. Thumbnails cant
/// be reused and can be only uploaded as a new file, so you can pass
/// “attach://<file_attach_name>” if the thumbnail was uploaded using
/// `multipart/form-data` under `<file_attach_name>`. [More info on
/// Sending Files »].
///
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn thumb(mut self, val: InputFile) -> Self { pub fn thumb(mut self, val: InputFile) -> Self {
self.thumb = Some(val); self.thumb = Some(val);
self self
} }
/// Document caption (may also be used when resending documents by
/// `file_id`), 0-1024 characters.
pub fn caption<T>(mut self, val: T) -> Self pub fn caption<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -122,21 +125,34 @@ impl<'a> SendDocument<'a> {
self self
} }
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, val: ParseMode) -> Self { pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val); self.parse_mode = Some(val);
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self
} }
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self { pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val); self.reply_to_message_id = Some(val);
self self
} }
/// Additional interface options.
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self { pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,32 +1,25 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{InlineKeyboardMarkup, Message}, types::{InlineKeyboardMarkup, Message},
Bot, Bot,
}; };
/// Use this method to send a game. On success, the sent Message is returned. /// Use this method to send a game.
///
/// [The official docs](https://core.telegram.org/bots/api#sendgame).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SendGame<'a> { pub struct SendGame<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat
chat_id: i32, chat_id: i32,
/// Short name of the game, serves as the unique identifier for the game.
/// Set up your games via Botfather.
game_short_name: String, game_short_name: String,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>, disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>, reply_to_message_id: Option<i32>,
/// A JSON-serialized object for an inline keyboard. If empty, one Play
/// game_title button will be shown. If not empty, the first button must
/// launch the game.
reply_markup: Option<InlineKeyboardMarkup>, reply_markup: Option<InlineKeyboardMarkup>,
} }
@ -35,7 +28,7 @@ impl Request for SendGame<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendGame", "sendGame",
@ -52,7 +45,7 @@ impl<'a> SendGame<'a> {
{ {
let game_short_name = game_short_name.into(); let game_short_name = game_short_name.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
game_short_name, game_short_name,
disable_notification: None, disable_notification: None,
@ -61,11 +54,16 @@ impl<'a> SendGame<'a> {
} }
} }
/// Unique identifier for the target chat.
pub fn chat_id(mut self, val: i32) -> Self { pub fn chat_id(mut self, val: i32) -> Self {
self.chat_id = val; self.chat_id = val;
self self
} }
/// Short name of the game, serves as the unique identifier for the game.
/// Set up your games via [@Botfather].
///
/// [@Botfather]: https://t.me/botfather
pub fn game_short_name<T>(mut self, val: T) -> Self pub fn game_short_name<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -74,16 +72,26 @@ impl<'a> SendGame<'a> {
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self
} }
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self { pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val); self.reply_to_message_id = Some(val);
self self
} }
/// A JSON-serialized object for an [inline keyboard]. If empty, one `Play
/// game_title` button will be shown. If not empty, the first button must
/// launch the game.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,76 +1,43 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{InlineKeyboardMarkup, LabeledPrice, Message}, types::{InlineKeyboardMarkup, LabeledPrice, Message},
Bot, Bot,
}; };
/// Use this method to send invoices. On success, the sent Message is returned. /// Use this method to send invoices.
///
/// [The official docs](https://core.telegram.org/bots/api#sendinvoice).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SendInvoice<'a> { pub struct SendInvoice<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target private chat
chat_id: i32, chat_id: i32,
/// Product name, 1-32 characters
title: String, title: String,
/// Product description, 1-255 characters
description: String, description: String,
/// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to
/// the user, use for your internal processes.
payload: String, payload: String,
/// Payments provider token, obtained via Botfather
provider_token: String, provider_token: String,
/// Unique deep-linking parameter that can be used to generate this invoice
/// when used as a start parameter
start_parameter: String, start_parameter: String,
/// Three-letter ISO 4217 currency code, see more on currencies
currency: String, currency: String,
/// Price breakdown, a list of components (e.g. product price, tax,
/// discount, delivery cost, delivery tax, bonus, etc.)
prices: Vec<LabeledPrice>, prices: Vec<LabeledPrice>,
/// JSON-encoded data about the invoice, which will be shared with the
/// payment provider. A detailed description of required fields should be
/// provided by the payment provider.
provider_data: Option<String>, provider_data: Option<String>,
/// URL of the product photo for the invoice. Can be a photo of the goods
/// or a marketing image for a service. People like it better when they see
/// what they are paying for.
photo_url: Option<String>, photo_url: Option<String>,
/// Photo size
photo_size: Option<i32>, photo_size: Option<i32>,
/// Photo width
photo_width: Option<i32>, photo_width: Option<i32>,
/// Photo height
photo_height: Option<i32>, photo_height: Option<i32>,
/// Pass True, if you require the user's full name to complete the order
need_name: Option<bool>, need_name: Option<bool>,
/// Pass True, if you require the user's phone number to complete the order
need_phone_number: Option<bool>, need_phone_number: Option<bool>,
/// Pass True, if you require the user's email address to complete the
/// order
need_email: Option<bool>, need_email: Option<bool>,
/// Pass True, if you require the user's shipping address to complete the
/// order
need_shipping_address: Option<bool>, need_shipping_address: Option<bool>,
/// Pass True, if user's phone number should be sent to provider
send_phone_number_to_provider: Option<bool>, send_phone_number_to_provider: Option<bool>,
/// Pass True, if user's email address should be sent to provider
send_email_to_provider: Option<bool>, send_email_to_provider: Option<bool>,
/// Pass True, if the final price depends on the shipping method
is_flexible: Option<bool>, is_flexible: Option<bool>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>, disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>, reply_to_message_id: Option<i32>,
/// A JSON-serialized object for an inline keyboard. If empty, one 'Pay
/// total price' button will be shown. If not empty, the first button must
/// be a Pay button.
reply_markup: Option<InlineKeyboardMarkup>, reply_markup: Option<InlineKeyboardMarkup>,
} }
@ -79,7 +46,7 @@ impl Request for SendInvoice<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendInvoice", "sendInvoice",
@ -119,7 +86,7 @@ impl<'a> SendInvoice<'a> {
let currency = currency.into(); let currency = currency.into();
let prices = prices.into(); let prices = prices.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
title, title,
description, description,
@ -146,11 +113,13 @@ impl<'a> SendInvoice<'a> {
} }
} }
/// Unique identifier for the target private chat.
pub fn chat_id(mut self, val: i32) -> Self { pub fn chat_id(mut self, val: i32) -> Self {
self.chat_id = val; self.chat_id = val;
self self
} }
/// Product name, 1-32 characters.
pub fn title<T>(mut self, val: T) -> Self pub fn title<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -159,6 +128,7 @@ impl<'a> SendInvoice<'a> {
self self
} }
/// Product description, 1-255 characters.
pub fn description<T>(mut self, val: T) -> Self pub fn description<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -167,6 +137,8 @@ impl<'a> SendInvoice<'a> {
self self
} }
/// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to
/// the user, use for your internal processes.
pub fn payload<T>(mut self, val: T) -> Self pub fn payload<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -175,6 +147,9 @@ impl<'a> SendInvoice<'a> {
self self
} }
/// Payments provider token, obtained via [@Botfather].
///
/// [@Botfather]: https://t.me/botfather
pub fn provider_token<T>(mut self, val: T) -> Self pub fn provider_token<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -183,6 +158,8 @@ impl<'a> SendInvoice<'a> {
self self
} }
/// Unique deep-linking parameter that can be used to generate this invoice
/// when used as a start parameter.
pub fn start_parameter<T>(mut self, val: T) -> Self pub fn start_parameter<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -191,6 +168,9 @@ impl<'a> SendInvoice<'a> {
self self
} }
/// Three-letter ISO 4217 currency code, see [more on currencies].
///
/// [more on currencies]: https://core.telegram.org/bots/payments#supported-currencies
pub fn currency<T>(mut self, val: T) -> Self pub fn currency<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -199,6 +179,8 @@ impl<'a> SendInvoice<'a> {
self self
} }
/// Price breakdown, a list of components (e.g. product price, tax,
/// discount, delivery cost, delivery tax, bonus, etc.).
pub fn prices<T>(mut self, val: T) -> Self pub fn prices<T>(mut self, val: T) -> Self
where where
T: Into<Vec<LabeledPrice>>, T: Into<Vec<LabeledPrice>>,
@ -207,6 +189,11 @@ impl<'a> SendInvoice<'a> {
self self
} }
/// JSON-encoded data about the invoice, which will be shared with the
/// payment provider.
///
/// A detailed description of required fields should be provided by the
/// payment provider.
pub fn provider_data<T>(mut self, val: T) -> Self pub fn provider_data<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -215,6 +202,10 @@ impl<'a> SendInvoice<'a> {
self self
} }
/// URL of the product photo for the invoice.
///
/// Can be a photo of the goods or a marketing image for a service. People
/// like it better when they see what they are paying for.
pub fn photo_url<T>(mut self, val: T) -> Self pub fn photo_url<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -223,67 +214,91 @@ impl<'a> SendInvoice<'a> {
self self
} }
/// Photo size.
pub fn photo_size(mut self, val: i32) -> Self { pub fn photo_size(mut self, val: i32) -> Self {
self.photo_size = Some(val); self.photo_size = Some(val);
self self
} }
/// Photo width.
pub fn photo_width(mut self, val: i32) -> Self { pub fn photo_width(mut self, val: i32) -> Self {
self.photo_width = Some(val); self.photo_width = Some(val);
self self
} }
/// Photo height.
pub fn photo_height(mut self, val: i32) -> Self { pub fn photo_height(mut self, val: i32) -> Self {
self.photo_height = Some(val); self.photo_height = Some(val);
self self
} }
/// Pass `true`, if you require the user's full name to complete the order.
pub fn need_name(mut self, val: bool) -> Self { pub fn need_name(mut self, val: bool) -> Self {
self.need_name = Some(val); self.need_name = Some(val);
self self
} }
/// Pass `true`, if you require the user's phone number to complete the
/// order.
pub fn need_phone_number(mut self, val: bool) -> Self { pub fn need_phone_number(mut self, val: bool) -> Self {
self.need_phone_number = Some(val); self.need_phone_number = Some(val);
self self
} }
/// Pass `true`, if you require the user's email address to complete the
/// order.
pub fn need_email(mut self, val: bool) -> Self { pub fn need_email(mut self, val: bool) -> Self {
self.need_email = Some(val); self.need_email = Some(val);
self self
} }
/// Pass `true`, if you require the user's shipping address to complete the
/// order.
pub fn need_shipping_address(mut self, val: bool) -> Self { pub fn need_shipping_address(mut self, val: bool) -> Self {
self.need_shipping_address = Some(val); self.need_shipping_address = Some(val);
self self
} }
/// Pass `true`, if user's phone number should be sent to provider.
pub fn send_phone_number_to_provider(mut self, val: bool) -> Self { pub fn send_phone_number_to_provider(mut self, val: bool) -> Self {
self.send_phone_number_to_provider = Some(val); self.send_phone_number_to_provider = Some(val);
self self
} }
/// Pass `true`, if user's email address should be sent to provider.
pub fn send_email_to_provider(mut self, val: bool) -> Self { pub fn send_email_to_provider(mut self, val: bool) -> Self {
self.send_email_to_provider = Some(val); self.send_email_to_provider = Some(val);
self self
} }
/// Pass `true`, if the final price depends on the shipping method.
#[allow(clippy::wrong_self_convention)] #[allow(clippy::wrong_self_convention)]
pub fn is_flexible(mut self, val: bool) -> Self { pub fn is_flexible(mut self, val: bool) -> Self {
self.is_flexible = Some(val); self.is_flexible = Some(val);
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self
} }
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self { pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val); self.reply_to_message_id = Some(val);
self self
} }
/// A JSON-serialized object for an [inline keyboard].
///
/// If empty, one 'Pay `total price`' button will be shown. If not empty,
/// the first button must be a Pay button.
///
/// [inlint keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,38 +1,27 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, Message, ReplyMarkup}, types::{ChatId, Message, ReplyMarkup},
Bot, Bot,
}; };
/// Use this method to send point on the map. On success, the sent Message is /// Use this method to send point on the map.
/// returned. ///
/// [The official docs](https://core.telegram.org/bots/api#sendlocation).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(PartialEq, Debug, Clone, Serialize)]
pub struct SendLocation<'a> { pub struct SendLocation<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Latitude of the location
latitude: f32, latitude: f32,
/// Longitude of the location
longitude: f32, longitude: f32,
/// Period in seconds for which the location will be updated (see Live
/// Locations, should be between 60 and 86400.
live_period: Option<i64>, live_period: Option<i64>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>, disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>, reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>, reply_markup: Option<ReplyMarkup>,
} }
@ -41,7 +30,7 @@ impl Request for SendLocation<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendLocation", "sendLocation",
@ -63,7 +52,7 @@ impl<'a> SendLocation<'a> {
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
latitude, latitude,
longitude, longitude,
@ -74,6 +63,8 @@ impl<'a> SendLocation<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -82,31 +73,48 @@ impl<'a> SendLocation<'a> {
self self
} }
/// Latitude of the location.
pub fn latitude(mut self, val: f32) -> Self { pub fn latitude(mut self, val: f32) -> Self {
self.latitude = val; self.latitude = val;
self self
} }
/// Longitude of the location.
pub fn longitude(mut self, val: f32) -> Self { pub fn longitude(mut self, val: f32) -> Self {
self.longitude = val; self.longitude = val;
self self
} }
/// Period in seconds for which the location will be updated (see [Live
/// Locations], should be between 60 and 86400).
///
/// [Live Locations]: https://telegram.org/blog/live-locations
pub fn live_period(mut self, val: i64) -> Self { pub fn live_period(mut self, val: i64) -> Self {
self.live_period = Some(val); self.live_period = Some(val);
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self
} }
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self { pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val); self.reply_to_message_id = Some(val);
self self
} }
/// A JSON-serialized object for an [inline keyboard].
///
/// If empty, one 'Pay `total price`' button will be shown. If not empty,
/// the first button must be a Pay button.
///
/// [inlint keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self { pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,26 +1,20 @@
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{form_builder::FormBuilder, Request, ResponseResult}, requests::{form_builder::FormBuilder, Request, ResponseResult},
types::{ChatId, InputMedia, Message}, types::{ChatId, InputMedia, Message},
Bot, Bot,
}; };
/// Use this method to send a group of photos or videos as an album. On success, /// Use this method to send a group of photos or videos as an album.
/// an array of the sent Messages is returned. ///
#[derive(Debug, Clone)] /// [The official docs](https://core.telegram.org/bots/api#sendmediagroup).
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendMediaGroup<'a> { pub struct SendMediaGroup<'a> {
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// A JSON-serialized array describing photos and videos to be sent, must
/// include 210 items
media: Vec<InputMedia>, // TODO: InputMediaPhoto and InputMediaVideo media: Vec<InputMedia>, // TODO: InputMediaPhoto and InputMediaVideo
/// Sends the messages silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>, disable_notification: Option<bool>,
/// If the messages are a reply, ID of the original message
reply_to_message_id: Option<i32>, reply_to_message_id: Option<i32>,
} }
@ -29,7 +23,7 @@ impl Request for SendMediaGroup<'_> {
type Output = Vec<Message>; type Output = Vec<Message>;
async fn send(&self) -> ResponseResult<Vec<Message>> { async fn send(&self) -> ResponseResult<Vec<Message>> {
network::request_multipart( net::request_multipart(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendMediaGroup", "sendMediaGroup",
@ -57,7 +51,7 @@ impl<'a> SendMediaGroup<'a> {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
let media = media.into(); let media = media.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
media, media,
disable_notification: None, disable_notification: None,
@ -65,6 +59,8 @@ impl<'a> SendMediaGroup<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -73,6 +69,8 @@ impl<'a> SendMediaGroup<'a> {
self self
} }
/// A JSON-serialized array describing photos and videos to be sent, must
/// include 210 items.
pub fn media<T>(mut self, val: T) -> Self pub fn media<T>(mut self, val: T) -> Self
where where
T: Into<Vec<InputMedia>>, T: Into<Vec<InputMedia>>,
@ -81,11 +79,16 @@ impl<'a> SendMediaGroup<'a> {
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self
} }
/// If the messages are a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self { pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val); self.reply_to_message_id = Some(val);
self self

View file

@ -1,7 +1,8 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, Message, ParseMode, ReplyMarkup}, types::{ChatId, Message, ParseMode, ReplyMarkup},
Bot, Bot,
@ -9,38 +10,18 @@ use crate::{
/// Use this method to send text messages. /// Use this method to send text messages.
/// ///
/// On success, the sent [`Message`] is returned. /// [The official docs](https://core.telegram.org/bots/api#sendmessage).
///
/// [`Message`]: crate::types::Message
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SendMessage<'a> { pub struct SendMessage<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`)
pub chat_id: ChatId, pub chat_id: ChatId,
/// Text of the message to be sent
pub text: String, pub text: String,
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in your bot's message.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub parse_mode: Option<ParseMode>, pub parse_mode: Option<ParseMode>,
/// Disables link previews for links in this message
pub disable_web_page_preview: Option<bool>, pub disable_web_page_preview: Option<bool>,
/// Sends the message silently.
/// Users will receive a notification with no sound.
pub disable_notification: Option<bool>, pub disable_notification: Option<bool>,
/// If the message is a reply, [id] of the original message
///
/// [id]: crate::types::Message::id
pub reply_to_message_id: Option<i32>, pub reply_to_message_id: Option<i32>,
/// Additional interface options.
pub reply_markup: Option<ReplyMarkup>, pub reply_markup: Option<ReplyMarkup>,
} }
@ -49,7 +30,7 @@ impl Request for SendMessage<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendMessage", "sendMessage",
@ -66,7 +47,7 @@ impl<'a> SendMessage<'a> {
T: Into<String>, T: Into<String>,
{ {
Self { Self {
bot, bot: BotWrapper(bot),
chat_id: chat_id.into(), chat_id: chat_id.into(),
text: text.into(), text: text.into(),
parse_mode: None, parse_mode: None,
@ -77,6 +58,8 @@ impl<'a> SendMessage<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, value: T) -> Self pub fn chat_id<T>(mut self, value: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -85,6 +68,7 @@ impl<'a> SendMessage<'a> {
self self
} }
/// Text of the message to be sent.
pub fn text<T>(mut self, value: T) -> Self pub fn text<T>(mut self, value: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -93,26 +77,47 @@ impl<'a> SendMessage<'a> {
self self
} }
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, value: ParseMode) -> Self { pub fn parse_mode(mut self, value: ParseMode) -> Self {
self.parse_mode = Some(value); self.parse_mode = Some(value);
self self
} }
/// Disables link previews for links in this message.
pub fn disable_web_page_preview(mut self, value: bool) -> Self { pub fn disable_web_page_preview(mut self, value: bool) -> Self {
self.disable_web_page_preview = Some(value); self.disable_web_page_preview = Some(value);
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, value: bool) -> Self { pub fn disable_notification(mut self, value: bool) -> Self {
self.disable_notification = Some(value); self.disable_notification = Some(value);
self self
} }
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, value: i32) -> Self { pub fn reply_to_message_id(mut self, value: i32) -> Self {
self.reply_to_message_id = Some(value); self.reply_to_message_id = Some(value);
self self
} }
/// Additional interface options.
///
/// A JSON-serialized object for an [inline keyboard], [custom reply
/// keyboard], instructions to remove reply keyboard or to force a reply
/// from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup<T>(mut self, value: T) -> Self pub fn reply_markup<T>(mut self, value: T) -> Self
where where
T: Into<ReplyMarkup>, T: Into<ReplyMarkup>,

View file

@ -1,37 +1,23 @@
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{form_builder::FormBuilder, Request, ResponseResult}, requests::{form_builder::FormBuilder, Request, ResponseResult},
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup}, types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
Bot, Bot,
}; };
/// Use this method to send photos. On success, the sent Message is returned. /// Use this method to send photos.
#[derive(Debug, Clone)] ///
/// [The official docs](https://core.telegram.org/bots/api#sendphoto).
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendPhoto<'a> { pub struct SendPhoto<'a> {
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Photo to send. Pass a file_id as String to send a photo that exists on
/// the Telegram servers (recommended), pass an HTTP URL as a String for
/// Telegram to get a photo from the Internet, or upload a new photo using
/// multipart/form-data. More info on Sending Files »
photo: InputFile, photo: InputFile,
/// Photo caption (may also be used when resending photos by file_id),
/// 0-1024 characters
caption: Option<String>, caption: Option<String>,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in the media caption.
parse_mode: Option<ParseMode>, parse_mode: Option<ParseMode>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>, disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>, reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>, reply_markup: Option<ReplyMarkup>,
} }
@ -40,7 +26,7 @@ impl Request for SendPhoto<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_multipart( net::request_multipart(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendPhoto", "sendPhoto",
@ -71,7 +57,7 @@ impl<'a> SendPhoto<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
Self { Self {
bot, bot: BotWrapper(bot),
chat_id: chat_id.into(), chat_id: chat_id.into(),
photo, photo,
caption: None, caption: None,
@ -82,6 +68,8 @@ impl<'a> SendPhoto<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -90,11 +78,25 @@ impl<'a> SendPhoto<'a> {
self self
} }
/// Photo to send.
///
/// Pass [`InputFile::File`] to send a photo that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
///
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn photo(mut self, val: InputFile) -> Self { pub fn photo(mut self, val: InputFile) -> Self {
self.photo = val; self.photo = val;
self self
} }
///Photo caption (may also be used when resending photos by file_id),
/// 0-1024 characters.
pub fn caption<T>(mut self, val: T) -> Self pub fn caption<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -103,21 +105,39 @@ impl<'a> SendPhoto<'a> {
self self
} }
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, val: ParseMode) -> Self { pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val); self.parse_mode = Some(val);
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self
} }
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self { pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val); self.reply_to_message_id = Some(val);
self self
} }
/// Additional interface options. A JSON-serialized object for an [inline
/// keyboard], [custom reply keyboard], instructions to remove reply
/// keyboard or to force a reply from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self { pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,36 +1,27 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, Message, ReplyMarkup}, types::{ChatId, Message, ReplyMarkup},
Bot, Bot,
}; };
/// Use this method to send a native poll. A native poll can't be sent to a /// Use this method to send a native poll. A native poll can't be sent to a
/// private chat. On success, the sent Message is returned. /// private chat.
///
/// [The official docs](https://core.telegram.org/bots/api#sendpoll).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SendPoll<'a> { pub struct SendPoll<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername). A native poll can't be sent to a
/// private chat.
chat_id: ChatId, chat_id: ChatId,
/// Poll question, 1-255 characters
question: String, question: String,
/// List of answer options, 2-10 strings 1-100 characters each
options: Vec<String>, options: Vec<String>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>, disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>, reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>, reply_markup: Option<ReplyMarkup>,
} }
@ -39,7 +30,7 @@ impl Request for SendPoll<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendPoll", "sendPoll",
@ -65,7 +56,7 @@ impl<'a> SendPoll<'a> {
let question = question.into(); let question = question.into();
let options = options.into(); let options = options.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
question, question,
options, options,
@ -75,6 +66,10 @@ impl<'a> SendPoll<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
///
/// A native poll can't be sent to a private chat.
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -83,6 +78,7 @@ impl<'a> SendPoll<'a> {
self self
} }
/// Poll question, 1-255 characters.
pub fn question<T>(mut self, val: T) -> Self pub fn question<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -91,6 +87,7 @@ impl<'a> SendPoll<'a> {
self self
} }
/// List of answer options, 2-10 strings 1-100 characters each.
pub fn options<T>(mut self, val: T) -> Self pub fn options<T>(mut self, val: T) -> Self
where where
T: Into<Vec<String>>, T: Into<Vec<String>>,
@ -99,16 +96,29 @@ impl<'a> SendPoll<'a> {
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self
} }
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self { pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val); self.reply_to_message_id = Some(val);
self self
} }
/// Additional interface options.
///
/// A JSON-serialized object for an [inline keyboard], [custom reply
/// keyboard], instructions to remove reply keyboard or to force a reply
/// from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self { pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,32 +1,23 @@
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{form_builder::FormBuilder, Request, ResponseResult}, requests::{form_builder::FormBuilder, Request, ResponseResult},
types::{ChatId, InputFile, Message, ReplyMarkup}, types::{ChatId, InputFile, Message, ReplyMarkup},
Bot, Bot,
}; };
/// Use this method to send static .WEBP or animated .TGS stickers. On success, /// Use this method to send static .WEBP or [animated] .TGS stickers.
/// the sent Message is returned. ///
#[derive(Debug, Clone)] /// [The official docs](https://core.telegram.org/bots/api#sendsticker).
///
/// [animated]: https://telegram.org/blog/animated-stickers
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendSticker<'a> { pub struct SendSticker<'a> {
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Sticker to send. Pass a file_id as String to send a file that exists on
/// the Telegram servers (recommended), pass an HTTP URL as a String for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using multipart/form-data. More info on Sending Files »
sticker: InputFile, sticker: InputFile,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>, disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>, reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>, reply_markup: Option<ReplyMarkup>,
} }
@ -35,7 +26,7 @@ impl Request for SendSticker<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_multipart( net::request_multipart(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendSticker", "sendSticker",
@ -62,7 +53,7 @@ impl<'a> SendSticker<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
Self { Self {
bot, bot: BotWrapper(bot),
chat_id: chat_id.into(), chat_id: chat_id.into(),
sticker, sticker,
disable_notification: None, disable_notification: None,
@ -71,6 +62,8 @@ impl<'a> SendSticker<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -79,21 +72,45 @@ impl<'a> SendSticker<'a> {
self self
} }
/// Sticker to send.
///
/// Pass [`InputFile::File`] to send a file that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn sticker(mut self, val: InputFile) -> Self { pub fn sticker(mut self, val: InputFile) -> Self {
self.sticker = val; self.sticker = val;
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self
} }
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self { pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val); self.reply_to_message_id = Some(val);
self self
} }
/// Additional interface options.
///
/// A JSON-serialized object for an [inline keyboard], [custom reply
/// keyboard], instructions to remove reply keyboard or to force a reply
/// from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self { pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,45 +1,30 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, Message, ReplyMarkup}, types::{ChatId, Message, ReplyMarkup},
Bot, Bot,
}; };
/// Use this method to send information about a venue. On success, the sent /// Use this method to send information about a venue.
/// Message is returned. ///
/// [The official docs](https://core.telegram.org/bots/api#sendvenue).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(PartialEq, Debug, Clone, Serialize)]
pub struct SendVenue<'a> { pub struct SendVenue<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Latitude of the venue
latitude: f32, latitude: f32,
/// Longitude of the venue
longitude: f32, longitude: f32,
/// Name of the venue
title: String, title: String,
/// Address of the venue
address: String, address: String,
/// Foursquare identifier of the venue
foursquare_id: Option<String>, foursquare_id: Option<String>,
/// Foursquare type of the venue, if known. (For example,
/// “arts_entertainment/default”, “arts_entertainment/aquarium” or
/// “food/icecream”.)
foursquare_type: Option<String>, foursquare_type: Option<String>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>, disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>, reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>, reply_markup: Option<ReplyMarkup>,
} }
@ -48,7 +33,7 @@ impl Request for SendVenue<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendVenue", "sendVenue",
@ -76,7 +61,7 @@ impl<'a> SendVenue<'a> {
let title = title.into(); let title = title.into();
let address = address.into(); let address = address.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
latitude, latitude,
longitude, longitude,
@ -90,6 +75,8 @@ impl<'a> SendVenue<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -98,16 +85,19 @@ impl<'a> SendVenue<'a> {
self self
} }
/// Latitude of the venue.
pub fn latitude(mut self, val: f32) -> Self { pub fn latitude(mut self, val: f32) -> Self {
self.latitude = val; self.latitude = val;
self self
} }
/// Longitude of the venue.
pub fn longitude(mut self, val: f32) -> Self { pub fn longitude(mut self, val: f32) -> Self {
self.longitude = val; self.longitude = val;
self self
} }
/// Name of the venue.
pub fn title<T>(mut self, val: T) -> Self pub fn title<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -116,6 +106,7 @@ impl<'a> SendVenue<'a> {
self self
} }
/// Address of the venue.
pub fn address<T>(mut self, val: T) -> Self pub fn address<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -124,6 +115,7 @@ impl<'a> SendVenue<'a> {
self self
} }
/// Foursquare identifier of the venue.
pub fn foursquare_id<T>(mut self, val: T) -> Self pub fn foursquare_id<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -132,6 +124,10 @@ impl<'a> SendVenue<'a> {
self self
} }
/// Foursquare type of the venue, if known.
///
/// For example, `arts_entertainment/default`, `arts_entertainment/aquarium`
/// or `food/icecream`.
pub fn foursquare_type<T>(mut self, val: T) -> Self pub fn foursquare_type<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -140,16 +136,29 @@ impl<'a> SendVenue<'a> {
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self
} }
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self { pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val); self.reply_to_message_id = Some(val);
self self
} }
/// Additional interface options.
///
/// A JSON-serialized object for an [inline keyboard], [custom reply
/// keyboard], instructions to remove reply keyboard or to force a reply
/// from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self { pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,57 +1,32 @@
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{form_builder::FormBuilder, Request, ResponseResult}, requests::{form_builder::FormBuilder, Request, ResponseResult},
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup}, types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
Bot, Bot,
}; };
/// Use this method to send video files, Telegram clients support mp4 videos /// Use this method to send video files, Telegram clients support mp4 videos
/// (other formats may be sent as Document). On success, the sent Message is /// (other formats may be sent as Document).
/// returned. Bots can currently send video files of up to 50 MB in size, this ///
/// Bots can currently send video files of up to 50 MB in size, this
/// limit may be changed in the future. /// limit may be changed in the future.
#[derive(Debug, Clone)] ///
/// [The official docs](https://core.telegram.org/bots/api#sendvideo).
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendVideo<'a> { pub struct SendVideo<'a> {
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Video to send. Pass a file_id as String to send a video that exists on
/// the Telegram servers (recommended), pass an HTTP URL as a String for
/// Telegram to get a video from the Internet, or upload a new video using
/// multipart/form-data. More info on Sending Files »
video: InputFile, video: InputFile,
/// Duration of sent video in seconds
duration: Option<i32>, duration: Option<i32>,
/// Video width
width: Option<i32>, width: Option<i32>,
/// Video height
height: Option<i32>, height: Option<i32>,
/// Thumbnail of the file sent; can be ignored if thumbnail generation for
/// the file is supported server-side. The thumbnail should be in JPEG
/// format and less than 200 kB in size. A thumbnails width and height
/// should not exceed 320. Ignored if the file is not uploaded using
/// multipart/form-data. Thumbnails cant be reused and can be only
/// uploaded as a new file, so you can pass “attach://<file_attach_name>”
/// if the thumbnail was uploaded using multipart/form-data under
/// <file_attach_name>. More info on Sending Files »
thumb: Option<InputFile>, thumb: Option<InputFile>,
/// Video caption (may also be used when resending videos by file_id),
/// 0-1024 characters
caption: Option<String>, caption: Option<String>,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in the media caption.
parse_mode: Option<ParseMode>, parse_mode: Option<ParseMode>,
/// Pass True, if the uploaded video is suitable for streaming
supports_streaming: Option<bool>, supports_streaming: Option<bool>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>, disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>, reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>, reply_markup: Option<ReplyMarkup>,
} }
@ -60,7 +35,7 @@ impl Request for SendVideo<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_multipart( net::request_multipart(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendVideo", "sendVideo",
@ -101,7 +76,7 @@ impl<'a> SendVideo<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
Self { Self {
bot, bot: BotWrapper(bot),
chat_id: chat_id.into(), chat_id: chat_id.into(),
video, video,
duration: None, duration: None,
@ -117,6 +92,8 @@ impl<'a> SendVideo<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -125,31 +102,58 @@ impl<'a> SendVideo<'a> {
self self
} }
/// Video to sent.
///
/// Pass [`InputFile::File`] to send a file that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
pub fn video(mut self, val: InputFile) -> Self { pub fn video(mut self, val: InputFile) -> Self {
self.video = val; self.video = val;
self self
} }
/// Duration of sent video in seconds.
pub fn duration(mut self, val: i32) -> Self { pub fn duration(mut self, val: i32) -> Self {
self.duration = Some(val); self.duration = Some(val);
self self
} }
/// Video width.
pub fn width(mut self, val: i32) -> Self { pub fn width(mut self, val: i32) -> Self {
self.width = Some(val); self.width = Some(val);
self self
} }
/// Video height.
pub fn height(mut self, val: i32) -> Self { pub fn height(mut self, val: i32) -> Self {
self.height = Some(val); self.height = Some(val);
self self
} }
/// Thumbnail of the file sent; can be ignored if thumbnail generation for
/// the file is supported server-side.
///
/// The thumbnail should be in JPEG format and less than 200 kB in size. A
/// thumbnails width and height should not exceed 320. Ignored if the
/// file is not uploaded using `multipart/form-data`. Thumbnails cant be
/// reused and can be only uploaded as a new file, so you can pass
/// `attach://<file_attach_name>` if the thumbnail was uploaded using
/// `multipart/form-data` under `<file_attach_name>`. [More info on Sending
/// Files »].
///
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn thumb(mut self, val: InputFile) -> Self { pub fn thumb(mut self, val: InputFile) -> Self {
self.thumb = Some(val); self.thumb = Some(val);
self self
} }
/// Video caption (may also be used when resending videos by file_id),
/// 0-1024 characters.
pub fn caption<T>(mut self, val: T) -> Self pub fn caption<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -158,26 +162,47 @@ impl<'a> SendVideo<'a> {
self self
} }
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, val: ParseMode) -> Self { pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val); self.parse_mode = Some(val);
self self
} }
/// Pass `true`, if the uploaded video is suitable for streaming.
pub fn supports_streaming(mut self, val: bool) -> Self { pub fn supports_streaming(mut self, val: bool) -> Self {
self.supports_streaming = Some(val); self.supports_streaming = Some(val);
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self
} }
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self { pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val); self.reply_to_message_id = Some(val);
self self
} }
/// Additional interface options.
///
/// A JSON-serialized object for an [inline keyboard], [custom reply
/// keyboard], instructions to remove reply keyboard or to force a reply
/// from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self { pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,46 +1,27 @@
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{form_builder::FormBuilder, Request, ResponseResult}, requests::{form_builder::FormBuilder, Request, ResponseResult},
types::{ChatId, InputFile, Message, ReplyMarkup}, types::{ChatId, InputFile, Message, ReplyMarkup},
Bot, Bot,
}; };
/// As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 /// As of [v.4.0], Telegram clients support rounded square mp4 videos of up to 1
/// minute long. Use this method to send video messages. On success, the sent /// minute long. Use this method to send video messages.
/// Message is returned. ///
#[derive(Debug, Clone)] /// [The official docs](https://core.telegram.org/bots/api#sendvideonote).
///
/// [v.4.0]: https://telegram.org/blog/video-messages-and-telescope
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendVideoNote<'a> { pub struct SendVideoNote<'a> {
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Video note to send. Pass a file_id as String to send a video note that
/// exists on the Telegram servers (recommended) or upload a new video
/// using multipart/form-data. More info on Sending Files ». Sending video
/// notes by a URL is currently unsupported
video_note: InputFile, video_note: InputFile,
/// Duration of sent video in seconds
duration: Option<i32>, duration: Option<i32>,
/// Video width and height, i.e. diameter of the video message
length: Option<i32>, length: Option<i32>,
/// Thumbnail of the file sent; can be ignored if thumbnail generation for
/// the file is supported server-side. The thumbnail should be in JPEG
/// format and less than 200 kB in size. A thumbnails width and height
/// should not exceed 320. Ignored if the file is not uploaded using
/// multipart/form-data. Thumbnails cant be reused and can be only
/// uploaded as a new file, so you can pass “attach://<file_attach_name>”
/// if the thumbnail was uploaded using multipart/form-data under
/// <file_attach_name>. More info on Sending Files »
thumb: Option<InputFile>, thumb: Option<InputFile>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>, disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>, reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>, reply_markup: Option<ReplyMarkup>,
} }
@ -49,7 +30,7 @@ impl Request for SendVideoNote<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_multipart( net::request_multipart(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendVideoNote", "sendVideoNote",
@ -86,7 +67,7 @@ impl<'a> SendVideoNote<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
Self { Self {
bot, bot: BotWrapper(bot),
chat_id: chat_id.into(), chat_id: chat_id.into(),
video_note, video_note,
duration: None, duration: None,
@ -98,6 +79,8 @@ impl<'a> SendVideoNote<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -106,36 +89,72 @@ impl<'a> SendVideoNote<'a> {
self self
} }
/// Video note to send.
///
/// Pass [`InputFile::File`] to send a file that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn video_note(mut self, val: InputFile) -> Self { pub fn video_note(mut self, val: InputFile) -> Self {
self.video_note = val; self.video_note = val;
self self
} }
/// Duration of sent video in seconds.
pub fn duration(mut self, val: i32) -> Self { pub fn duration(mut self, val: i32) -> Self {
self.duration = Some(val); self.duration = Some(val);
self self
} }
/// Video width and height, i.e. diameter of the video message.
pub fn length(mut self, val: i32) -> Self { pub fn length(mut self, val: i32) -> Self {
self.length = Some(val); self.length = Some(val);
self self
} }
/// Thumbnail of the file sent; can be ignored if thumbnail generation for
/// the file is supported server-side.
///
/// The thumbnail should be in JPEG format and less than 200 kB in size. A
/// thumbnails width and height should not exceed 320. Ignored if the
/// file is not uploaded using `multipart/form-data`. Thumbnails cant
/// be reused and can be only uploaded as a new file, so you can pass
/// `attach://<file_attach_name>` if the thumbnail was uploaded using
/// `multipart/form-data` under `<file_attach_name>`. [More info on
/// Sending Files »].
pub fn thumb(mut self, val: InputFile) -> Self { pub fn thumb(mut self, val: InputFile) -> Self {
self.thumb = Some(val); self.thumb = Some(val);
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self
} }
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self { pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val); self.reply_to_message_id = Some(val);
self self
} }
/// Additional interface options.
///
/// A JSON-serialized object for an [inline keyboard], [custom reply
/// keyboard], instructions to remove reply keyboard or to force a reply
/// from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self { pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,43 +1,33 @@
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{form_builder::FormBuilder, Request, ResponseResult}, requests::{form_builder::FormBuilder, Request, ResponseResult},
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup}, types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
Bot, Bot,
}; };
/// Use this method to send audio files, if you want Telegram clients to display /// Use this method to send audio files, if you want Telegram clients to display
/// the file as a playable voice message. For this to work, your audio must be /// the file as a playable voice message.
/// in an .ogg file encoded with OPUS (other formats may be sent as Audio or ///
/// Document). On success, the sent Message is returned. Bots can currently send /// For this to work, your audio must be in an .ogg file encoded with OPUS
/// voice messages of up to 50 MB in size, this limit may be changed in the /// (other formats may be sent as [`Audio`] or [`Document`]). Bots can currently
/// send voice messages of up to 50 MB in size, this limit may be changed in the
/// future. /// future.
#[derive(Debug, Clone)] ///
/// [The official docs](https://core.telegram.org/bots/api#sendvoice).
///
/// [`Audio`]: crate::types::Audio
/// [`Document`]: crate::types::Document
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SendVoice<'a> { pub struct SendVoice<'a> {
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Audio file to send. Pass a file_id as String to send a file that exists
/// on the Telegram servers (recommended), pass an HTTP URL as a String for
/// Telegram to get a file from the Internet, or upload a new one using
/// multipart/form-data. More info on Sending Files »
voice: InputFile, voice: InputFile,
/// Voice message caption, 0-1024 characters
caption: Option<String>, caption: Option<String>,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in the media caption.
parse_mode: Option<ParseMode>, parse_mode: Option<ParseMode>,
/// Duration of the voice message in seconds
duration: Option<i32>, duration: Option<i32>,
/// Sends the message silently. Users will receive a notification with no
/// sound.
disable_notification: Option<bool>, disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
reply_to_message_id: Option<i32>, reply_to_message_id: Option<i32>,
/// Additional interface options. A JSON-serialized object for an inline
/// keyboard, custom reply keyboard, instructions to remove reply keyboard
/// or to force a reply from the user.
reply_markup: Option<ReplyMarkup>, reply_markup: Option<ReplyMarkup>,
} }
@ -46,7 +36,7 @@ impl Request for SendVoice<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_multipart( net::request_multipart(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendVoice", "sendVoice",
@ -79,7 +69,7 @@ impl<'a> SendVoice<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
Self { Self {
bot, bot: BotWrapper(bot),
chat_id: chat_id.into(), chat_id: chat_id.into(),
voice, voice,
caption: None, caption: None,
@ -91,6 +81,8 @@ impl<'a> SendVoice<'a> {
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -99,11 +91,23 @@ impl<'a> SendVoice<'a> {
self self
} }
/// Audio file to send.
///
/// Pass [`InputFile::File`] to send a file that exists on
/// the Telegram servers (recommended), pass an [`InputFile::Url`] for
/// Telegram to get a .webp file from the Internet, or upload a new one
/// using [`InputFile::FileId`]. [More info on Sending Files »].
///
/// [`InputFile::File`]: crate::types::InputFile::File
/// [`InputFile::Url`]: crate::types::InputFile::Url
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn voice(mut self, val: InputFile) -> Self { pub fn voice(mut self, val: InputFile) -> Self {
self.voice = val; self.voice = val;
self self
} }
/// Voice message caption, 0-1024 characters.
pub fn caption<T>(mut self, val: T) -> Self pub fn caption<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -112,26 +116,47 @@ impl<'a> SendVoice<'a> {
self self
} }
/// Send [Markdown] or [HTML], if you want Telegram apps to show
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
///
/// [Markdown]: crate::types::ParseMode::Markdown
/// [HTML]: crate::types::ParseMode::HTML
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::types::ParseMode
pub fn parse_mode(mut self, val: ParseMode) -> Self { pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val); self.parse_mode = Some(val);
self self
} }
/// Duration of the voice message in seconds.
pub fn duration(mut self, val: i32) -> Self { pub fn duration(mut self, val: i32) -> Self {
self.duration = Some(val); self.duration = Some(val);
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_notification(mut self, val: bool) -> Self { pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val); self.disable_notification = Some(val);
self self
} }
/// If the message is a reply, ID of the original message.
pub fn reply_to_message_id(mut self, val: i32) -> Self { pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val); self.reply_to_message_id = Some(val);
self self
} }
/// Additional interface options.
///
/// A JSON-serialized object for an [inline keyboard], [custom reply
/// keyboard], instructions to remove reply keyboard or to force a reply
/// from the user.
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
/// [custom reply keyboard]: https://core.telegram.org/bots#keyboards
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self { pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,7 +1,8 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, True}, types::{ChatId, True},
Bot, Bot,
@ -9,22 +10,16 @@ use crate::{
/// Use this method to set a custom title for an administrator in a supergroup /// Use this method to set a custom title for an administrator in a supergroup
/// promoted by the bot. /// promoted by the bot.
///
/// [The official docs](https://core.telegram.org/bots/api#setchatadministratorcustomtitle).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetChatAdministratorCustomTitle<'a> { pub struct SetChatAdministratorCustomTitle<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
chat_id: ChatId,
/// Unique identifier for the target chat or username of the target user_id: i32,
/// supergroup (in the format `@supergroupusername`) custom_title: String,
pub chat_id: ChatId,
/// Unique identifier of the target user
pub user_id: i32,
/// New custom title for the administrator; 0-16 characters, emoji are not
/// allowed
pub custom_title: String,
} }
#[async_trait::async_trait] #[async_trait::async_trait]
@ -32,7 +27,7 @@ impl Request for SetChatAdministratorCustomTitle<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"setChatAdministratorCustomTitle", "setChatAdministratorCustomTitle",
@ -56,13 +51,15 @@ impl<'a> SetChatAdministratorCustomTitle<'a> {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
let custom_title = custom_title.into(); let custom_title = custom_title.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
user_id, user_id,
custom_title, custom_title,
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -71,11 +68,14 @@ impl<'a> SetChatAdministratorCustomTitle<'a> {
self self
} }
/// Unique identifier of the target user.
pub fn user_id(mut self, val: i32) -> Self { pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val; self.user_id = val;
self self
} }
/// New custom title for the administrator; 0-16 characters, emoji are not
/// allowed.
pub fn custom_title<T>(mut self, val: T) -> Self pub fn custom_title<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,

View file

@ -1,25 +1,26 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, True}, types::{ChatId, True},
Bot, Bot,
}; };
/// Use this method to change the description of a group, a supergroup or a /// Use this method to change the description of a group, a supergroup or a
/// channel. The bot must be an administrator in the chat for this to work and /// channel.
/// must have the appropriate admin rights. Returns True on success. ///
/// The bot must be an administrator in the chat for this to work and must have
/// the appropriate admin rights.
///
/// [The official docs](https://core.telegram.org/bots/api#setchatdescription).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetChatDescription<'a> { pub struct SetChatDescription<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// New chat description, 0-255 characters
description: Option<String>, description: Option<String>,
} }
@ -28,7 +29,7 @@ impl Request for SetChatDescription<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"setChatDescription", "setChatDescription",
@ -45,12 +46,14 @@ impl<'a> SetChatDescription<'a> {
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
description: None, description: None,
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -59,6 +62,7 @@ impl<'a> SetChatDescription<'a> {
self self
} }
/// New chat description, 0-255 characters.
pub fn description<T>(mut self, val: T) -> Self pub fn description<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,

View file

@ -1,25 +1,25 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, ChatPermissions, True}, types::{ChatId, ChatPermissions, True},
Bot, Bot,
}; };
/// Use this method to set default chat permissions for all members. The bot /// Use this method to set default chat permissions for all members.
/// must be an administrator in the group or a supergroup for this to work and ///
/// must have the can_restrict_members admin rights. Returns True on success. /// The bot must be an administrator in the group or a supergroup for this to
/// work and must have the can_restrict_members admin rights.
///
/// [The official docs](https://core.telegram.org/bots/api#setchatpermissions).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetChatPermissions<'a> { pub struct SetChatPermissions<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format @supergroupusername)
chat_id: ChatId, chat_id: ChatId,
/// New default chat permissions
permissions: ChatPermissions, permissions: ChatPermissions,
} }
@ -28,7 +28,7 @@ impl Request for SetChatPermissions<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"sendChatPermissions", "sendChatPermissions",
@ -49,12 +49,14 @@ impl<'a> SetChatPermissions<'a> {
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
permissions, permissions,
} }
} }
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format `@supergroupusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -63,6 +65,7 @@ impl<'a> SetChatPermissions<'a> {
self self
} }
/// New default chat permissions.
pub fn permissions(mut self, val: ChatPermissions) -> Self { pub fn permissions(mut self, val: ChatPermissions) -> Self {
self.permissions = val; self.permissions = val;
self self

View file

@ -1,26 +1,25 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, InputFile, True}, types::{ChatId, InputFile, True},
Bot, Bot,
}; };
/// Use this method to set a new profile photo for the chat. Photos can't be /// Use this method to set a new profile photo for the chat.
/// changed for private chats. The bot must be an administrator in the chat for ///
/// this to work and must have the appropriate admin rights. Returns True on /// Photos can't be changed for private chats. The bot must be an administrator
/// success. /// in the chat for this to work and must have the appropriate admin rights.
///
/// [The official docs](https://core.telegram.org/bots/api#setchatphoto).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetChatPhoto<'a> { pub struct SetChatPhoto<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// New chat photo, uploaded using multipart/form-data
photo: InputFile, photo: InputFile,
} }
@ -29,7 +28,7 @@ impl Request for SetChatPhoto<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"setChatPhoto", "setChatPhoto",
@ -46,12 +45,14 @@ impl<'a> SetChatPhoto<'a> {
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
photo, photo,
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -60,6 +61,7 @@ impl<'a> SetChatPhoto<'a> {
self self
} }
/// New chat photo, uploaded using `multipart/form-data`.
pub fn photo(mut self, val: InputFile) -> Self { pub fn photo(mut self, val: InputFile) -> Self {
self.photo = val; self.photo = val;
self self

View file

@ -1,27 +1,26 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, True}, types::{ChatId, True},
Bot, Bot,
}; };
/// Use this method to set a new group sticker set for a supergroup. The bot /// Use this method to set a new group sticker set for a supergroup.
/// must be an administrator in the chat for this to work and must have the ///
/// appropriate admin rights. Use the field can_set_sticker_set optionally /// The bot must be an administrator in the chat for this to work and must have
/// the appropriate admin rights. Use the field can_set_sticker_set optionally
/// returned in getChat requests to check if the bot can use this method. /// returned in getChat requests to check if the bot can use this method.
/// Returns True on success. ///
/// [The official docs](https://core.telegram.org/bots/api#setchatstickerset).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetChatStickerSet<'a> { pub struct SetChatStickerSet<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format @supergroupusername)
chat_id: ChatId, chat_id: ChatId,
/// Name of the sticker set to be set as the group sticker set
sticker_set_name: String, sticker_set_name: String,
} }
@ -30,7 +29,7 @@ impl Request for SetChatStickerSet<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"setChatStickerSet", "setChatStickerSet",
@ -53,12 +52,14 @@ impl<'a> SetChatStickerSet<'a> {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
let sticker_set_name = sticker_set_name.into(); let sticker_set_name = sticker_set_name.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
sticker_set_name, sticker_set_name,
} }
} }
/// Unique identifier for the target chat or username of the target
/// supergroup (in the format `@supergroupusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -67,6 +68,7 @@ impl<'a> SetChatStickerSet<'a> {
self self
} }
/// Name of the sticker set to be set as the group sticker set.
pub fn sticker_set_name<T>(mut self, val: T) -> Self pub fn sticker_set_name<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,

View file

@ -1,25 +1,25 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, True}, types::{ChatId, True},
Bot, Bot,
}; };
/// Use this method to change the title of a chat. Titles can't be changed for /// Use this method to change the title of a chat.
/// private chats. The bot must be an administrator in the chat for this to work ///
/// and must have the appropriate admin rights. Returns True on success. /// Titles can't be changed for private chats. The bot must be an administrator
/// in the chat for this to work and must have the appropriate admin rights.
///
/// [The official docs](https://core.telegram.org/bots/api#setchattitle).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetChatTitle<'a> { pub struct SetChatTitle<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// New chat title, 1-255 characters
title: String, title: String,
} }
@ -28,7 +28,7 @@ impl Request for SetChatTitle<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"setChatTitle", "setChatTitle",
@ -47,12 +47,14 @@ impl<'a> SetChatTitle<'a> {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
let title = title.into(); let title = title.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
title, title,
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -61,6 +63,7 @@ impl<'a> SetChatTitle<'a> {
self self
} }
/// New chat title, 1-255 characters.
pub fn title<T>(mut self, val: T) -> Self pub fn title<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,

View file

@ -1,34 +1,34 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatOrInlineMessage, Message}, types::{ChatOrInlineMessage, Message},
Bot, Bot,
}; };
/// Use this method to set the score of the specified user in a game. On /// Use this method to set the score of the specified user in a game.
/// success, if the message was sent by the bot, returns the edited Message, ///
/// otherwise returns True. Returns an error, if the new score is not greater /// On success, if the message was sent by the bot, returns the edited
/// than the user's current score in the chat and force is False. /// [`Message`], otherwise returns [`True`]. Returns an error, if the new score
/// is not greater than the user's current score in the chat and force is
/// `false`.
///
/// [The official docs](https://core.telegram.org/bots/api#setgamescore).
///
/// [`Message`]: crate::types::Message
/// [`True`]: crate::types::True
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetGameScore<'a> { pub struct SetGameScore<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
#[serde(flatten)] #[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage, chat_or_inline_message: ChatOrInlineMessage,
/// User identifier
user_id: i32, user_id: i32,
/// New score, must be non-negative
score: i32, score: i32,
/// Pass True, if the high score is allowed to decrease. This can be useful
/// when fixing mistakes or banning cheaters
force: Option<bool>, force: Option<bool>,
/// Pass True, if the game message should not be automatically edited to
/// include the current scoreboard
disable_edit_message: Option<bool>, disable_edit_message: Option<bool>,
} }
@ -37,7 +37,7 @@ impl Request for SetGameScore<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"setGameScore", "setGameScore",
@ -55,7 +55,7 @@ impl<'a> SetGameScore<'a> {
score: i32, score: i32,
) -> Self { ) -> Self {
Self { Self {
bot, bot: BotWrapper(bot),
chat_or_inline_message, chat_or_inline_message,
user_id, user_id,
score, score,
@ -69,21 +69,30 @@ impl<'a> SetGameScore<'a> {
self self
} }
/// User identifier.
pub fn user_id(mut self, val: i32) -> Self { pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val; self.user_id = val;
self self
} }
/// New score, must be non-negative.
pub fn score(mut self, val: i32) -> Self { pub fn score(mut self, val: i32) -> Self {
self.score = val; self.score = val;
self self
} }
/// Pass `true`, if the high score is allowed to decrease.
///
/// This can be useful when fixing mistakes or banning cheaters.
pub fn force(mut self, val: bool) -> Self { pub fn force(mut self, val: bool) -> Self {
self.force = Some(val); self.force = Some(val);
self self
} }
/// Sends the message [silently]. Users will receive a notification with no
/// sound.
///
/// [silently]: https://telegram.org/blog/channels-2-0#silent-messages
pub fn disable_edit_message(mut self, val: bool) -> Self { pub fn disable_edit_message(mut self, val: bool) -> Self {
self.disable_edit_message = Some(val); self.disable_edit_message = Some(val);
self self

View file

@ -1,23 +1,23 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::True, types::True,
Bot, Bot,
}; };
/// Use this method to move a sticker in a set created by the bot to a specific /// Use this method to move a sticker in a set created by the bot to a specific
/// position . Returns True on success. /// position.
///
/// [The official docs](https://core.telegram.org/bots/api#setstickerpositioninset).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetStickerPositionInSet<'a> { pub struct SetStickerPositionInSet<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// File identifier of the sticker
sticker: String, sticker: String,
/// New sticker position in the set, zero-based
position: i32, position: i32,
} }
@ -26,7 +26,7 @@ impl Request for SetStickerPositionInSet<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"setStickerPositionInSet", "setStickerPositionInSet",
@ -43,12 +43,13 @@ impl<'a> SetStickerPositionInSet<'a> {
{ {
let sticker = sticker.into(); let sticker = sticker.into();
Self { Self {
bot, bot: BotWrapper(bot),
sticker, sticker,
position, position,
} }
} }
/// File identifier of the sticker.
pub fn sticker<T>(mut self, val: T) -> Self pub fn sticker<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -57,6 +58,7 @@ impl<'a> SetStickerPositionInSet<'a> {
self self
} }
/// New sticker position in the set, zero-based.
pub fn position(mut self, val: i32) -> Self { pub fn position(mut self, val: i32) -> Self {
self.position = val; self.position = val;
self self

View file

@ -1,51 +1,38 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{InputFile, True}, types::{AllowedUpdate, InputFile, True},
Bot, Bot,
}; };
/// Use this method to specify a url and receive incoming updates via an /// Use this method to specify a url and receive incoming updates via an
/// outgoing webhook. Whenever there is an update for the bot, we will send an /// outgoing webhook.
///
/// Whenever there is an update for the bot, we will send an
/// HTTPS POST request to the specified url, containing a JSON-serialized /// HTTPS POST request to the specified url, containing a JSON-serialized
/// Update. In case of an unsuccessful request, we will give up after a /// [`Update`]. In case of an unsuccessful request, we will give up after a
/// reasonable amount of attempts. Returns True on success. If you'd like to /// reasonable amount of attempts.
/// make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/<token>. Since nobody else ///
/// knows your bots token, you can be pretty sure its us.Notes1. You will not /// If you'd like to make sure that the Webhook request comes from Telegram,
/// be able to receive updates using getUpdates for as long as an outgoing /// we recommend using a secret path in the URL, e.g.
/// webhook is set up.2. To use a self-signed certificate, you need to upload /// `https://www.example.com/<token>`. Since nobody else knows your bots
/// your public key certificate using certificate parameter. Please upload as /// token, you can be pretty sure its us.
/// InputFile, sending a String will not work.3. Ports currently supported for ///
/// Webhooks: 443, 80, 88, 8443.NEW! If you're having any trouble setting up /// [The official docs](https://core.telegram.org/bots/api#setwebhook).
/// webhooks, please check out this amazing guide to Webhooks. ///
/// [`Update`]: crate::types::Update
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct SetWebhook<'a> { pub struct SetWebhook<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// HTTPS url to send updates to. Use an empty string to remove webhook
/// integration
url: String, url: String,
/// Upload your public key certificate so that the root certificate in use
/// can be checked. See our self-signed guide for details.
certificate: Option<InputFile>, certificate: Option<InputFile>,
/// Maximum allowed number of simultaneous HTTPS connections to the webhook
/// for update delivery, 1-100. Defaults to 40. Use lower values to limit
/// the load on your bots server, and higher values to increase your bots
/// throughput.
max_connections: Option<i32>, max_connections: Option<i32>,
/// List the types of updates you want your bot to receive. For example, allowed_updates: Option<Vec<AllowedUpdate>>,
/// specify [“message”, “edited_channel_post”, “callback_query”] to only
/// receive updates of these types. See Update for a complete list of
/// available update types. Specify an empty list to receive all updates
/// regardless of type (default). If not specified, the previous setting
/// will be used.Please note that this parameter doesn't affect updates
/// created before the call to the setWebhook, so unwanted updates may be
/// received for a short period of time.
allowed_updates: Option<Vec<String>>,
} }
#[async_trait::async_trait] #[async_trait::async_trait]
@ -53,7 +40,7 @@ impl Request for SetWebhook<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"setWebhook", "setWebhook",
@ -70,7 +57,7 @@ impl<'a> SetWebhook<'a> {
{ {
let url = url.into(); let url = url.into();
Self { Self {
bot, bot: BotWrapper(bot),
url, url,
certificate: None, certificate: None,
max_connections: None, max_connections: None,
@ -78,6 +65,9 @@ impl<'a> SetWebhook<'a> {
} }
} }
/// HTTPS url to send updates to.
///
/// Use an empty string to remove webhook integration.
pub fn url<T>(mut self, val: T) -> Self pub fn url<T>(mut self, val: T) -> Self
where where
T: Into<String>, T: Into<String>,
@ -86,19 +76,50 @@ impl<'a> SetWebhook<'a> {
self self
} }
/// Upload your public key certificate so that the root certificate in use
/// can be checked.
///
/// See our [self-signed guide] for details.
///
/// [self-signed guide]: https://core.telegram.org/bots/self-signed
pub fn certificate(mut self, val: InputFile) -> Self { pub fn certificate(mut self, val: InputFile) -> Self {
self.certificate = Some(val); self.certificate = Some(val);
self self
} }
/// Maximum allowed number of simultaneous HTTPS connections to the webhook
/// for update delivery, 1-100.
///
/// Defaults to 40. Use lower values to limit the load on your bots server,
/// and higher values to increase your bots throughput.
pub fn max_connections(mut self, val: i32) -> Self { pub fn max_connections(mut self, val: i32) -> Self {
self.max_connections = Some(val); self.max_connections = Some(val);
self self
} }
/// List the types of updates you want your bot to receive.
///
/// For example, specify [`AllowedUpdate::Message`],
/// [`AllowedUpdate::EditedChannelPost`], [`AllowedUpdate::CallbackQuery`]
/// to only receive updates of these types. Specify an empty list to receive
/// all updates regardless of type (default). If not specified, the
/// previous setting will be used. See [`AllowedUpdate`] for a complete list
/// of available update types.
///
/// Please note that this parameter doesn't affect updates created before
/// the call to the [`Bot::set_webhook`], so unwanted updates may be
/// received for a short period of time.
///
/// [`Bot::set_webhook`]: crate::Bot::set_webhook
/// [`AllowedUpdate::Message`]: crate::types::AllowedUpdate::Message
/// [`AllowedUpdate::EditedChannelPost`]:
/// crate::types::AllowedUpdate::EditedChannelPost
/// [`AllowedUpdate::CallbackQuery`]:
/// crate::types::AllowedUpdate::CallbackQuery
/// [`AllowedUpdate`]: crate::types::AllowedUpdate
pub fn allowed_updates<T>(mut self, val: T) -> Self pub fn allowed_updates<T>(mut self, val: T) -> Self
where where
T: Into<Vec<String>>, T: Into<Vec<AllowedUpdate>>,
{ {
self.allowed_updates = Some(val.into()); self.allowed_updates = Some(val.into());
self self

View file

@ -1,25 +1,30 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message},
Bot, Bot,
}; };
/// Use this method to stop updating a live location message before live_period /// Use this method to stop updating a live location message before
/// expires. On success, if the message was sent by the bot, the sent Message is /// `live_period` expires.
/// returned, otherwise True is returned. ///
/// On success, if the message was sent by the bot, the sent [`Message`] is
/// returned, otherwise [`True`] is returned.
///
/// [The official docs](https://core.telegram.org/bots/api#stopmessagelivelocation).
///
/// [`Message`]: crate::types::Message
/// [`True`]: crate::types::True
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct StopMessageLiveLocation<'a> { pub struct StopMessageLiveLocation<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
#[serde(flatten)] #[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage, chat_or_inline_message: ChatOrInlineMessage,
/// A JSON-serialized object for a new inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>, reply_markup: Option<InlineKeyboardMarkup>,
} }
@ -28,7 +33,7 @@ impl Request for StopMessageLiveLocation<'_> {
type Output = Message; type Output = Message;
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"stopMessageLiveLocation", "stopMessageLiveLocation",
@ -44,7 +49,7 @@ impl<'a> StopMessageLiveLocation<'a> {
chat_or_inline_message: ChatOrInlineMessage, chat_or_inline_message: ChatOrInlineMessage,
) -> Self { ) -> Self {
Self { Self {
bot, bot: BotWrapper(bot),
chat_or_inline_message, chat_or_inline_message,
reply_markup: None, reply_markup: None,
} }
@ -55,6 +60,9 @@ impl<'a> StopMessageLiveLocation<'a> {
self self
} }
/// A JSON-serialized object for a new [inline keyboard].
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,26 +1,23 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, InlineKeyboardMarkup, Poll}, types::{ChatId, InlineKeyboardMarkup, Poll},
Bot, Bot,
}; };
/// Use this method to stop a poll which was sent by the bot. On success, the /// Use this method to stop a poll which was sent by the bot.
/// stopped Poll with the final results is returned. ///
/// [The official docs](https://core.telegram.org/bots/api#stoppoll).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct StopPoll<'a> { pub struct StopPoll<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
/// Identifier of the original message with the poll
message_id: i32, message_id: i32,
/// A JSON-serialized object for a new message inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>, reply_markup: Option<InlineKeyboardMarkup>,
} }
@ -28,8 +25,11 @@ pub struct StopPoll<'a> {
impl Request for StopPoll<'_> { impl Request for StopPoll<'_> {
type Output = Poll; type Output = Poll;
/// On success, the stopped [`Poll`] with the final results is returned.
///
/// [`Poll`]: crate::types::Poll
async fn send(&self) -> ResponseResult<Poll> { async fn send(&self) -> ResponseResult<Poll> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"stopPoll", "stopPoll",
@ -45,13 +45,15 @@ impl<'a> StopPoll<'a> {
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
message_id, message_id,
reply_markup: None, reply_markup: None,
} }
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -60,11 +62,15 @@ impl<'a> StopPoll<'a> {
self self
} }
/// Identifier of the original message with the poll.
pub fn message_id(mut self, val: i32) -> Self { pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val; self.message_id = val;
self self
} }
/// A JSON-serialized object for a new [inline keyboard].
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self { pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val); self.reply_markup = Some(val);
self self

View file

@ -1,26 +1,25 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, True}, types::{ChatId, True},
Bot, Bot,
}; };
/// Use this method to unban a previously kicked user in a supergroup or /// Use this method to unban a previously kicked user in a supergroup or
/// channel. The user will not return to the group or channel automatically, but /// channel. The user will **not** return to the group or channel automatically,
/// will be able to join via link, etc. The bot must be an administrator for /// but will be able to join via link, etc. The bot must be an administrator for
/// this to work. Returns True on success. /// this to work.
///
/// [The official docs](https://core.telegram.org/bots/api#unbanchatmember).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct UnbanChatMember<'a> { pub struct UnbanChatMember<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target group or username of the target
/// supergroup or channel (in the format @username)
chat_id: ChatId, chat_id: ChatId,
/// Unique identifier of the target user
user_id: i32, user_id: i32,
} }
@ -29,7 +28,7 @@ impl Request for UnbanChatMember<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"unbanChatMember", "unbanChatMember",
@ -46,12 +45,14 @@ impl<'a> UnbanChatMember<'a> {
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { Self {
bot, bot: BotWrapper(bot),
chat_id, chat_id,
user_id, user_id,
} }
} }
/// Unique identifier for the target group or username of the target
/// supergroup or channel (in the format `@username`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
@ -60,6 +61,7 @@ impl<'a> UnbanChatMember<'a> {
self self
} }
/// Unique identifier of the target user.
pub fn user_id(mut self, val: i32) -> Self { pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val; self.user_id = val;
self self

View file

@ -1,24 +1,25 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, True}, types::{ChatId, True},
Bot, Bot,
}; };
/// Use this method to unpin a message in a group, a supergroup, or a channel. /// Use this method to unpin a message in a group, a supergroup, or a channel.
///
/// The bot must be an administrator in the chat for this to work and must have /// The bot must be an administrator in the chat for this to work and must have
/// the can_pin_messages admin right in the supergroup or can_edit_messages /// the `can_pin_messages` admin right in the supergroup or `can_edit_messages`
/// admin right in the channel. Returns True on success. /// admin right in the channel.
///
/// [The official docs](https://core.telegram.org/bots/api#unpinchatmessage).
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct UnpinChatMessage<'a> { pub struct UnpinChatMessage<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId, chat_id: ChatId,
} }
@ -27,7 +28,7 @@ impl Request for UnpinChatMessage<'_> {
type Output = True; type Output = True;
async fn send(&self) -> ResponseResult<True> { async fn send(&self) -> ResponseResult<True> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"unpinChatMessage", "unpinChatMessage",
@ -43,9 +44,14 @@ impl<'a> UnpinChatMessage<'a> {
C: Into<ChatId>, C: Into<ChatId>,
{ {
let chat_id = chat_id.into(); let chat_id = chat_id.into();
Self { bot, chat_id } Self {
bot: BotWrapper(bot),
chat_id,
}
} }
/// Unique identifier for the target chat or username of the target channel
/// (in the format `@channelusername`).
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_id<T>(mut self, val: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,

View file

@ -1,26 +1,27 @@
use serde::Serialize; use serde::Serialize;
use super::BotWrapper;
use crate::{ use crate::{
network, net,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{File, InputFile}, types::{File, InputFile},
Bot, Bot,
}; };
/// Use this method to upload a .png file with a sticker for later use in /// Use this method to upload a .png file with a sticker for later use in
/// createNewStickerSet and addStickerToSet methods (can be used multiple /// [`Bot::create_new_sticker_set`] and [`Bot::add_sticker_to_set`] methods (can
/// times). Returns the uploaded File on success. /// be used multiple times).
///
/// [The official docs](https://core.telegram.org/bots/api#uploadstickerfile).
///
/// [`Bot::create_new_sticker_set`]: crate::Bot::create_new_sticker_set
/// [`Bot::add_sticker_to_set`]: crate::Bot::add_sticker_to_set
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)] #[derive(Eq, PartialEq, Debug, Clone, Serialize)]
pub struct UploadStickerFile<'a> { pub struct UploadStickerFile<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: BotWrapper<'a>,
/// User identifier of sticker file owner
user_id: i32, user_id: i32,
/// Png image with the sticker, must be up to 512 kilobytes in size,
/// dimensions must not exceed 512px, and either width or height must be
/// exactly 512px. More info on Sending Files »
png_sticker: InputFile, png_sticker: InputFile,
} }
#[async_trait::async_trait] #[async_trait::async_trait]
@ -28,7 +29,7 @@ impl Request for UploadStickerFile<'_> {
type Output = File; type Output = File;
async fn send(&self) -> ResponseResult<File> { async fn send(&self) -> ResponseResult<File> {
network::request_json( net::request_json(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"uploadStickerFile", "uploadStickerFile",
@ -45,17 +46,23 @@ impl<'a> UploadStickerFile<'a> {
png_sticker: InputFile, png_sticker: InputFile,
) -> Self { ) -> Self {
Self { Self {
bot, bot: BotWrapper(bot),
user_id, user_id,
png_sticker, png_sticker,
} }
} }
/// User identifier of sticker file owner.
pub fn user_id(mut self, val: i32) -> Self { pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val; self.user_id = val;
self self
} }
/// **Png** image with the sticker, must be up to 512 kilobytes in size,
/// dimensions must not exceed 512px, and either width or height must be
/// exactly 512px. [More info on Sending Files »].
///
/// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files
pub fn png_sticker(mut self, val: InputFile) -> Self { pub fn png_sticker(mut self, val: InputFile) -> Self {
self.png_sticker = val; self.png_sticker = val;
self self

View file

@ -9,10 +9,10 @@ use super::PassportFile;
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct EncryptedPassportElement { pub struct EncryptedPassportElement {
/// Base64-encoded element hash for using in /// Base64-encoded element hash for using in
/// [`PassportElementErrorUnspecified`]. /// [`PassportElementErrorKind::Unspecified`].
/// ///
/// [`PassportElementErrorUnspecified`]: /// [`PassportElementErrorKind::Unspecified`]:
/// crate::types::PassportElementErrorUnspecified /// crate::types::PassportElementErrorKind::Unspecified
pub hash: String, pub hash: String,
#[serde(flatten)] #[serde(flatten)]