mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 09:49:07 +01:00
Merge pull request #28 from async-telegram-bot/reformatting
Reformatting
This commit is contained in:
commit
e7edb29fc3
111 changed files with 663 additions and 633 deletions
116
src/bot/api.rs
Normal file
116
src/bot/api.rs
Normal file
|
@ -0,0 +1,116 @@
|
|||
use crate::{
|
||||
bot::Bot,
|
||||
requests::{
|
||||
edit_message_live_location::EditMessageLiveLocation,
|
||||
forward_message::ForwardMessage, get_file::GetFile, get_me::GetMe,
|
||||
send_audio::SendAudio, send_location::SendLocation,
|
||||
send_media_group::SendMediaGroup, send_message::SendMessage,
|
||||
send_photo::SendPhoto,
|
||||
stop_message_live_location::StopMessageLiveLocation, ChatId,
|
||||
},
|
||||
types::{InputFile, InputMedia},
|
||||
};
|
||||
|
||||
/// Telegram functions
|
||||
impl Bot {
|
||||
pub fn get_me(&self) -> GetMe {
|
||||
GetMe::new(self.ctx())
|
||||
}
|
||||
|
||||
pub fn send_message<C, T>(&self, chat_id: C, text: T) -> SendMessage
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
T: Into<String>,
|
||||
{
|
||||
SendMessage::new(self.ctx(), chat_id.into(), text.into())
|
||||
}
|
||||
|
||||
pub fn edit_message_live_location<Lt, Lg>(
|
||||
&self,
|
||||
latitude: Lt,
|
||||
longitude: Lg,
|
||||
) -> EditMessageLiveLocation
|
||||
where
|
||||
Lt: Into<f64>,
|
||||
Lg: Into<f64>,
|
||||
{
|
||||
EditMessageLiveLocation::new(
|
||||
self.ctx(),
|
||||
latitude.into(),
|
||||
longitude.into(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn forward_message<C, F, M>(
|
||||
&self,
|
||||
chat_id: C,
|
||||
from_chat_id: F,
|
||||
message_id: M,
|
||||
) -> ForwardMessage
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
F: Into<ChatId>,
|
||||
M: Into<i32>,
|
||||
{
|
||||
ForwardMessage::new(
|
||||
self.ctx(),
|
||||
chat_id.into(),
|
||||
from_chat_id.into(),
|
||||
message_id.into(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn send_audio<C, A>(&self, chat_id: C, audio: A) -> SendAudio
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
A: Into<InputFile>,
|
||||
{
|
||||
SendAudio::new(self.ctx(), chat_id.into(), audio.into())
|
||||
}
|
||||
|
||||
pub fn send_location<C, Lt, Lg>(
|
||||
&self,
|
||||
chat_id: C,
|
||||
latitude: Lt,
|
||||
longitude: Lg,
|
||||
) -> SendLocation
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
Lt: Into<f64>,
|
||||
Lg: Into<f64>,
|
||||
{
|
||||
SendLocation::new(
|
||||
self.ctx(),
|
||||
chat_id.into(),
|
||||
latitude.into(),
|
||||
longitude.into(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn send_media_group<C, M>(&self, chat_id: C, media: M) -> SendMediaGroup
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
M: Into<Vec<InputMedia>>,
|
||||
{
|
||||
SendMediaGroup::new(self.ctx(), chat_id.into(), media.into())
|
||||
}
|
||||
|
||||
pub fn send_photo<C, P>(&self, chat_id: C, photo: P) -> SendPhoto
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
P: Into<InputFile>,
|
||||
{
|
||||
SendPhoto::new(self.ctx(), chat_id.into(), photo.into())
|
||||
}
|
||||
|
||||
pub fn stop_message_live_location(&self) -> StopMessageLiveLocation {
|
||||
StopMessageLiveLocation::new(self.ctx())
|
||||
}
|
||||
|
||||
pub fn get_file<F>(&self, file_id: F) -> GetFile
|
||||
where
|
||||
F: Into<String>,
|
||||
{
|
||||
GetFile::new(self.ctx(), file_id.into())
|
||||
}
|
||||
}
|
65
src/bot/download.rs
Normal file
65
src/bot/download.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
use reqwest::r#async::Chunk;
|
||||
use tokio::{io::AsyncWrite, stream::Stream};
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network::{download_file, download_file_stream},
|
||||
DownloadError,
|
||||
};
|
||||
|
||||
impl Bot {
|
||||
/// Download file from telegram into `destination`.
|
||||
/// `path` can be obtained from [`get_file`] method.
|
||||
///
|
||||
/// For downloading as Stream of Chunks see [`download_file_stream`].
|
||||
///
|
||||
/// ## Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// use async_telegram_bot::{
|
||||
/// bot::Bot, requests::Request, types::File as TgFile,
|
||||
/// };
|
||||
/// use tokio::fs::File;
|
||||
/// # use async_telegram_bot::RequestError;
|
||||
///
|
||||
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let bot = Bot::new("TOKEN");
|
||||
/// let mut file = File::create("/home/waffle/Pictures/test.png").await?;
|
||||
///
|
||||
/// let TgFile { file_path, .. } = bot.get_file("*file_id*").send().await?;
|
||||
/// bot.download_file(&file_path, &mut file).await?;
|
||||
/// # Ok(()) }
|
||||
/// ```
|
||||
///
|
||||
/// [`get_file`]: crate::bot::Bot::get_file
|
||||
/// [`download_file_stream`]: crate::bot::Bot::download_file_stream
|
||||
pub async fn download_file<D>(
|
||||
&self,
|
||||
path: &str,
|
||||
destination: &mut D,
|
||||
) -> Result<(), DownloadError>
|
||||
where
|
||||
D: AsyncWrite + Unpin,
|
||||
{
|
||||
download_file(&self.client, &self.token, path, destination).await
|
||||
}
|
||||
|
||||
/// Download file from telegram.
|
||||
///
|
||||
/// `path` can be obtained from [`get_file`] method.
|
||||
///
|
||||
/// For downloading into [`AsyncWrite`] (e.g. [`tokio::fs::File`])
|
||||
/// see [`download_file`].
|
||||
///
|
||||
/// [`get_file`]: crate::bot::Bot::get_file
|
||||
/// [`AsyncWrite`]: tokio::io::AsyncWrite
|
||||
/// [`tokio::fs::File`]: tokio::fs::File
|
||||
/// [`download_file`]: crate::bot::Bot::download_file
|
||||
pub async fn download_file_stream(
|
||||
&self,
|
||||
path: &str,
|
||||
) -> Result<impl Stream<Item = Result<Chunk, reqwest::Error>>, reqwest::Error>
|
||||
{
|
||||
download_file_stream(&self.client, &self.token, path).await
|
||||
}
|
||||
}
|
184
src/bot/mod.rs
184
src/bot/mod.rs
|
@ -1,28 +1,16 @@
|
|||
mod api;
|
||||
mod download;
|
||||
|
||||
use reqwest::r#async::Client;
|
||||
|
||||
use crate::core::network::{download_file, download_file_stream};
|
||||
use crate::core::requests::get_file::GetFile;
|
||||
use crate::core::{
|
||||
requests::{
|
||||
edit_message_live_location::EditMessageLiveLocation,
|
||||
forward_message::ForwardMessage, get_me::GetMe, send_audio::SendAudio,
|
||||
send_location::SendLocation, send_media_group::SendMediaGroup,
|
||||
send_message::SendMessage, send_photo::SendPhoto,
|
||||
stop_message_live_location::StopMessageLiveLocation, ChatId,
|
||||
RequestContext,
|
||||
},
|
||||
types::{InputFile, InputMedia},
|
||||
};
|
||||
use crate::DownloadError;
|
||||
use reqwest::r#async::Chunk;
|
||||
use tokio::io::AsyncWrite;
|
||||
use tokio::stream::Stream;
|
||||
use crate::requests::RequestContext;
|
||||
|
||||
pub struct Bot {
|
||||
token: String,
|
||||
client: Client,
|
||||
}
|
||||
|
||||
/// Constructors
|
||||
impl Bot {
|
||||
pub fn new(token: &str) -> Self {
|
||||
Bot {
|
||||
|
@ -37,7 +25,9 @@ impl Bot {
|
|||
client,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Bot {
|
||||
fn ctx(&self) -> RequestContext {
|
||||
RequestContext {
|
||||
token: &self.token,
|
||||
|
@ -45,163 +35,3 @@ impl Bot {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Telegram functions
|
||||
impl Bot {
|
||||
/// Download file from telegram into `destination`.
|
||||
/// `path` can be obtained from [`get_file`] method.
|
||||
///
|
||||
/// For downloading as Stream of Chunks see [`download_file_stream`].
|
||||
///
|
||||
/// ## Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// use async_telegram_bot::{
|
||||
/// bot::Bot,
|
||||
/// core::{requests::Request, types::File as TgFile},
|
||||
/// };
|
||||
/// use tokio::fs::File;
|
||||
/// # use async_telegram_bot::core::requests::RequestError;
|
||||
///
|
||||
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let bot = Bot::new("TOKEN");
|
||||
/// let mut file = File::create("/home/waffle/Pictures/test.png").await?;
|
||||
///
|
||||
/// let TgFile { file_path, .. } = bot.get_file("*file_id*").send().await?;
|
||||
/// bot.download_file(&file_path, &mut file).await?;
|
||||
/// # Ok(()) }
|
||||
/// ```
|
||||
///
|
||||
/// [`get_file`]: crate::bot::Bot::get_file
|
||||
/// [`download_file_stream`]: crate::bot::Bot::download_file_stream
|
||||
pub async fn download_file<D>(
|
||||
&self,
|
||||
path: &str,
|
||||
destination: &mut D,
|
||||
) -> Result<(), DownloadError>
|
||||
where
|
||||
D: AsyncWrite + Unpin,
|
||||
{
|
||||
download_file(&self.client, &self.token, path, destination).await
|
||||
}
|
||||
|
||||
/// Download file from telegram.
|
||||
///
|
||||
/// `path` can be obtained from [`get_file`] method.
|
||||
///
|
||||
/// For downloading into [`AsyncWrite`] (e.g. [`tokio::fs::File`])
|
||||
/// see [`download_file`].
|
||||
///
|
||||
/// [`get_file`]: crate::bot::Bot::get_file
|
||||
/// [`AsyncWrite`]: tokio::io::AsyncWrite
|
||||
/// [`tokio::fs::File`]: tokio::fs::File
|
||||
/// [`download_file`]: crate::bot::Bot::download_file
|
||||
pub async fn download_file_stream(
|
||||
&self,
|
||||
path: &str,
|
||||
) -> Result<impl Stream<Item = Result<Chunk, reqwest::Error>>, reqwest::Error>
|
||||
{
|
||||
download_file_stream(&self.client, &self.token, path).await
|
||||
}
|
||||
|
||||
pub fn get_me(&self) -> GetMe {
|
||||
GetMe::new(self.ctx())
|
||||
}
|
||||
|
||||
pub fn send_message<C, T>(&self, chat_id: C, text: T) -> SendMessage
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
T: Into<String>,
|
||||
{
|
||||
SendMessage::new(self.ctx(), chat_id.into(), text.into())
|
||||
}
|
||||
|
||||
pub fn edit_message_live_location<Lt, Lg>(
|
||||
&self,
|
||||
latitude: Lt,
|
||||
longitude: Lg,
|
||||
) -> EditMessageLiveLocation
|
||||
where
|
||||
Lt: Into<f64>,
|
||||
Lg: Into<f64>,
|
||||
{
|
||||
EditMessageLiveLocation::new(
|
||||
self.ctx(),
|
||||
latitude.into(),
|
||||
longitude.into(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn forward_message<C, F, M>(
|
||||
&self,
|
||||
chat_id: C,
|
||||
from_chat_id: F,
|
||||
message_id: M,
|
||||
) -> ForwardMessage
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
F: Into<ChatId>,
|
||||
M: Into<i32>,
|
||||
{
|
||||
ForwardMessage::new(
|
||||
self.ctx(),
|
||||
chat_id.into(),
|
||||
from_chat_id.into(),
|
||||
message_id.into(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn send_audio<C, A>(&self, chat_id: C, audio: A) -> SendAudio
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
A: Into<InputFile>,
|
||||
{
|
||||
SendAudio::new(self.ctx(), chat_id.into(), audio.into())
|
||||
}
|
||||
|
||||
pub fn send_location<C, Lt, Lg>(
|
||||
&self,
|
||||
chat_id: C,
|
||||
latitude: Lt,
|
||||
longitude: Lg,
|
||||
) -> SendLocation
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
Lt: Into<f64>,
|
||||
Lg: Into<f64>,
|
||||
{
|
||||
SendLocation::new(
|
||||
self.ctx(),
|
||||
chat_id.into(),
|
||||
latitude.into(),
|
||||
longitude.into(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn send_media_group<C, M>(&self, chat_id: C, media: M) -> SendMediaGroup
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
M: Into<Vec<InputMedia>>,
|
||||
{
|
||||
SendMediaGroup::new(self.ctx(), chat_id.into(), media.into())
|
||||
}
|
||||
|
||||
pub fn send_photo<C, P>(&self, chat_id: C, photo: P) -> SendPhoto
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
P: Into<InputFile>,
|
||||
{
|
||||
SendPhoto::new(self.ctx(), chat_id.into(), photo.into())
|
||||
}
|
||||
|
||||
pub fn stop_message_live_location(&self) -> StopMessageLiveLocation {
|
||||
StopMessageLiveLocation::new(self.ctx())
|
||||
}
|
||||
|
||||
pub fn get_file<F>(&self, file_id: F) -> GetFile
|
||||
where
|
||||
F: Into<String>,
|
||||
{
|
||||
GetFile::new(self.ctx(), file_id.into())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
pub(crate) mod network;
|
||||
pub mod requests;
|
||||
pub mod types;
|
|
@ -1,204 +0,0 @@
|
|||
use crate::core::{
|
||||
requests::{RequestError, ResponseResult},
|
||||
types::ResponseParameters,
|
||||
};
|
||||
|
||||
use crate::DownloadError;
|
||||
use apply::Apply;
|
||||
use bytes::Buf;
|
||||
use futures::StreamExt;
|
||||
use reqwest::r#async::Chunk;
|
||||
use reqwest::{
|
||||
r#async::{multipart::Form, Client, Response},
|
||||
StatusCode,
|
||||
};
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tokio::prelude::AsyncWrite;
|
||||
use tokio::stream::Stream;
|
||||
|
||||
const TELEGRAM_API_URL: &str = "https://api.telegram.org";
|
||||
|
||||
/// Creates URL for making HTTPS requests. See the [Telegram documentation].
|
||||
///
|
||||
/// [Telegram documentation]: https://core.telegram.org/bots/api#making-requests
|
||||
fn method_url(base: &str, token: &str, method_name: &str) -> String {
|
||||
format!(
|
||||
"{url}/bot{token}/{method}",
|
||||
url = base,
|
||||
token = token,
|
||||
method = method_name,
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates URL for downloading a file. See the [Telegram documentation].
|
||||
///
|
||||
/// [Telegram documentation] (https://core.telegram.org/bots/api#file)
|
||||
fn file_url(base: &str, token: &str, file_path: &str) -> String {
|
||||
format!(
|
||||
"{url}/file/bot{token}/{file}",
|
||||
url = base,
|
||||
token = token,
|
||||
file = file_path,
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn request_multipart<T: DeserializeOwned>(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
method_name: &str,
|
||||
params: Option<Form>,
|
||||
) -> ResponseResult<T> {
|
||||
process_response(
|
||||
client
|
||||
.post(&method_url(TELEGRAM_API_URL, token, method_name))
|
||||
.apply(|request_builder| match params {
|
||||
Some(params) => request_builder.multipart(params),
|
||||
None => request_builder,
|
||||
})
|
||||
.send()
|
||||
.await
|
||||
.map_err(RequestError::NetworkError)?,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn request_json<T: DeserializeOwned, P: Serialize>(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
method_name: &str,
|
||||
params: &P,
|
||||
) -> ResponseResult<T> {
|
||||
process_response(
|
||||
client
|
||||
.post(&method_url(TELEGRAM_API_URL, token, method_name))
|
||||
.json(params)
|
||||
.send()
|
||||
.await
|
||||
.map_err(RequestError::NetworkError)?,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn process_response<T: DeserializeOwned>(
|
||||
mut response: Response,
|
||||
) -> ResponseResult<T> {
|
||||
let response = serde_json::from_str::<TelegramResponse<T>>(
|
||||
&response.text().await.map_err(RequestError::NetworkError)?,
|
||||
)
|
||||
.map_err(RequestError::InvalidJson)?;
|
||||
|
||||
response.into()
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum TelegramResponse<R> {
|
||||
Ok {
|
||||
/// A dummy field. Used only for deserialization.
|
||||
#[allow(dead_code)]
|
||||
ok: bool, // TODO: True type
|
||||
|
||||
result: R,
|
||||
},
|
||||
Err {
|
||||
/// A dummy field. Used only for deserialization.
|
||||
#[allow(dead_code)]
|
||||
ok: bool, // TODO: False type
|
||||
|
||||
description: String,
|
||||
error_code: u16,
|
||||
response_parameters: Option<ResponseParameters>,
|
||||
},
|
||||
}
|
||||
|
||||
pub async fn download_file<D>(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
path: &str,
|
||||
destination: &mut D,
|
||||
) -> Result<(), DownloadError>
|
||||
where
|
||||
D: AsyncWrite + Unpin,
|
||||
{
|
||||
let mut stream = download_file_stream(client, token, path).await?;
|
||||
|
||||
while let Some(chunk) = stream.next().await {
|
||||
destination.write_all(chunk?.bytes()).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn download_file_stream(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
path: &str,
|
||||
) -> Result<impl Stream<Item = Result<Chunk, reqwest::Error>>, reqwest::Error> {
|
||||
let url = file_url(TELEGRAM_API_URL, token, path);
|
||||
let resp = client.get(&url).send().await?.error_for_status()?;
|
||||
Ok(resp.into_body())
|
||||
}
|
||||
|
||||
impl<R> Into<ResponseResult<R>> for TelegramResponse<R> {
|
||||
fn into(self) -> Result<R, RequestError> {
|
||||
match self {
|
||||
TelegramResponse::Ok { result, .. } => Ok(result),
|
||||
TelegramResponse::Err {
|
||||
description,
|
||||
error_code,
|
||||
response_parameters,
|
||||
..
|
||||
} => {
|
||||
if let Some(params) = response_parameters {
|
||||
match params {
|
||||
ResponseParameters::RetryAfter(i) => {
|
||||
Err(RequestError::RetryAfter(i))
|
||||
}
|
||||
ResponseParameters::MigrateToChatId(to) => {
|
||||
Err(RequestError::MigrateToChatId(to))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Err(RequestError::ApiError {
|
||||
description,
|
||||
status_code: StatusCode::from_u16(error_code).unwrap(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn method_url_test() {
|
||||
let url = method_url(
|
||||
TELEGRAM_API_URL,
|
||||
"535362388:AAF7-g0gYncWnm5IyfZlpPRqRRv6kNAGlao",
|
||||
"methodName",
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
url,
|
||||
"https://api.telegram.org/bot535362388:AAF7-g0gYncWnm5IyfZlpPRqRRv6kNAGlao/methodName"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn file_url_test() {
|
||||
let url = file_url(
|
||||
TELEGRAM_API_URL,
|
||||
"535362388:AAF7-g0gYncWnm5IyfZlpPRqRRv6kNAGlao",
|
||||
"AgADAgADyqoxG2g8aEsu_KjjVsGF4-zetw8ABAEAAwIAA20AA_8QAwABFgQ",
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
url,
|
||||
"https://api.telegram.org/file/bot535362388:AAF7-g0gYncWnm5IyfZlpPRqRRv6kNAGlao/AgADAgADyqoxG2g8aEsu_KjjVsGF4-zetw8ABAEAAwIAA20AA_8QAwABFgQ"
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
use reqwest::StatusCode;
|
||||
|
||||
//<editor-fold desc="download">
|
||||
#[derive(Debug, Display, From)]
|
||||
pub enum DownloadError {
|
||||
#[display(fmt = "Network error: {err}", err = _0)]
|
||||
|
@ -15,3 +18,43 @@ impl std::error::Error for DownloadError {
|
|||
}
|
||||
}
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
//<editor-fold desc="request">
|
||||
#[derive(Debug, Display)]
|
||||
pub enum RequestError {
|
||||
#[display(fmt = "Telegram error #{}: {}", status_code, description)]
|
||||
ApiError {
|
||||
status_code: StatusCode,
|
||||
description: String,
|
||||
},
|
||||
|
||||
/// The group has been migrated to a supergroup with the specified
|
||||
/// identifier.
|
||||
#[display(fmt = "The group has been migrated to a supergroup with id {id}", id = _0)]
|
||||
MigrateToChatId(i64),
|
||||
|
||||
/// In case of exceeding flood control, the number of seconds left to wait
|
||||
/// before the request can be repeated
|
||||
#[display(fmt = "Retry after {secs} seconds", secs = _0)]
|
||||
RetryAfter(i32),
|
||||
|
||||
#[display(fmt = "Network error: {err}", err = _0)]
|
||||
NetworkError(reqwest::Error),
|
||||
|
||||
#[display(fmt = "InvalidJson error caused by: {err}", err = _0)]
|
||||
InvalidJson(serde_json::Error),
|
||||
}
|
||||
|
||||
impl std::error::Error for RequestError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
RequestError::ApiError { .. } => None,
|
||||
RequestError::MigrateToChatId(_) => None,
|
||||
RequestError::RetryAfter(_) => None,
|
||||
RequestError::NetworkError(err) => Some(err),
|
||||
RequestError::InvalidJson(err) => Some(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
//</editor-fold>
|
||||
|
|
11
src/lib.rs
11
src/lib.rs
|
@ -3,8 +3,11 @@ extern crate derive_more;
|
|||
#[macro_use]
|
||||
extern crate serde;
|
||||
|
||||
pub mod bot;
|
||||
pub mod core;
|
||||
pub mod errors;
|
||||
mod network;
|
||||
|
||||
pub use errors::DownloadError;
|
||||
pub mod bot;
|
||||
pub mod errors;
|
||||
pub mod requests;
|
||||
pub mod types;
|
||||
|
||||
pub use errors::{DownloadError, RequestError};
|
||||
|
|
40
src/network/download.rs
Normal file
40
src/network/download.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
use futures::StreamExt;
|
||||
use reqwest::r#async::{Chunk, Client};
|
||||
use tokio::{
|
||||
io::{AsyncWrite, AsyncWriteExt},
|
||||
stream::Stream,
|
||||
};
|
||||
use bytes::Buf;
|
||||
|
||||
use crate::{
|
||||
network::{file_url, TELEGRAM_API_URL},
|
||||
DownloadError,
|
||||
};
|
||||
|
||||
pub async fn download_file<D>(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
path: &str,
|
||||
destination: &mut D,
|
||||
) -> Result<(), DownloadError>
|
||||
where
|
||||
D: AsyncWrite + Unpin,
|
||||
{
|
||||
let mut stream = download_file_stream(client, token, path).await?;
|
||||
|
||||
while let Some(chunk) = stream.next().await {
|
||||
destination.write_all(chunk?.bytes()).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn download_file_stream(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
path: &str,
|
||||
) -> Result<impl Stream<Item = Result<Chunk, reqwest::Error>>, reqwest::Error> {
|
||||
let url = file_url(TELEGRAM_API_URL, token, path);
|
||||
let resp = client.get(&url).send().await?.error_for_status()?;
|
||||
Ok(resp.into_body())
|
||||
}
|
66
src/network/mod.rs
Normal file
66
src/network/mod.rs
Normal file
|
@ -0,0 +1,66 @@
|
|||
mod download;
|
||||
mod request;
|
||||
mod telegram_response;
|
||||
|
||||
pub use download::{download_file, download_file_stream};
|
||||
pub use request::{request_json, request_multipart};
|
||||
pub use telegram_response::TelegramResponse;
|
||||
|
||||
pub const TELEGRAM_API_URL: &str = "https://api.telegram.org";
|
||||
|
||||
/// Creates URL for making HTTPS requests. See the [Telegram documentation].
|
||||
///
|
||||
/// [Telegram documentation]: https://core.telegram.org/bots/api#making-requests
|
||||
fn method_url(base: &str, token: &str, method_name: &str) -> String {
|
||||
format!(
|
||||
"{url}/bot{token}/{method}",
|
||||
url = base,
|
||||
token = token,
|
||||
method = method_name,
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates URL for downloading a file. See the [Telegram documentation].
|
||||
///
|
||||
/// [Telegram documentation] (https://core.telegram.org/bots/api#file)
|
||||
fn file_url(base: &str, token: &str, file_path: &str) -> String {
|
||||
format!(
|
||||
"{url}/file/bot{token}/{file}",
|
||||
url = base,
|
||||
token = token,
|
||||
file = file_path,
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn method_url_test() {
|
||||
let url = method_url(
|
||||
TELEGRAM_API_URL,
|
||||
"535362388:AAF7-g0gYncWnm5IyfZlpPRqRRv6kNAGlao",
|
||||
"methodName",
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
url,
|
||||
"https://api.telegram.org/bot535362388:AAF7-g0gYncWnm5IyfZlpPRqRRv6kNAGlao/methodName"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn file_url_test() {
|
||||
let url = file_url(
|
||||
TELEGRAM_API_URL,
|
||||
"535362388:AAF7-g0gYncWnm5IyfZlpPRqRRv6kNAGlao",
|
||||
"AgADAgADyqoxG2g8aEsu_KjjVsGF4-zetw8ABAEAAwIAA20AA_8QAwABFgQ",
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
url,
|
||||
"https://api.telegram.org/file/bot535362388:AAF7-g0gYncWnm5IyfZlpPRqRRv6kNAGlao/AgADAgADyqoxG2g8aEsu_KjjVsGF4-zetw8ABAEAAwIAA20AA_8QAwABFgQ"
|
||||
);
|
||||
}
|
||||
}
|
60
src/network/request.rs
Normal file
60
src/network/request.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
use apply::Apply;
|
||||
use reqwest::r#async::{multipart::Form, Client, Response};
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
use crate::{
|
||||
network::{method_url, TELEGRAM_API_URL, TelegramResponse},
|
||||
requests::ResponseResult,
|
||||
RequestError,
|
||||
};
|
||||
|
||||
pub async fn request_multipart<T>(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
method_name: &str,
|
||||
params: Option<Form>,
|
||||
) -> ResponseResult<T>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
process_response(
|
||||
client
|
||||
.post(&method_url(TELEGRAM_API_URL, token, method_name))
|
||||
.apply(|request_builder| match params {
|
||||
Some(params) => request_builder.multipart(params),
|
||||
None => request_builder,
|
||||
})
|
||||
.send()
|
||||
.await
|
||||
.map_err(RequestError::NetworkError)?,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn request_json<T: DeserializeOwned, P: Serialize>(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
method_name: &str,
|
||||
params: &P,
|
||||
) -> ResponseResult<T> {
|
||||
process_response(
|
||||
client
|
||||
.post(&method_url(TELEGRAM_API_URL, token, method_name))
|
||||
.json(params)
|
||||
.send()
|
||||
.await
|
||||
.map_err(RequestError::NetworkError)?,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn process_response<T: DeserializeOwned>(
|
||||
mut response: Response,
|
||||
) -> ResponseResult<T> {
|
||||
let response = serde_json::from_str::<TelegramResponse<T>>(
|
||||
&response.text().await.map_err(RequestError::NetworkError)?,
|
||||
)
|
||||
.map_err(RequestError::InvalidJson)?;
|
||||
|
||||
response.into()
|
||||
}
|
56
src/network/telegram_response.rs
Normal file
56
src/network/telegram_response.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
use reqwest::StatusCode;
|
||||
|
||||
use crate::{
|
||||
requests::ResponseResult, types::ResponseParameters, RequestError,
|
||||
};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum TelegramResponse<R> {
|
||||
Ok {
|
||||
/// A dummy field. Used only for deserialization.
|
||||
#[allow(dead_code)]
|
||||
ok: bool, // TODO: True type
|
||||
|
||||
result: R,
|
||||
},
|
||||
Err {
|
||||
/// A dummy field. Used only for deserialization.
|
||||
#[allow(dead_code)]
|
||||
ok: bool, // TODO: False type
|
||||
|
||||
description: String,
|
||||
error_code: u16,
|
||||
response_parameters: Option<ResponseParameters>,
|
||||
},
|
||||
}
|
||||
|
||||
impl<R> Into<ResponseResult<R>> for TelegramResponse<R> {
|
||||
fn into(self) -> Result<R, RequestError> {
|
||||
match self {
|
||||
TelegramResponse::Ok { result, .. } => Ok(result),
|
||||
TelegramResponse::Err {
|
||||
description,
|
||||
error_code,
|
||||
response_parameters,
|
||||
..
|
||||
} => {
|
||||
if let Some(params) = response_parameters {
|
||||
match params {
|
||||
ResponseParameters::RetryAfter(i) => {
|
||||
Err(RequestError::RetryAfter(i))
|
||||
}
|
||||
ResponseParameters::MigrateToChatId(to) => {
|
||||
Err(RequestError::MigrateToChatId(to))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Err(RequestError::ApiError {
|
||||
description,
|
||||
status_code: StatusCode::from_u16(error_code).unwrap(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::{
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, RequestContext, RequestFuture, ResponseResult},
|
||||
};
|
|
@ -1,8 +1,8 @@
|
|||
use crate::core::network;
|
||||
use crate::core::requests::{
|
||||
Request, RequestContext, RequestFuture, ResponseResult,
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, RequestContext, RequestFuture, ResponseResult},
|
||||
types::ShippingOption,
|
||||
};
|
||||
use crate::core::types::ShippingOption;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
/// If you sent an invoice requesting a shipping address and the parameter
|
|
@ -1,9 +1,10 @@
|
|||
use crate::core::network;
|
||||
use crate::core::requests::{
|
||||
use crate::{
|
||||
network,
|
||||
requests::{
|
||||
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||
},
|
||||
types::{Message, ReplyMarkup},
|
||||
};
|
||||
use crate::core::types::{Message, ReplyMarkup};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
/// Use this method to edit live location messages. A location can be edited
|
|
@ -1,12 +1,12 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use crate::core::{
|
||||
use reqwest::r#async::multipart::Form;
|
||||
|
||||
use crate::{
|
||||
requests::{utils, ChatId},
|
||||
types::{InputMedia, ParseMode},
|
||||
};
|
||||
|
||||
use reqwest::r#async::multipart::Form;
|
||||
|
||||
/// This is a convenient struct that builds `reqwest::r#async::multipart::Form`
|
||||
/// from scratch.
|
||||
pub struct FormBuilder {
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::{
|
||||
use crate::{
|
||||
network,
|
||||
requests::{
|
||||
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
|
@ -1,6 +1,10 @@
|
|||
use crate::core::requests::{ChatId, RequestContext, RequestFuture, ResponseResult, Request};
|
||||
use crate::core::types::Chat;
|
||||
use crate::core::network;
|
||||
use crate::{
|
||||
network,
|
||||
requests::{
|
||||
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||
},
|
||||
types::Chat,
|
||||
};
|
||||
|
||||
/// Use this method to get up to date information about the chat
|
||||
/// (current name of the user for one-on-one conversations,
|
||||
|
@ -15,7 +19,6 @@ pub struct GetChat<'a> {
|
|||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
|
||||
impl<'a> Request<'a> for GetChat<'a> {
|
||||
type ReturnValue = Chat;
|
||||
|
||||
|
@ -26,13 +29,13 @@ impl<'a> Request<'a> for GetChat<'a> {
|
|||
&self.ctx.token,
|
||||
"getChat",
|
||||
&self,
|
||||
).await
|
||||
)
|
||||
.await
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'a> GetChat<'a>{
|
||||
impl<'a> GetChat<'a> {
|
||||
pub fn chat_id<T>(mut self, chat_id: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
|
@ -1,8 +1,8 @@
|
|||
use crate::core::network;
|
||||
use crate::core::requests::{
|
||||
Request, RequestContext, RequestFuture, ResponseResult,
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, RequestContext, RequestFuture, ResponseResult},
|
||||
types::File,
|
||||
};
|
||||
use crate::core::types::File;
|
||||
|
||||
/// Use this method to get basic info about a file and prepare it for
|
||||
/// downloading. For the moment, bots can download files of up to 20MB in size.
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::{
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, RequestContext, RequestFuture, ResponseResult},
|
||||
types::User,
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::requests::RequestContext;
|
||||
use crate::requests::RequestContext;
|
||||
|
||||
//TODO: complete implementation after user_profile_fotos will be added to
|
||||
// types/mod.rs
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::requests::RequestContext;
|
||||
use crate::requests::RequestContext;
|
||||
//TODO:: need implementation
|
||||
/// Use this method to kick a user from a group, a supergroup or a channel. In
|
||||
/// the case of supergroups and channels, the user will not be able to return to
|
|
@ -1,48 +1,11 @@
|
|||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
||||
use reqwest::{r#async::Client, StatusCode};
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
mod form_builder;
|
||||
mod utils;
|
||||
|
||||
#[derive(Debug, Display)]
|
||||
pub enum RequestError {
|
||||
#[display(fmt = "Telegram error #{}: {}", status_code, description)]
|
||||
ApiError {
|
||||
status_code: StatusCode,
|
||||
description: String,
|
||||
},
|
||||
use reqwest::r#async::Client;
|
||||
use serde::de::DeserializeOwned;
|
||||
use std::{future::Future, pin::Pin};
|
||||
|
||||
/// The group has been migrated to a supergroup with the specified
|
||||
/// identifier.
|
||||
#[display(fmt = "The group has been migrated to a supergroup with id {id}", id = _0)]
|
||||
MigrateToChatId(i64),
|
||||
|
||||
/// In case of exceeding flood control, the number of seconds left to wait
|
||||
/// before the request can be repeated
|
||||
#[display(fmt = "Retry after {secs} seconds", secs = _0)]
|
||||
RetryAfter(i32),
|
||||
|
||||
#[display(fmt = "Network error: {err}", err = _0)]
|
||||
NetworkError(reqwest::Error),
|
||||
|
||||
#[display(fmt = "InvalidJson error caused by: {err}", err = _0)]
|
||||
InvalidJson(serde_json::Error),
|
||||
}
|
||||
|
||||
impl std::error::Error for RequestError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
RequestError::ApiError { .. } => None,
|
||||
RequestError::MigrateToChatId(_) => None,
|
||||
RequestError::RetryAfter(_) => None,
|
||||
RequestError::NetworkError(err) => Some(err),
|
||||
RequestError::InvalidJson(err) => Some(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
use crate::RequestError;
|
||||
|
||||
pub type ResponseResult<T> = Result<T, RequestError>;
|
||||
|
||||
|
@ -104,6 +67,7 @@ pub mod answer_pre_checkout_query;
|
|||
pub mod answer_shipping_query;
|
||||
pub mod edit_message_live_location;
|
||||
pub mod forward_message;
|
||||
pub mod get_chat;
|
||||
pub mod get_file;
|
||||
pub mod get_me;
|
||||
pub mod get_user_profile_photos;
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::requests::RequestContext;
|
||||
use crate::requests::RequestContext;
|
||||
//TODO:: need implementation
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
|
@ -1,8 +1,8 @@
|
|||
use crate::core::{
|
||||
use crate::{
|
||||
network,
|
||||
requests::form_builder::FormBuilder,
|
||||
requests::{
|
||||
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||
form_builder::FormBuilder, ChatId, Request, RequestContext,
|
||||
RequestFuture, ResponseResult,
|
||||
},
|
||||
types::{InputFile, Message, ParseMode, ReplyMarkup},
|
||||
};
|
||||
|
@ -32,10 +32,10 @@ pub struct SendAudio<'a> {
|
|||
/// if you want Telegram apps to show [bold, italic, fixed-width text
|
||||
/// or inline URLs] in the media caption.
|
||||
///
|
||||
/// [Markdown]: crate::core::types::ParseMode::Markdown
|
||||
/// [Html]: crate::core::types::ParseMode::Html
|
||||
/// [Markdown]: crate::types::ParseMode::Markdown
|
||||
/// [Html]: crate::types::ParseMode::Html
|
||||
/// [bold, italic, fixed-width text or inline URLs]:
|
||||
/// crate::core::types::ParseMode
|
||||
/// crate::types::ParseMode
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
/// Duration of the audio in seconds
|
||||
pub duration: Option<i32>,
|
|
@ -1,6 +1,8 @@
|
|||
use crate::core::network;
|
||||
use crate::core::requests::{
|
||||
use crate::{
|
||||
network,
|
||||
requests::{
|
||||
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||
},
|
||||
};
|
||||
|
||||
///Use this method when you need to tell the user that something is happening
|
|
@ -1,8 +1,10 @@
|
|||
use crate::core::network;
|
||||
use crate::core::requests::{
|
||||
use crate::{
|
||||
network,
|
||||
requests::{
|
||||
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||
},
|
||||
types::{Message, ReplyMarkup},
|
||||
};
|
||||
use crate::core::types::{Message, ReplyMarkup};
|
||||
|
||||
/// Use this method to send phone contacts.
|
||||
/// returned.
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::{
|
||||
use crate::{
|
||||
network,
|
||||
requests::{
|
||||
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
|
@ -1,4 +1,6 @@
|
|||
use crate::core::{
|
||||
use apply::Apply;
|
||||
|
||||
use crate::{
|
||||
network::request_multipart,
|
||||
requests::{
|
||||
form_builder::FormBuilder, ChatId, Request, RequestContext,
|
||||
|
@ -6,7 +8,6 @@ use crate::core::{
|
|||
},
|
||||
types::{InputFile, InputMedia, Message},
|
||||
};
|
||||
use apply::Apply;
|
||||
|
||||
/// Use this method to send a group of photos or videos as an album.
|
||||
#[derive(Debug, Clone)]
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::{
|
||||
use crate::{
|
||||
network,
|
||||
requests::{
|
||||
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||
|
@ -23,10 +23,10 @@ pub struct SendMessage<'a> {
|
|||
/// if you want Telegram apps to show [bold, italic, fixed-width text
|
||||
/// or inline URLs] in the media caption.
|
||||
///
|
||||
/// [Markdown]: crate::core::types::ParseMode::Markdown
|
||||
/// [Html]: crate::core::types::ParseMode::Html
|
||||
/// [Markdown]: crate::types::ParseMode::Markdown
|
||||
/// [Html]: crate::types::ParseMode::Html
|
||||
/// [bold, italic, fixed-width text or inline URLs]:
|
||||
/// crate::core::types::ParseMode
|
||||
/// crate::types::ParseMode
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
/// Disables link previews for links in this message
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::{
|
||||
use crate::{
|
||||
network,
|
||||
requests::{
|
||||
form_builder::FormBuilder, ChatId, Request, RequestContext,
|
||||
|
@ -30,10 +30,10 @@ pub struct SendPhoto<'a> {
|
|||
/// if you want Telegram apps to show [bold, italic, fixed-width text
|
||||
/// or inline URLs] in the media caption.
|
||||
///
|
||||
/// [Markdown]: crate::core::types::ParseMode::Markdown
|
||||
/// [Html]: crate::core::types::ParseMode::Html
|
||||
/// [Markdown]: crate::types::ParseMode::Markdown
|
||||
/// [Html]: crate::types::ParseMode::Html
|
||||
/// [bold, italic, fixed-width text or inline URLs]:
|
||||
/// crate::core::types::ParseMode
|
||||
/// crate::types::ParseMode
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
/// Sends the message silently. Users will receive a notification with no
|
||||
/// sound.
|
|
@ -1,8 +1,10 @@
|
|||
use crate::core::network;
|
||||
use crate::core::requests::{
|
||||
use crate::{
|
||||
network,
|
||||
requests::{
|
||||
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||
},
|
||||
types::{Message, ReplyMarkup},
|
||||
};
|
||||
use crate::core::types::{Message, ReplyMarkup};
|
||||
|
||||
/// 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.
|
|
@ -1,8 +1,10 @@
|
|||
use crate::core::network;
|
||||
use crate::core::requests::{
|
||||
use crate::{
|
||||
network,
|
||||
requests::{
|
||||
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||
},
|
||||
types::{Message, ReplyMarkup},
|
||||
};
|
||||
use crate::core::types::{Message, ReplyMarkup};
|
||||
|
||||
/// Use this method to send information about a venue.
|
||||
/// Message is returned.
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::{
|
||||
use crate::{
|
||||
network,
|
||||
requests::{
|
||||
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::requests::RequestContext;
|
||||
use crate::requests::RequestContext;
|
||||
//TODO:: need implementation
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::PhotoSize;
|
||||
use crate::types::PhotoSize;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
/// This object represents an animation file (GIF or H.264/MPEG-4 AVC video
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::PhotoSize;
|
||||
use crate::types::PhotoSize;
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
|
||||
pub struct Audio {
|
||||
|
@ -42,8 +42,8 @@ mod tests {
|
|||
file_id: "id".to_string(),
|
||||
width: 320,
|
||||
height: 320,
|
||||
file_size: Some(3452)
|
||||
})
|
||||
file_size: Some(3452),
|
||||
}),
|
||||
};
|
||||
let actual = serde_json::from_str::<Audio>(&json).unwrap();
|
||||
assert_eq!(actual, expected)
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::{Message, User};
|
||||
use crate::types::{Message, User};
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Clone)]
|
||||
pub struct CallbackQuery {
|
||||
|
@ -8,7 +8,7 @@ pub struct CallbackQuery {
|
|||
pub message: Option<Message>,
|
||||
pub inline_message_id: Option<String>,
|
||||
pub data: Option<String>,
|
||||
pub game_short_name: Option<String>
|
||||
pub game_short_name: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -37,13 +37,13 @@ mod tests {
|
|||
first_name: "firstName".to_string(),
|
||||
last_name: None,
|
||||
username: None,
|
||||
language_code: None
|
||||
language_code: None,
|
||||
},
|
||||
chat_instance: "123456".to_string(),
|
||||
message: None,
|
||||
inline_message_id: Some("i_m_id".to_string()),
|
||||
data: Some("some_data".to_string()),
|
||||
game_short_name: Some("game_name".to_string())
|
||||
game_short_name: Some("game_name".to_string()),
|
||||
};
|
||||
let actual = serde_json::from_str::<CallbackQuery>(json).unwrap();
|
||||
assert_eq!(actual, expected);
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::{ChatPermissions, ChatPhoto, Message};
|
||||
use crate::types::{ChatPermissions, ChatPhoto, Message};
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Clone)]
|
||||
pub struct Chat {
|
||||
|
@ -80,7 +80,7 @@ where
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::core::types::*;
|
||||
use crate::types::*;
|
||||
use serde_json::from_str;
|
||||
|
||||
#[test]
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::User;
|
||||
use crate::types::User;
|
||||
|
||||
/// This object contains information about one member of the chat.
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
||||
|
@ -63,7 +63,7 @@ pub enum ChatMemberStatus {
|
|||
Member,
|
||||
Restricted,
|
||||
Left,
|
||||
Kicked
|
||||
Kicked,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -103,7 +103,7 @@ mod tests {
|
|||
first_name: "firstName".to_string(),
|
||||
last_name: None,
|
||||
username: None,
|
||||
language_code: None
|
||||
language_code: None,
|
||||
},
|
||||
status: ChatMemberStatus::Creator,
|
||||
until_date: Some(123456),
|
||||
|
@ -119,7 +119,7 @@ mod tests {
|
|||
can_send_messages: Some(true),
|
||||
can_send_media_messages: Some(true),
|
||||
can_send_other_messages: Some(true),
|
||||
can_add_web_page_previews: Some(true)
|
||||
can_add_web_page_previews: Some(true),
|
||||
};
|
||||
let actual = serde_json::from_str::<ChatMember>(&json).unwrap();
|
||||
assert_eq!(actual, expected)
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::{Location, User};
|
||||
use crate::types::{Location, User};
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, PartialEq)]
|
||||
/// Represents a result of an inline query that was chosen by the user and
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::PhotoSize;
|
||||
use crate::types::PhotoSize;
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||
pub struct Document {
|
|
@ -1,6 +1,6 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::core::types::{Animation, MessageEntity, PhotoSize};
|
||||
use crate::types::{Animation, MessageEntity, PhotoSize};
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)]
|
||||
/// This object represents a game. Use BotFather to create and edit games, their
|
|
@ -1,6 +1,6 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::core::types::user::User;
|
||||
use crate::types::user::User;
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
/// This object represents one row of the high scores table for a game.
|
|
@ -45,7 +45,7 @@ pub enum InlineKeyboardButtonKind {
|
|||
///
|
||||
/// Example:
|
||||
/// ```edition2018
|
||||
/// use async_telegram_bot::core::types::InlineKeyboardButton;
|
||||
/// use async_telegram_bot::types::InlineKeyboardButton;
|
||||
///
|
||||
/// fn main() {
|
||||
/// let url_button = InlineKeyboardButton::url(
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::InlineKeyboardButton;
|
||||
use crate::types::InlineKeyboardButton;
|
||||
|
||||
/// This object represents an inline keyboard that appears right next to the
|
||||
/// message it belongs to.
|
||||
|
@ -16,7 +16,7 @@ pub struct InlineKeyboardMarkup {
|
|||
///
|
||||
/// Example:
|
||||
/// ```
|
||||
/// use async_telegram_bot::core::types::{
|
||||
/// use async_telegram_bot::types::{
|
||||
/// InlineKeyboardButton, InlineKeyboardMarkup,
|
||||
/// };
|
||||
///
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::{Location, User};
|
||||
use crate::types::{Location, User};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQuery {
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::{
|
||||
use crate::types::{
|
||||
InlineQueryResultArticle, InlineQueryResultAudio,
|
||||
InlineQueryResultCachedAudio, InlineQueryResultCachedDocument,
|
||||
InlineQueryResultCachedGif, InlineQueryResultCachedMpeg4Gif,
|
||||
|
@ -49,9 +49,9 @@ pub enum InlineQueryResult {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::core::types::inline_keyboard_markup::InlineKeyboardMarkup;
|
||||
use crate::core::types::parse_mode::ParseMode;
|
||||
use crate::core::types::{
|
||||
use crate::types::inline_keyboard_markup::InlineKeyboardMarkup;
|
||||
use crate::types::parse_mode::ParseMode;
|
||||
use crate::types::{
|
||||
InlineQueryResult, InlineQueryResultCachedAudio, InputMessageContent,
|
||||
};
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::{InlineKeyboardMarkup, InputMessageContent};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultArticle {
|
|
@ -1,6 +1,4 @@
|
|||
use crate::core::types::{
|
||||
InlineKeyboardMarkup, InputMessageContent, ParseMode,
|
||||
};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultAudio {
|
|
@ -1,6 +1,4 @@
|
|||
use crate::core::types::{
|
||||
InlineKeyboardMarkup, InputMessageContent, ParseMode,
|
||||
};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultCachedAudio {
|
|
@ -1,6 +1,4 @@
|
|||
use crate::core::types::{
|
||||
InlineKeyboardMarkup, InputMessageContent, ParseMode,
|
||||
};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultCachedDocument {
|
|
@ -1,6 +1,4 @@
|
|||
use crate::core::types::{
|
||||
InlineKeyboardMarkup, InputMessageContent, ParseMode,
|
||||
};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultCachedGif {
|
|
@ -1,6 +1,4 @@
|
|||
use crate::core::types::{
|
||||
InlineKeyboardMarkup, InputMessageContent, ParseMode,
|
||||
};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultCachedMpeg4Gif {
|
|
@ -1,6 +1,4 @@
|
|||
use crate::core::types::{
|
||||
InlineKeyboardMarkup, InputMessageContent, ParseMode,
|
||||
};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultCachedPhoto {
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::{InlineKeyboardMarkup, InputMessageContent};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultCachedSticker {
|
|
@ -1,6 +1,4 @@
|
|||
use crate::core::types::{
|
||||
InlineKeyboardMarkup, InputMessageContent, ParseMode,
|
||||
};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultCachedVideo {
|
|
@ -1,6 +1,4 @@
|
|||
use crate::core::types::{
|
||||
InlineKeyboardMarkup, InputMessageContent, ParseMode,
|
||||
};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultCachedVoice {
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::{InlineKeyboardMarkup, InputMessageContent};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultContact {
|
|
@ -1,6 +1,4 @@
|
|||
use crate::core::types::{
|
||||
InlineKeyboardMarkup, InputMessageContent, ParseMode,
|
||||
};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultDocument {
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::InlineKeyboardMarkup;
|
||||
use crate::types::InlineKeyboardMarkup;
|
||||
|
||||
#[derive(Debug, Serialize, Hash, PartialEq, Eq, Clone)]
|
||||
pub struct InlineQueryResultGame {
|
|
@ -1,6 +1,4 @@
|
|||
use crate::core::types::{
|
||||
InlineKeyboardMarkup, InputMessageContent, ParseMode,
|
||||
};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultGif {
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::{InlineKeyboardMarkup, InputMessageContent};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultLocation {
|
|
@ -1,6 +1,4 @@
|
|||
use crate::core::types::{
|
||||
InlineKeyboardMarkup, InputMessageContent, ParseMode,
|
||||
};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultMpeg4Gif {
|
|
@ -1,6 +1,4 @@
|
|||
use crate::core::types::{
|
||||
InlineKeyboardMarkup, InputMessageContent, ParseMode,
|
||||
};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
|
||||
|
||||
/// Represents a link to a photo. By default, this photo will be sent by the
|
||||
/// user with optional caption. Alternatively, you can use input_message_content
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::{InlineKeyboardMarkup, InputMessageContent};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultVenue {
|
|
@ -1,6 +1,4 @@
|
|||
use crate::core::types::{
|
||||
InlineKeyboardMarkup, InputMessageContent, ParseMode,
|
||||
};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultVideo {
|
|
@ -1,6 +1,4 @@
|
|||
use crate::core::types::{
|
||||
InlineKeyboardMarkup, InputMessageContent, ParseMode,
|
||||
};
|
||||
use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Clone)]
|
||||
pub struct InlineQueryResultVoice {
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::{InputFile, ParseMode};
|
||||
use crate::types::{InputFile, ParseMode};
|
||||
|
||||
// TODO: should variants use new-type?
|
||||
#[derive(Debug, Serialize, PartialEq, Eq, Clone)]
|
||||
|
@ -18,10 +18,10 @@ pub enum InputMedia {
|
|||
/// if you want Telegram apps to show [bold, italic, fixed-width text
|
||||
/// or inline URLs] in the media caption.
|
||||
///
|
||||
/// [Markdown]: crate::core::types::ParseMode::Markdown
|
||||
/// [Html]: crate::core::types::ParseMode::Html
|
||||
/// [Markdown]: crate::types::ParseMode::Markdown
|
||||
/// [Html]: crate::types::ParseMode::Html
|
||||
/// [bold, italic, fixed-width text or inline URLs]:
|
||||
/// crate::core::types::ParseMode
|
||||
/// crate::types::ParseMode
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
parse_mode: Option<ParseMode>,
|
||||
},
|
||||
|
@ -35,7 +35,7 @@ pub enum InputMedia {
|
|||
/// size. A thumbnail‘s width and height should not exceed 320.
|
||||
/// Ignored if the file is not uploaded using [InputFile::File].
|
||||
///
|
||||
/// [InputFile::File]: crate::core::types::InputFile::File
|
||||
/// [InputFile::File]: crate::types::InputFile::File
|
||||
thumb: Option<InputFile>,
|
||||
/// Caption of the video to be sent, 0-1024 characters.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
@ -44,10 +44,10 @@ pub enum InputMedia {
|
|||
/// if you want Telegram apps to show [bold, italic, fixed-width text
|
||||
/// or inline URLs] in the media caption.
|
||||
///
|
||||
/// [Markdown]: crate::core::types::ParseMode::Markdown
|
||||
/// [Html]: crate::core::types::ParseMode::Html
|
||||
/// [Markdown]: crate::types::ParseMode::Markdown
|
||||
/// [Html]: crate::types::ParseMode::Html
|
||||
/// [bold, italic, fixed-width text or inline URLs]:
|
||||
/// crate::core::types::ParseMode
|
||||
/// crate::types::ParseMode
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
parse_mode: Option<ParseMode>,
|
||||
/// Video width
|
||||
|
@ -74,7 +74,7 @@ pub enum InputMedia {
|
|||
/// size. A thumbnail‘s width and height should not exceed 320.
|
||||
/// Ignored if the file is not uploaded using [InputFile::File].
|
||||
///
|
||||
/// [InputFile::File]: crate::core::types::InputFile::File
|
||||
/// [InputFile::File]: crate::types::InputFile::File
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
thumb: Option<InputFile>,
|
||||
/// Caption of the animation to be sent, 0-1024 characters
|
||||
|
@ -84,10 +84,10 @@ pub enum InputMedia {
|
|||
/// if you want Telegram apps to show [bold, italic, fixed-width text
|
||||
/// or inline URLs] in the media caption.
|
||||
///
|
||||
/// [Markdown]: crate::core::types::ParseMode::Markdown
|
||||
/// [Html]: crate::core::types::ParseMode::Html
|
||||
/// [Markdown]: crate::types::ParseMode::Markdown
|
||||
/// [Html]: crate::types::ParseMode::Html
|
||||
/// [bold, italic, fixed-width text or inline URLs]:
|
||||
/// crate::core::types::ParseMode
|
||||
/// crate::types::ParseMode
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
parse_mode: Option<ParseMode>,
|
||||
/// Animation width
|
||||
|
@ -110,7 +110,7 @@ pub enum InputMedia {
|
|||
/// size. A thumbnail‘s width and height should not exceed 320.
|
||||
/// Ignored if the file is not uploaded using [InputFile::File].
|
||||
///
|
||||
/// [InputFile::File]: crate::core::types::InputFile::File
|
||||
/// [InputFile::File]: crate::types::InputFile::File
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
thumb: Option<InputFile>,
|
||||
/// Caption of the audio to be sent, 0-1024 characters
|
||||
|
@ -120,10 +120,10 @@ pub enum InputMedia {
|
|||
/// if you want Telegram apps to show [bold, italic, fixed-width text
|
||||
/// or inline URLs] in the media caption.
|
||||
///
|
||||
/// [Markdown]: crate::core::types::ParseMode::Markdown
|
||||
/// [Html]: crate::core::types::ParseMode::Html
|
||||
/// [Markdown]: crate::types::ParseMode::Markdown
|
||||
/// [Html]: crate::types::ParseMode::Html
|
||||
/// [bold, italic, fixed-width text or inline URLs]:
|
||||
/// crate::core::types::ParseMode
|
||||
/// crate::types::ParseMode
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
parse_mode: Option<String>,
|
||||
/// Duration of the audio in seconds
|
||||
|
@ -146,7 +146,7 @@ pub enum InputMedia {
|
|||
/// size. A thumbnail‘s width and height should not exceed 320.
|
||||
/// Ignored if the file is not uploaded using [InputFile::File].
|
||||
///
|
||||
/// [InputFile::File]: crate::core::types::InputFile::File
|
||||
/// [InputFile::File]: crate::types::InputFile::File
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
thumb: Option<InputFile>,
|
||||
/// Caption of the document to be sent, 0-1024 characters
|
||||
|
@ -156,10 +156,10 @@ pub enum InputMedia {
|
|||
/// if you want Telegram apps to show [bold, italic, fixed-width text
|
||||
/// or inline URLs] in the media caption.
|
||||
///
|
||||
/// [Markdown]: crate::core::types::ParseMode::Markdown
|
||||
/// [Html]: crate::core::types::ParseMode::Html
|
||||
/// [Markdown]: crate::types::ParseMode::Markdown
|
||||
/// [Html]: crate::types::ParseMode::Html
|
||||
/// [bold, italic, fixed-width text or inline URLs]:
|
||||
/// crate::core::types::ParseMode
|
||||
/// crate::types::ParseMode
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
parse_mode: Option<ParseMode>,
|
||||
},
|
|
@ -1,6 +1,6 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::core::types::ParseMode;
|
||||
use crate::types::ParseMode;
|
||||
|
||||
#[derive(Debug, Serialize, Clone, PartialEq)]
|
||||
#[serde(untagged)]
|
||||
|
@ -18,10 +18,10 @@ pub enum InputMessageContent {
|
|||
/// if you want Telegram apps to show [bold, italic, fixed-width text
|
||||
/// or inline URLs] in the media caption.
|
||||
///
|
||||
/// [Markdown]: crate::core::types::ParseMode::Markdown
|
||||
/// [Html]: crate::core::types::ParseMode::Html
|
||||
/// [Markdown]: crate::types::ParseMode::Markdown
|
||||
/// [Html]: crate::types::ParseMode::Html
|
||||
/// [bold, italic, fixed-width text or inline URLs]:
|
||||
/// crate::core::types::ParseMode
|
||||
/// crate::types::ParseMode
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
parse_mode: Option<ParseMode>,
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::{
|
||||
use crate::types::{
|
||||
Animation, Audio, Chat, Contact, Document, Game, InlineKeyboardMarkup,
|
||||
Invoice, Location, MessageEntity, PassportData, PhotoSize, Poll, Sticker,
|
||||
SuccessfulPayment, User, Venue, Video, VideoNote, Voice,
|
||||
|
@ -17,9 +17,10 @@ pub struct Message {
|
|||
impl Message {
|
||||
fn text(&self) -> Option<&str> {
|
||||
if let MessageKind::Common {
|
||||
media_kind: MediaKind::Text {
|
||||
ref text, ..
|
||||
}, .. } = self.kind {
|
||||
media_kind: MediaKind::Text { ref text, .. },
|
||||
..
|
||||
} = self.kind
|
||||
{
|
||||
Some(text)
|
||||
} else {
|
||||
None
|
||||
|
@ -202,7 +203,7 @@ pub enum MediaKind {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::core::types::*;
|
||||
use crate::types::*;
|
||||
use serde_json::from_str;
|
||||
|
||||
#[test]
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::User;
|
||||
use crate::types::User;
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||
pub struct MessageEntity {
|
|
@ -2,6 +2,7 @@ use self::not_implemented_types::*;
|
|||
pub use self::{
|
||||
animation::Animation,
|
||||
audio::Audio,
|
||||
callback_game::CallbackGame,
|
||||
callback_query::CallbackQuery,
|
||||
chat::{Chat, ChatKind, NonPrivateChatKind},
|
||||
chat_member::{ChatMember, ChatMemberStatus},
|
||||
|
@ -13,6 +14,7 @@ pub use self::{
|
|||
file::File,
|
||||
force_reply::ForceReply,
|
||||
game::Game,
|
||||
game_high_score::GameHighScore,
|
||||
inline_keyboard_button::{InlineKeyboardButton, InlineKeyboardButtonKind},
|
||||
inline_keyboard_markup::InlineKeyboardMarkup,
|
||||
inline_query::InlineQuery,
|
||||
|
@ -44,6 +46,7 @@ pub use self::{
|
|||
keyboard_button::KeyboardButton,
|
||||
label_price::LabeledPrice,
|
||||
location::Location,
|
||||
login_url::LoginUrl,
|
||||
mask_position::MaskPosition,
|
||||
message::{
|
||||
ForwardKind, ForwardedFrom, MediaKind, Message, MessageKind, Sender,
|
||||
|
@ -63,17 +66,21 @@ pub use self::{
|
|||
shipping_option::ShippingOption,
|
||||
shipping_query::ShippingQuery,
|
||||
sticker::Sticker,
|
||||
sticker_set::StickerSet,
|
||||
successful_payment::SuccessfulPayment,
|
||||
update::{Update, UpdateKind},
|
||||
user::User,
|
||||
user_profile_photos::UserProfilePhotos,
|
||||
venue::Venue,
|
||||
video::Video,
|
||||
video_note::VideoNote,
|
||||
voice::Voice,
|
||||
webhook_info::WebhookInfo,
|
||||
};
|
||||
|
||||
mod animation;
|
||||
mod audio;
|
||||
mod callback_game;
|
||||
mod callback_query;
|
||||
mod chat;
|
||||
mod chat_member;
|
||||
|
@ -85,6 +92,7 @@ mod document;
|
|||
mod file;
|
||||
mod force_reply;
|
||||
mod game;
|
||||
mod game_high_score;
|
||||
mod inline_keyboard_button;
|
||||
mod inline_keyboard_markup;
|
||||
mod input_file;
|
||||
|
@ -94,6 +102,7 @@ mod invoice;
|
|||
mod keyboard_button;
|
||||
mod label_price;
|
||||
mod location;
|
||||
mod login_url;
|
||||
mod mask_position;
|
||||
mod message;
|
||||
mod message_entity;
|
||||
|
@ -112,13 +121,16 @@ mod shipping_address;
|
|||
mod shipping_option;
|
||||
mod shipping_query;
|
||||
mod sticker;
|
||||
mod sticker_set;
|
||||
mod successful_payment;
|
||||
mod update;
|
||||
mod user;
|
||||
mod user_profile_photos;
|
||||
mod venue;
|
||||
mod video;
|
||||
mod video_note;
|
||||
mod voice;
|
||||
mod webhook_info;
|
||||
|
||||
mod inline_query;
|
||||
mod inline_query_result;
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::ShippingAddress;
|
||||
use crate::types::ShippingAddress;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone, Serialize)]
|
||||
pub struct OrderInfo {
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::{OrderInfo, User};
|
||||
use crate::types::{OrderInfo, User};
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
||||
pub struct PreCheckoutQuery {
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::KeyboardButton;
|
||||
use crate::types::KeyboardButton;
|
||||
|
||||
/// This object represents a custom keyboard with reply options.
|
||||
#[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Clone)]
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::{
|
||||
use crate::types::{
|
||||
ForceReply, InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove,
|
||||
};
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::core::requests::ChatId;
|
||||
use crate::core::types::{InlineKeyboardMarkup, LabeledPrice};
|
||||
use crate::requests::ChatId;
|
||||
use crate::types::{InlineKeyboardMarkup, LabeledPrice};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub struct SendInvoice {
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::LabeledPrice;
|
||||
use crate::types::LabeledPrice;
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq, Clone, Serialize)]
|
||||
/// This object represents one shipping option.
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::types::{ShippingAddress, User};
|
||||
use crate::types::{ShippingAddress, User};
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
||||
pub struct ShippingQuery {
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue