mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-24 09:16:12 +01:00
commit
91015b7b3f
89 changed files with 112 additions and 8616 deletions
1569
src/bot/api.rs
1569
src/bot/api.rs
File diff suppressed because it is too large
Load diff
|
@ -10,28 +10,30 @@ use crate::{
|
|||
impl Bot {
|
||||
/// Download a file from Telegram into `destination`.
|
||||
///
|
||||
/// `path` can be obtained from [`Bot::get_file`].
|
||||
/// `path` can be obtained from [`GetFile`].
|
||||
///
|
||||
/// To download as a stream of chunks, see [`Bot::download_file_stream`].
|
||||
///
|
||||
/// ## Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// use teloxide_core::types::File as TgFile;
|
||||
/// use teloxide_core::{
|
||||
/// requests::{Request, Requester},
|
||||
/// types::File as TgFile,
|
||||
/// Bot,
|
||||
/// };
|
||||
/// use tokio::fs::File;
|
||||
/// # use teloxide_core::RequestError;
|
||||
/// use teloxide_core::{requests::RequestOld, Bot};
|
||||
///
|
||||
/// # 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?;
|
||||
/// let mut file = File::create("/home/waffle/Pictures/test.png").await?;
|
||||
/// bot.download_file(&file_path, &mut file).await?;
|
||||
/// # Ok(()) }
|
||||
/// ```
|
||||
///
|
||||
/// [`Bot::get_file`]: crate::Bot::get_file
|
||||
/// [`GetFile`]: crate::payloads::GetFile
|
||||
/// [`Bot::download_file_stream`]: crate::Bot::download_file_stream
|
||||
pub async fn download_file<D>(
|
||||
&self,
|
||||
|
@ -46,12 +48,12 @@ impl Bot {
|
|||
|
||||
/// Download a file from Telegram.
|
||||
///
|
||||
/// `path` can be obtained from the [`Bot::get_file`].
|
||||
/// `path` can be obtained from the [`GetFile`].
|
||||
///
|
||||
/// To download into [`AsyncWrite`] (e.g. [`tokio::fs::File`]), see
|
||||
/// [`Bot::download_file`].
|
||||
///
|
||||
/// [`Bot::get_file`]: crate::bot::Bot::get_file
|
||||
/// [`GetFile`]: crate::payloads::GetFile
|
||||
/// [`AsyncWrite`]: tokio::io::AsyncWrite
|
||||
/// [`tokio::fs::File`]: tokio::fs::File
|
||||
/// [`Bot::download_file`]: crate::Bot::download_file
|
||||
|
|
|
@ -129,7 +129,7 @@ impl Bot {
|
|||
.expect("serialization of request to be infallible");
|
||||
|
||||
// async move to capture client&token&api_url¶ms
|
||||
async move { net::request_json2(&client, token.as_ref(), api_url.get(), P::NAME, params).await }
|
||||
async move { net::request_json(&client, token.as_ref(), api_url.get(), P::NAME, params).await }
|
||||
}
|
||||
|
||||
pub(crate) fn execute_multipart<P>(
|
||||
|
@ -149,7 +149,7 @@ impl Bot {
|
|||
// async move to capture client&token&api_url¶ms
|
||||
async move {
|
||||
let params = params.await?;
|
||||
net::request_multipart2(&client, token.as_ref(), api_url.get(), P::NAME, params).await
|
||||
net::request_multipart(&client, token.as_ref(), api_url.get(), P::NAME, params).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`EditMessageText`]
|
||||
///
|
||||
/// [`EditMessageText`]: crate::requests::EditMessageText
|
||||
/// [`EditMessageText`]: crate::payloads::EditMessageText
|
||||
#[serde(rename = "Bad Request: message is not modified: specified new message content and \
|
||||
reply markup are exactly the same as a current content and reply markup \
|
||||
of the message")]
|
||||
|
@ -82,8 +82,8 @@ pub enum ApiError {
|
|||
/// 1. [`ForwardMessage`]
|
||||
/// 2. [`DeleteMessage`]
|
||||
///
|
||||
/// [`ForwardMessage`]: crate::requests::ForwardMessage
|
||||
/// [`DeleteMessage`]: crate::requests::DeleteMessage
|
||||
/// [`ForwardMessage`]: crate::payloads::ForwardMessage
|
||||
/// [`DeleteMessage`]: crate::payloads::DeleteMessage
|
||||
#[serde(rename = "Bad Request: MESSAGE_ID_INVALID")]
|
||||
MessageIdInvalid,
|
||||
|
||||
|
@ -92,7 +92,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`ForwardMessage`]
|
||||
///
|
||||
/// [`ForwardMessage`]: crate::requests::ForwardMessage
|
||||
/// [`ForwardMessage`]: crate::payloads::ForwardMessage
|
||||
#[serde(rename = "Bad Request: message to forward not found")]
|
||||
MessageToForwardNotFound,
|
||||
|
||||
|
@ -101,7 +101,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`DeleteMessage`]
|
||||
///
|
||||
/// [`DeleteMessage`]: crate::requests::DeleteMessage
|
||||
/// [`DeleteMessage`]: crate::payloads::DeleteMessage
|
||||
#[serde(rename = "Bad Request: message to delete not found")]
|
||||
MessageToDeleteNotFound,
|
||||
|
||||
|
@ -110,7 +110,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendMessage`]
|
||||
///
|
||||
/// [`SendMessage`]: crate::requests::SendMessage
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: message text is empty")]
|
||||
MessageTextIsEmpty,
|
||||
|
||||
|
@ -119,7 +119,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`EditMessageText`]
|
||||
///
|
||||
/// [`EditMessageText`]: crate::requests::EditMessageText
|
||||
/// [`EditMessageText`]: crate::payloads::EditMessageText
|
||||
#[serde(rename = "Bad Request: message can't be edited")]
|
||||
MessageCantBeEdited,
|
||||
|
||||
|
@ -129,7 +129,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`DeleteMessage`]
|
||||
///
|
||||
/// [`DeleteMessage`]: crate::requests::DeleteMessage
|
||||
/// [`DeleteMessage`]: crate::payloads::DeleteMessage
|
||||
#[serde(rename = "Bad Request: message can't be deleted")]
|
||||
MessageCantBeDeleted,
|
||||
|
||||
|
@ -138,7 +138,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`EditMessageText`]
|
||||
///
|
||||
/// [`EditMessageText`]: crate::requests::EditMessageText
|
||||
/// [`EditMessageText`]: crate::payloads::EditMessageText
|
||||
#[serde(rename = "Bad Request: message to edit not found")]
|
||||
MessageToEditNotFound,
|
||||
|
||||
|
@ -147,7 +147,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendMessage`]
|
||||
///
|
||||
/// [`SendMessage`]: crate::requests::SendMessage
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: reply message not found")]
|
||||
MessageToReplyNotFound,
|
||||
|
||||
|
@ -161,7 +161,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendMessage`]
|
||||
///
|
||||
/// [`SendMessage`]: crate::requests::SendMessage
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: message is too long")]
|
||||
MessageIsTooLong,
|
||||
|
||||
|
@ -170,7 +170,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendMediaGroup`]
|
||||
///
|
||||
/// [`SendMediaGroup`]: crate::requests::SendMediaGroup
|
||||
/// [`SendMediaGroup`]: crate::payloads::SendMediaGroup
|
||||
#[serde(rename = "Bad Request: Too much messages to send as an album")]
|
||||
ToMuchMessages,
|
||||
|
||||
|
@ -179,7 +179,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendPoll`]
|
||||
///
|
||||
/// [`SendPoll`]: crate::requests::SendPoll
|
||||
/// [`SendPoll`]: crate::payloads::SendPoll
|
||||
#[serde(rename = "Bad Request: poll has already been closed")]
|
||||
PollHasAlreadyClosed,
|
||||
|
||||
|
@ -188,7 +188,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendPoll`]
|
||||
///
|
||||
/// [`SendPoll`]: crate::requests::SendPoll
|
||||
/// [`SendPoll`]: crate::payloads::SendPoll
|
||||
#[serde(rename = "Bad Request: poll must have at least 2 option")]
|
||||
PollMustHaveMoreOptions,
|
||||
|
||||
|
@ -197,7 +197,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendPoll`]
|
||||
///
|
||||
/// [`SendPoll`]: crate::requests::SendPoll
|
||||
/// [`SendPoll`]: crate::payloads::SendPoll
|
||||
#[serde(rename = "Bad Request: poll can't have more than 10 options")]
|
||||
PollCantHaveMoreOptions,
|
||||
|
||||
|
@ -206,7 +206,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendPoll`]
|
||||
///
|
||||
/// [`SendPoll`]: crate::requests::SendPoll
|
||||
/// [`SendPoll`]: crate::payloads::SendPoll
|
||||
#[serde(rename = "Bad Request: poll options must be non-empty")]
|
||||
PollOptionsMustBeNonEmpty,
|
||||
|
||||
|
@ -215,7 +215,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendPoll`]
|
||||
///
|
||||
/// [`SendPoll`]: crate::requests::SendPoll
|
||||
/// [`SendPoll`]: crate::payloads::SendPoll
|
||||
#[serde(rename = "Bad Request: poll question must be non-empty")]
|
||||
PollQuestionMustBeNonEmpty,
|
||||
|
||||
|
@ -225,7 +225,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendPoll`]
|
||||
///
|
||||
/// [`SendPoll`]: crate::requests::SendPoll
|
||||
/// [`SendPoll`]: crate::payloads::SendPoll
|
||||
#[serde(rename = "Bad Request: poll options length must not exceed 100")]
|
||||
PollOptionsLengthTooLong,
|
||||
|
||||
|
@ -235,7 +235,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendPoll`]
|
||||
///
|
||||
/// [`SendPoll`]: crate::requests::SendPoll
|
||||
/// [`SendPoll`]: crate::payloads::SendPoll
|
||||
#[serde(rename = "Bad Request: poll question length must not exceed 255")]
|
||||
PollQuestionLengthTooLong,
|
||||
|
||||
|
@ -244,7 +244,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`StopPoll`]
|
||||
///
|
||||
/// [`StopPoll`]: crate::requests::StopPoll
|
||||
/// [`StopPoll`]: crate::payloads::StopPoll
|
||||
#[serde(rename = "Bad Request: message with poll to stop not found")]
|
||||
MessageWithPollNotFound,
|
||||
|
||||
|
@ -253,7 +253,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`StopPoll`]
|
||||
///
|
||||
/// [`StopPoll`]: crate::requests::StopPoll
|
||||
/// [`StopPoll`]: crate::payloads::StopPoll
|
||||
#[serde(rename = "Bad Request: message is not a poll")]
|
||||
MessageIsNotAPoll,
|
||||
|
||||
|
@ -263,7 +263,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendMessage`]
|
||||
///
|
||||
/// [`SendMessage`]: crate::requests::SendMessage
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: chat not found")]
|
||||
ChatNotFound,
|
||||
|
||||
|
@ -273,7 +273,7 @@ pub enum ApiError {
|
|||
/// 1. [`getUserProfilePhotos`]
|
||||
///
|
||||
/// [`getUserProfilePhotos`]:
|
||||
/// crate::requests::GetUserProfilePhotos
|
||||
/// crate::payloads::GetUserProfilePhotos
|
||||
#[serde(rename = "Bad Request: user not found")]
|
||||
UserNotFound,
|
||||
|
||||
|
@ -283,7 +283,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SetChatDescription`]
|
||||
///
|
||||
/// [`SetChatDescription`]: crate::requests::SetChatDescription
|
||||
/// [`SetChatDescription`]: crate::payloads::SetChatDescription
|
||||
#[serde(rename = "Bad Request: chat description is not modified")]
|
||||
ChatDescriptionIsNotModified,
|
||||
|
||||
|
@ -292,7 +292,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`AnswerCallbackQuery`]
|
||||
///
|
||||
/// [`AnswerCallbackQuery`]: crate::requests::AnswerCallbackQuery
|
||||
/// [`AnswerCallbackQuery`]: crate::payloads::AnswerCallbackQuery
|
||||
#[serde(rename = "Bad Request: query is too old and response timeout expired or query id is \
|
||||
invalid")]
|
||||
InvalidQueryID,
|
||||
|
@ -303,7 +303,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendMessage`]
|
||||
///
|
||||
/// [`SendMessage`]: crate::requests::SendMessage
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: BUTTON_URL_INVALID")]
|
||||
ButtonURLInvalid,
|
||||
|
||||
|
@ -312,7 +312,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendMessage`]
|
||||
///
|
||||
/// [`SendMessage`]: crate::requests::SendMessage
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: BUTTON_DATA_INVALID")]
|
||||
ButtonDataInvalid,
|
||||
|
||||
|
@ -321,7 +321,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendMessage`]
|
||||
///
|
||||
/// [`SendMessage`]: crate::requests::SendMessage
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: can't parse inline keyboard button: Text buttons are \
|
||||
unallowed in the inline keyboard")]
|
||||
TextButtonsAreUnallowed,
|
||||
|
@ -331,7 +331,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`GetFile`]
|
||||
///
|
||||
/// [`GetFile`]: crate::requests::GetFile
|
||||
/// [`GetFile`]: crate::payloads::GetFile
|
||||
#[serde(rename = "Bad Request: wrong file id")]
|
||||
WrongFileID,
|
||||
|
||||
|
@ -344,7 +344,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SetChatPhoto`]
|
||||
///
|
||||
/// [`SetChatPhoto`]: crate::requests::SetChatPhoto
|
||||
/// [`SetChatPhoto`]: crate::payloads::SetChatPhoto
|
||||
#[serde(rename = "Bad Request: Photo should be uploaded as an InputFile")]
|
||||
PhotoAsInputFileRequired,
|
||||
|
||||
|
@ -353,7 +353,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`AddStickerToSet`]
|
||||
///
|
||||
/// [`AddStickerToSet`]: crate::requests::AddStickerToSet
|
||||
/// [`AddStickerToSet`]: crate::payloads::AddStickerToSet
|
||||
#[serde(rename = "Bad Request: STICKERSET_INVALID")]
|
||||
InvalidStickersSet,
|
||||
|
||||
|
@ -363,7 +363,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`PinChatMessage`]
|
||||
///
|
||||
/// [`PinChatMessage`]: crate::requests::PinChatMessage
|
||||
/// [`PinChatMessage`]: crate::payloads::PinChatMessage
|
||||
#[serde(rename = "Bad Request: not enough rights to pin a message")]
|
||||
NotEnoughRightsToPinMessage,
|
||||
|
||||
|
@ -377,7 +377,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`PromoteChatMember`]
|
||||
///
|
||||
/// [`PromoteChatMember`]: crate::requests::PromoteChatMember
|
||||
/// [`PromoteChatMember`]: crate::payloads::PromoteChatMember
|
||||
#[serde(rename = "Bad Request: can't demote chat creator")]
|
||||
CantDemoteChatCreator,
|
||||
|
||||
|
@ -386,7 +386,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`RestrictChatMember`]
|
||||
///
|
||||
/// [`RestrictChatMember`]: crate::requests::RestrictChatMember
|
||||
/// [`RestrictChatMember`]: crate::payloads::RestrictChatMember
|
||||
#[serde(rename = "Bad Request: can't restrict self")]
|
||||
CantRestrictSelf,
|
||||
|
||||
|
@ -396,7 +396,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`RestrictChatMember`]
|
||||
///
|
||||
/// [`RestrictChatMember`]: crate::requests::RestrictChatMember
|
||||
/// [`RestrictChatMember`]: crate::payloads::RestrictChatMember
|
||||
#[serde(rename = "Bad Request: not enough rights to restrict/unrestrict chat member")]
|
||||
NotEnoughRightsToRestrict,
|
||||
|
||||
|
@ -405,7 +405,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SetWebhook`]
|
||||
///
|
||||
/// [`SetWebhook`]: crate::requests::SetWebhook
|
||||
/// [`SetWebhook`]: crate::payloads::SetWebhook
|
||||
#[serde(rename = "Bad Request: bad webhook: HTTPS url must be provided for webhook")]
|
||||
WebhookRequireHTTPS,
|
||||
|
||||
|
@ -415,7 +415,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SetWebhook`]
|
||||
///
|
||||
/// [`SetWebhook`]: crate::requests::SetWebhook
|
||||
/// [`SetWebhook`]: crate::payloads::SetWebhook
|
||||
#[serde(rename = "Bad Request: bad webhook: Webhook can be set up only on ports 80, 88, 443 \
|
||||
or 8443")]
|
||||
BadWebhookPort,
|
||||
|
@ -425,7 +425,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SetWebhook`]
|
||||
///
|
||||
/// [`SetWebhook`]: crate::requests::SetWebhook
|
||||
/// [`SetWebhook`]: crate::payloads::SetWebhook
|
||||
#[serde(rename = "Bad Request: bad webhook: Failed to resolve host: Name or service not known")]
|
||||
UnknownHost,
|
||||
|
||||
|
@ -434,7 +434,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SetWebhook`]
|
||||
///
|
||||
/// [`SetWebhook`]: crate::requests::SetWebhook
|
||||
/// [`SetWebhook`]: crate::payloads::SetWebhook
|
||||
#[serde(rename = "Bad Request: can't parse URL")]
|
||||
CantParseUrl,
|
||||
|
||||
|
@ -443,7 +443,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendMessage`]
|
||||
///
|
||||
/// [`SendMessage`]: crate::requests::SendMessage
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: can't parse entities")]
|
||||
CantParseEntities,
|
||||
|
||||
|
@ -452,7 +452,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`GetUpdates`]
|
||||
///
|
||||
/// [`GetUpdates`]: crate::requests::GetUpdates
|
||||
/// [`GetUpdates`]: crate::payloads::GetUpdates
|
||||
#[serde(rename = "can't use getUpdates method while webhook is active")]
|
||||
CantGetUpdates,
|
||||
|
||||
|
@ -461,7 +461,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendMessage`]
|
||||
///
|
||||
/// [`SendMessage`]: crate::requests::SendMessage
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Unauthorized: bot was kicked from a chat")]
|
||||
BotKicked,
|
||||
|
||||
|
@ -470,7 +470,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendMessage`]
|
||||
///
|
||||
/// [`SendMessage`]: crate::requests::SendMessage
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Unauthorized: user is deactivated")]
|
||||
UserDeactivated,
|
||||
|
||||
|
@ -479,7 +479,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendMessage`]
|
||||
///
|
||||
/// [`SendMessage`]: crate::requests::SendMessage
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Unauthorized: bot can't initiate conversation with a user")]
|
||||
CantInitiateConversation,
|
||||
|
||||
|
@ -488,7 +488,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendMessage`]
|
||||
///
|
||||
/// [`SendMessage`]: crate::requests::SendMessage
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Unauthorized: bot can't send messages to bots")]
|
||||
CantTalkWithBots,
|
||||
|
||||
|
@ -497,7 +497,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`SendMessage`]
|
||||
///
|
||||
/// [`SendMessage`]: crate::requests::SendMessage
|
||||
/// [`SendMessage`]: crate::payloads::SendMessage
|
||||
#[serde(rename = "Bad Request: wrong HTTP URL")]
|
||||
WrongHTTPurl,
|
||||
|
||||
|
@ -507,7 +507,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`GetUpdates`]
|
||||
///
|
||||
/// [`GetUpdates`]: crate::requests::GetUpdates
|
||||
/// [`GetUpdates`]: crate::payloads::GetUpdates
|
||||
#[serde(rename = "Conflict: terminated by other getUpdates request; make sure that only one \
|
||||
bot instance is running")]
|
||||
TerminatedByOtherGetUpdates,
|
||||
|
@ -517,7 +517,7 @@ pub enum ApiError {
|
|||
/// May happen in methods:
|
||||
/// 1. [`GetFile`]
|
||||
///
|
||||
/// [`GetFile`]: crate::requests::GetFile
|
||||
/// [`GetFile`]: crate::payloads::GetFile
|
||||
#[serde(rename = "Bad Request: invalid file id")]
|
||||
FileIdInvalid,
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
pub(crate) use self::{
|
||||
download::{download_file, download_file_stream},
|
||||
request::{request_json, request_json2, request_multipart, request_multipart2},
|
||||
request::{request_json, request_multipart},
|
||||
telegram_response::TelegramResponse,
|
||||
};
|
||||
|
||||
|
|
|
@ -4,80 +4,13 @@ use reqwest::{
|
|||
header::{HeaderValue, CONTENT_TYPE},
|
||||
Client, Response,
|
||||
};
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
use crate::{
|
||||
net::{TelegramResponse, TELEGRAM_API_URL},
|
||||
requests::ResponseResult,
|
||||
serde_multipart::to_form,
|
||||
RequestError,
|
||||
};
|
||||
use crate::{net::TelegramResponse, requests::ResponseResult, RequestError};
|
||||
|
||||
const DELAY_ON_SERVER_ERROR: Duration = Duration::from_secs(10);
|
||||
|
||||
pub async fn request_multipart<P, R>(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
method_name: &str,
|
||||
params: &P, // I'll regret this
|
||||
) -> ResponseResult<R>
|
||||
where
|
||||
P: Serialize,
|
||||
R: DeserializeOwned,
|
||||
{
|
||||
use crate::serde_multipart::Error;
|
||||
let form = match to_form(params).await {
|
||||
Ok(x) => x,
|
||||
Err(Error::Io(ioerr)) => return Err(RequestError::Io(ioerr)),
|
||||
Err(_) => unreachable!(
|
||||
"we don't create requests those fail to serialize (if you see this, open an issue :|)"
|
||||
),
|
||||
};
|
||||
|
||||
let response = client
|
||||
.post(crate::net::method_url(
|
||||
reqwest::Url::parse(TELEGRAM_API_URL).expect("failed to parse default url"),
|
||||
token,
|
||||
method_name,
|
||||
))
|
||||
.multipart(form)
|
||||
.send()
|
||||
.await
|
||||
.map_err(RequestError::NetworkError)?;
|
||||
|
||||
process_response(response).await
|
||||
}
|
||||
|
||||
pub async fn request_json<P, R>(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
method_name: &str,
|
||||
params: &P,
|
||||
) -> ResponseResult<R>
|
||||
where
|
||||
P: Serialize,
|
||||
R: DeserializeOwned,
|
||||
{
|
||||
let response = client
|
||||
.post(crate::net::method_url(
|
||||
reqwest::Url::parse(TELEGRAM_API_URL).expect("failed to parse default url"),
|
||||
token,
|
||||
method_name,
|
||||
))
|
||||
.json(params)
|
||||
.send()
|
||||
.await
|
||||
.map_err(RequestError::NetworkError)?;
|
||||
|
||||
process_response(response).await
|
||||
}
|
||||
|
||||
// FIXME(waffle):
|
||||
// request_{json,mutipart} are currently used in old code, so we keep them
|
||||
// for now when they will not be used anymore, we should remove them
|
||||
// and rename request_{json,mutipart}2 => request_{json,mutipart}
|
||||
|
||||
pub async fn request_multipart2<T>(
|
||||
pub async fn request_multipart<T>(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
api_url: reqwest::Url,
|
||||
|
@ -97,7 +30,7 @@ where
|
|||
process_response(response).await
|
||||
}
|
||||
|
||||
pub async fn request_json2<T>(
|
||||
pub async fn request_json<T>(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
api_url: reqwest::Url,
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
types::{MaskPosition, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::InputSticker,
|
||||
};
|
||||
|
||||
/// Use this method to add a new sticker to a set created by the bot.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#addstickertoset).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct AddStickerToSet {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub user_id: i32,
|
||||
pub name: String,
|
||||
#[serde(flatten)]
|
||||
pub sticker_type: InputSticker,
|
||||
pub emojis: String,
|
||||
pub mask_position: Option<MaskPosition>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for AddStickerToSet {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_multipart(self.bot.client(), self.bot.token(), "addStickerToSet", self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl AddStickerToSet {
|
||||
pub(crate) fn new<N, E>(
|
||||
bot: Bot,
|
||||
user_id: i32,
|
||||
name: N,
|
||||
sticker_type: InputSticker,
|
||||
emojis: E,
|
||||
) -> Self
|
||||
where
|
||||
N: Into<String>,
|
||||
E: Into<String>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
user_id,
|
||||
name: name.into(),
|
||||
sticker_type,
|
||||
emojis: emojis.into(),
|
||||
mask_position: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// User identifier of sticker set owner.
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sticker set name.
|
||||
pub fn name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.name = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn sticker_type(mut self, val: InputSticker) -> Self {
|
||||
self.sticker_type = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// One or more emoji corresponding to the sticker.
|
||||
pub fn emojis<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.emojis = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// A JSON-serialized object for position where the mask should be placed on
|
||||
/// faces.
|
||||
pub fn mask_position(mut self, val: MaskPosition) -> Self {
|
||||
self.mask_position = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::True,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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 top of the chat screen or as an alert.
|
||||
///
|
||||
/// [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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct AnswerCallbackQuery {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub callback_query_id: String,
|
||||
pub text: Option<String>,
|
||||
pub show_alert: Option<bool>,
|
||||
pub url: Option<String>,
|
||||
pub cache_time: Option<i32>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for AnswerCallbackQuery {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "answerCallbackQuery", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl AnswerCallbackQuery {
|
||||
pub(crate) fn new<C>(bot: Bot, callback_query_id: C) -> Self
|
||||
where
|
||||
C: Into<String>,
|
||||
{
|
||||
let callback_query_id = callback_query_id.into();
|
||||
Self { bot, callback_query_id, text: None, show_alert: None, url: None, cache_time: None }
|
||||
}
|
||||
|
||||
/// Unique identifier for the query to be answered.
|
||||
pub fn callback_query_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.callback_query_id = val.into();
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.text = Some(val.into());
|
||||
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 {
|
||||
self.show_alert = Some(val);
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.url = Some(val.into());
|
||||
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 {
|
||||
self.cache_time = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{InlineQueryResult, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send answers to an inline query.
|
||||
///
|
||||
/// 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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct AnswerInlineQuery {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub inline_query_id: String,
|
||||
pub results: Vec<InlineQueryResult>,
|
||||
pub cache_time: Option<i32>,
|
||||
pub is_personal: Option<bool>,
|
||||
pub next_offset: Option<String>,
|
||||
pub switch_pm_text: Option<String>,
|
||||
pub switch_pm_parameter: Option<String>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for AnswerInlineQuery {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "answerInlineQuery", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl AnswerInlineQuery {
|
||||
pub(crate) fn new<I, R>(bot: Bot, inline_query_id: I, results: R) -> Self
|
||||
where
|
||||
I: Into<String>,
|
||||
R: Into<Vec<InlineQueryResult>>,
|
||||
{
|
||||
let inline_query_id = inline_query_id.into();
|
||||
let results = results.into();
|
||||
Self {
|
||||
bot,
|
||||
inline_query_id,
|
||||
results,
|
||||
cache_time: None,
|
||||
is_personal: None,
|
||||
next_offset: None,
|
||||
switch_pm_text: None,
|
||||
switch_pm_parameter: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Unique identifier for the answered query.
|
||||
pub fn inline_query_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.inline_query_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// A JSON-serialized array of results for the inline query.
|
||||
pub fn results<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<Vec<InlineQueryResult>>,
|
||||
{
|
||||
self.results = val.into();
|
||||
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 {
|
||||
self.cache_time = Some(val);
|
||||
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)]
|
||||
pub fn is_personal(mut self, val: bool) -> Self {
|
||||
self.is_personal = Some(val);
|
||||
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 don‘t
|
||||
/// support pagination. Offset length can’t exceed 64 bytes.
|
||||
pub fn next_offset<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.next_offset = Some(val.into());
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.switch_pm_text = Some(val.into());
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.switch_pm_parameter = Some(val.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::True,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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
|
||||
/// `pre_checkout_query`. Use this method to respond to such pre-checkout
|
||||
/// queries.
|
||||
///
|
||||
/// # Note
|
||||
/// The Bot API must receive an answer within 10 seconds after 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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct AnswerPreCheckoutQuery {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub pre_checkout_query_id: String,
|
||||
pub ok: bool,
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for AnswerPreCheckoutQuery {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "answerPreCheckoutQuery", &self)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl AnswerPreCheckoutQuery {
|
||||
pub(crate) fn new<P>(bot: Bot, pre_checkout_query_id: P, ok: bool) -> Self
|
||||
where
|
||||
P: Into<String>,
|
||||
{
|
||||
let pre_checkout_query_id = pre_checkout_query_id.into();
|
||||
Self { bot, pre_checkout_query_id, ok, error_message: None }
|
||||
}
|
||||
|
||||
/// Unique identifier for the query to be answered.
|
||||
pub fn pre_checkout_query_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.pre_checkout_query_id = val.into();
|
||||
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 {
|
||||
self.ok = val;
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.error_message = Some(val.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ShippingOption, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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
|
||||
/// shipping_query field to the bot. Use this method to reply to shipping
|
||||
/// queries.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#answershippingquery).
|
||||
///
|
||||
/// [`Update`]: crate::types::Update
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct AnswerShippingQuery {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub shipping_query_id: String,
|
||||
pub ok: bool,
|
||||
pub shipping_options: Option<Vec<ShippingOption>>,
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for AnswerShippingQuery {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "answerShippingQuery", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl AnswerShippingQuery {
|
||||
pub(crate) fn new<S>(bot: Bot, shipping_query_id: S, ok: bool) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
let shipping_query_id = shipping_query_id.into();
|
||||
Self { bot, shipping_query_id, ok, shipping_options: None, error_message: None }
|
||||
}
|
||||
|
||||
/// Unique identifier for the query to be answered.
|
||||
pub fn shipping_query_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.shipping_query_id = val.into();
|
||||
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 {
|
||||
self.ok = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// Required if ok is `true`. A JSON-serialized array of available shipping
|
||||
/// options.
|
||||
pub fn shipping_options<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<Vec<ShippingOption>>,
|
||||
{
|
||||
self.shipping_options = Some(val.into());
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.error_message = Some(val.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,120 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{InputSticker, MaskPosition, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to create new sticker set owned by a user. The bot will be
|
||||
/// able to edit the created sticker set.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#createnewstickerset).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct CreateNewStickerSet {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub user_id: i32,
|
||||
pub name: String,
|
||||
pub title: String,
|
||||
#[serde(flatten)]
|
||||
pub sticker: InputSticker,
|
||||
pub emojis: String,
|
||||
pub contains_masks: Option<bool>,
|
||||
pub mask_position: Option<MaskPosition>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for CreateNewStickerSet {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_multipart(self.bot.client(), self.bot.token(), "createNewStickerSet", self)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl CreateNewStickerSet {
|
||||
pub(crate) fn new<N, T, E>(
|
||||
bot: Bot,
|
||||
user_id: i32,
|
||||
name: N,
|
||||
title: T,
|
||||
sticker_type: InputSticker,
|
||||
emojis: E,
|
||||
) -> Self
|
||||
where
|
||||
N: Into<String>,
|
||||
T: Into<String>,
|
||||
E: Into<String>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
user_id,
|
||||
name: name.into(),
|
||||
title: title.into(),
|
||||
sticker: sticker_type,
|
||||
emojis: emojis.into(),
|
||||
contains_masks: None,
|
||||
mask_position: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// User identifier of created sticker set owner.
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.name = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Sticker set title, 1-64 characters.
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.title = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn sticker_type(mut self, val: InputSticker) -> Self {
|
||||
self.sticker = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// One or more emoji corresponding to the sticker.
|
||||
pub fn emojis<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.emojis = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Pass `true`, if a set of mask stickers should be created.
|
||||
pub fn contains_masks(mut self, val: bool) -> Self {
|
||||
self.contains_masks = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// A JSON-serialized object for position where the mask should be placed on
|
||||
/// faces.
|
||||
pub fn mask_position(mut self, val: MaskPosition) -> Self {
|
||||
self.mask_position = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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
|
||||
/// must have the appropriate admin rights.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#deletechatphoto).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct DeleteChatPhoto {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for DeleteChatPhoto {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "deleteChatPhoto", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl DeleteChatPhoto {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to delete a group sticker set from a supergroup.
|
||||
///
|
||||
/// 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 [`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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct DeleteChatStickerSet {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for DeleteChatStickerSet {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "deleteChatStickerSet", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl DeleteChatStickerSet {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to delete a message, including service messages.
|
||||
///
|
||||
/// The limitations are:
|
||||
/// - A message can only be deleted if it was sent less than 48 hours ago.
|
||||
/// - Bots can delete outgoing messages in private chats, groups, and
|
||||
/// supergroups.
|
||||
/// - Bots can delete incoming messages in private chats.
|
||||
/// - Bots granted can_post_messages permissions can delete outgoing messages
|
||||
/// 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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct DeleteMessage {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub message_id: i32,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for DeleteMessage {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "deleteMessage", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl DeleteMessage {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, message_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Identifier of the message to delete.
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.message_id = val;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::True,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to delete a sticker from a set created by the bot.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#deletestickerfromset).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct DeleteStickerFromSet {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub sticker: String,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for DeleteStickerFromSet {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "deleteStickerFromSet", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl DeleteStickerFromSet {
|
||||
pub(crate) fn new<S>(bot: Bot, sticker: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
let sticker = sticker.into();
|
||||
Self { bot, sticker }
|
||||
}
|
||||
|
||||
/// File identifier of the sticker.
|
||||
pub fn sticker<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.sticker = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::True,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to remove webhook integration if you decide to switch back
|
||||
/// 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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct DeleteWebhook {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for DeleteWebhook {
|
||||
type Output = True;
|
||||
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "deleteWebhook", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl DeleteWebhook {
|
||||
pub(crate) fn new(bot: Bot) -> Self {
|
||||
Self { bot }
|
||||
}
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{InlineKeyboardMarkup, ParseMode, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to edit captions of messages sent via the bot.
|
||||
///
|
||||
/// On success, [`True`] is returned.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#editmessagecaption).
|
||||
///
|
||||
/// [`True`]: crate::types::True
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct EditInlineMessageCaption {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub inline_message_id: String,
|
||||
pub caption: Option<String>,
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for EditInlineMessageCaption {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "editMessageCaption", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl EditInlineMessageCaption {
|
||||
pub(crate) fn new<I>(bot: Bot, inline_message_id: I) -> Self
|
||||
where
|
||||
I: Into<String>,
|
||||
{
|
||||
let inline_message_id = inline_message_id.into();
|
||||
Self { bot, inline_message_id, caption: None, parse_mode: None, reply_markup: None }
|
||||
}
|
||||
|
||||
/// Identifier of the inline message.
|
||||
pub fn inline_message_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.inline_message_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// New caption of the message.
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(val.into());
|
||||
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 {
|
||||
self.parse_mode = Some(val);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{InlineKeyboardMarkup, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to edit live location messages sent via the bot.
|
||||
///
|
||||
/// A location can be edited until its live_period expires or editing is
|
||||
/// explicitly disabled by a call to stopMessageLiveLocation. On success,
|
||||
/// [`True`] is returned.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#editmessagelivelocation).
|
||||
///
|
||||
/// [`True`]: crate::types::True
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct EditInlineMessageLiveLocation {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub inline_message_id: String,
|
||||
pub latitude: f32,
|
||||
pub longitude: f32,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for EditInlineMessageLiveLocation {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "editMessageLiveLocation", &self)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl EditInlineMessageLiveLocation {
|
||||
pub(crate) fn new<I>(bot: Bot, inline_message_id: I, latitude: f32, longitude: f32) -> Self
|
||||
where
|
||||
I: Into<String>,
|
||||
{
|
||||
let inline_message_id = inline_message_id.into();
|
||||
Self { bot, inline_message_id, latitude, longitude, reply_markup: None }
|
||||
}
|
||||
|
||||
/// Identifier of the inline message.
|
||||
pub fn inline_message_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.inline_message_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Latitude of new location.
|
||||
pub fn latitude(mut self, val: f32) -> Self {
|
||||
self.latitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// Longitude of new location.
|
||||
pub fn longitude(mut self, val: f32) -> Self {
|
||||
self.longitude = val;
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{InlineKeyboardMarkup, InputMedia, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to edit animation, audio, document, photo, or video
|
||||
/// messages sent via the bot.
|
||||
///
|
||||
/// If a message is a part of a message album, then it can be edited only to a
|
||||
/// photo or a video. Otherwise, message type can be changed arbitrarily. When
|
||||
/// this method is used, new file can't be uploaded. Use previously
|
||||
/// uploaded file via its `file_id` or specify a URL. On success, [`True`] is
|
||||
/// returned.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#editmessagemedia).
|
||||
///
|
||||
/// [`True`]: crate::types::True
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct EditInlineMessageMedia {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub inline_message_id: String,
|
||||
pub media: InputMedia,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for EditInlineMessageMedia {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_multipart(self.bot.client(), self.bot.token(), "editMessageMedia", self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl EditInlineMessageMedia {
|
||||
pub(crate) fn new<I>(bot: Bot, inline_message_id: I, media: InputMedia) -> Self
|
||||
where
|
||||
I: Into<String>,
|
||||
{
|
||||
let inline_message_id = inline_message_id.into();
|
||||
Self { bot, inline_message_id, media, reply_markup: None }
|
||||
}
|
||||
|
||||
/// Identifier of the inline message.
|
||||
pub fn inline_message_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.inline_message_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// A JSON-serialized object for a new media content of the message.
|
||||
pub fn media(mut self, val: InputMedia) -> Self {
|
||||
self.media = val;
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{InlineKeyboardMarkup, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to edit only the reply markup of messages sent via the bot.
|
||||
///
|
||||
/// On success, [`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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct EditInlineMessageReplyMarkup {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub inline_message_id: String,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for EditInlineMessageReplyMarkup {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "editMessageReplyMarkup", &self)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl EditInlineMessageReplyMarkup {
|
||||
pub(crate) fn new<I>(bot: Bot, inline_message_id: I) -> Self
|
||||
where
|
||||
I: Into<String>,
|
||||
{
|
||||
let inline_message_id = inline_message_id.into();
|
||||
Self { bot, inline_message_id, reply_markup: None }
|
||||
}
|
||||
|
||||
/// Identifier of the inline message.
|
||||
pub fn inline_message_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.inline_message_id = val.into();
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{InlineKeyboardMarkup, Message, ParseMode},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to edit text and game messages sent via the bot.
|
||||
///
|
||||
/// On success, [`True`] is returned.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#editmessagetext).
|
||||
///
|
||||
/// [`True`]: crate::types::True
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct EditInlineMessageText {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub inline_message_id: String,
|
||||
pub text: String,
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
pub disable_web_page_preview: Option<bool>,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for EditInlineMessageText {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "editMessageText", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl EditInlineMessageText {
|
||||
pub(crate) fn new<I, T>(bot: Bot, inline_message_id: I, text: T) -> Self
|
||||
where
|
||||
I: Into<String>,
|
||||
T: Into<String>,
|
||||
{
|
||||
let inline_message_id = inline_message_id.into();
|
||||
let text = text.into();
|
||||
Self {
|
||||
bot,
|
||||
inline_message_id,
|
||||
text,
|
||||
parse_mode: None,
|
||||
disable_web_page_preview: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Identifier of the inline message.
|
||||
pub fn inline_message_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.inline_message_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// New text of the message.
|
||||
pub fn text<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.text = val.into();
|
||||
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 {
|
||||
self.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Disables link previews for links in this message.
|
||||
pub fn disable_web_page_preview(mut self, val: bool) -> Self {
|
||||
self.disable_web_page_preview = Some(val);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InlineKeyboardMarkup, Message, ParseMode},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to edit captions of messages sent by the bot.
|
||||
///
|
||||
/// On success, the edited [`Message`] is returned.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#editmessagecaption).
|
||||
///
|
||||
/// [`Message`]: crate::types::Message
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct EditMessageCaption {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub message_id: i32,
|
||||
pub caption: Option<String>,
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for EditMessageCaption {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "editMessageCaption", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageCaption {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, message_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id, message_id, caption: None, parse_mode: 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Identifier of the message to edit
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.message_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// New caption of the message.
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(val.into());
|
||||
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 {
|
||||
self.parse_mode = Some(val);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InlineKeyboardMarkup, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to edit live location messages.
|
||||
///
|
||||
/// A location can be edited until its live_period expires or editing is
|
||||
/// explicitly disabled by a call to stopMessageLiveLocation. On success, the
|
||||
/// edited [`Message`] is returned.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#editmessagelivelocation).
|
||||
///
|
||||
/// [`Message`]: crate::types::Message
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct EditMessageLiveLocation {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub message_id: i32,
|
||||
pub latitude: f32,
|
||||
pub longitude: f32,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for EditMessageLiveLocation {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "editMessageLiveLocation", &self)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageLiveLocation {
|
||||
pub(crate) fn new<C>(
|
||||
bot: Bot,
|
||||
chat_id: C,
|
||||
message_id: i32,
|
||||
latitude: f32,
|
||||
longitude: f32,
|
||||
) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id, message_id, latitude, longitude, 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Identifier of the message to edit
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.message_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// Latitude of new location.
|
||||
pub fn latitude(mut self, val: f32) -> Self {
|
||||
self.latitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// Longitude of new location.
|
||||
pub fn longitude(mut self, val: f32) -> Self {
|
||||
self.longitude = val;
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InlineKeyboardMarkup, InputMedia, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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 only to a
|
||||
/// photo or a video. Otherwise, message type can be changed arbitrarily. On
|
||||
/// success, the edited [`Message`] is returned.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#editmessagemedia).
|
||||
///
|
||||
/// [`Message`]: crate::types::Message
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct EditMessageMedia {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub message_id: i32,
|
||||
pub media: InputMedia,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for EditMessageMedia {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_multipart(self.bot.client(), self.bot.token(), "editMessageMedia", self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageMedia {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, message_id: i32, media: InputMedia) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id, message_id, media, 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Identifier of the message to edit
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.message_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// A JSON-serialized object for a new media content of the message.
|
||||
pub fn media(mut self, val: InputMedia) -> Self {
|
||||
self.media = val;
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InlineKeyboardMarkup, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to edit only the reply markup of messages.
|
||||
///
|
||||
/// On success, the edited [`Message`] is returned.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#editmessagereplymarkup).
|
||||
///
|
||||
/// [`Message`]: crate::types::Message
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct EditMessageReplyMarkup {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub message_id: i32,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for EditMessageReplyMarkup {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "editMessageReplyMarkup", &self)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageReplyMarkup {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, message_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id, message_id, 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Identifier of the message to edit
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.message_id = val;
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InlineKeyboardMarkup, Message, ParseMode},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to edit text and game messages.
|
||||
///
|
||||
/// On success, the edited [`Message`] is returned.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#editmessagetext).
|
||||
///
|
||||
/// [`Message`]: crate::types::Message
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct EditMessageText {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub message_id: i32,
|
||||
pub text: String,
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
pub disable_web_page_preview: Option<bool>,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for EditMessageText {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "editMessageText", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageText {
|
||||
pub(crate) fn new<C, T>(bot: Bot, chat_id: C, message_id: i32, text: T) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
T: Into<String>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let text = text.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
message_id,
|
||||
text,
|
||||
parse_mode: None,
|
||||
disable_web_page_preview: 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Identifier of the message to edit
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.message_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// New text of the message.
|
||||
pub fn text<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.text = val.into();
|
||||
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 {
|
||||
self.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Disables link previews for links in this message.
|
||||
pub fn disable_web_page_preview(mut self, val: bool) -> Self {
|
||||
self.disable_web_page_preview = Some(val);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::ChatId,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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 this to work and must have
|
||||
/// the appropriate admin rights.
|
||||
///
|
||||
/// ## Note
|
||||
/// Each administrator in a chat generates their own invite links. Bots can't
|
||||
/// use invite links generated by other administrators. If you want your bot to
|
||||
/// 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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct ExportChatInviteLink {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for ExportChatInviteLink {
|
||||
type Output = String;
|
||||
|
||||
/// Returns the new invite link as `String` on success.
|
||||
async fn send(&self) -> ResponseResult<String> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "exportChatInviteLink", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl ExportChatInviteLink {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to forward messages of any kind.
|
||||
///
|
||||
/// [`The official docs`](https://core.telegram.org/bots/api#forwardmessage).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct ForwardMessage {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub from_chat_id: ChatId,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub message_id: i32,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for ForwardMessage {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "forwardMessage", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl ForwardMessage {
|
||||
pub(crate) fn new<C, F>(bot: Bot, chat_id: C, from_chat_id: F, message_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
F: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let from_chat_id = from_chat_id.into();
|
||||
Self { bot, chat_id, from_chat_id, message_id, 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Unique identifier for the chat where the original message was sent (or
|
||||
/// channel username in the format `@channelusername`).
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
pub fn from_chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.from_chat_id = val.into();
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
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 {
|
||||
self.message_id = val;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{Chat, ChatId},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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
|
||||
/// or channel, etc.).
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#getchat).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetChat {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for GetChat {
|
||||
type Output = Chat;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Chat> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "getChat", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChat {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, ChatMember},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to get a list of administrators in a chat.
|
||||
///
|
||||
/// If the chat is a group or a supergroup and no administrators were appointed,
|
||||
/// only the creator will be returned.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#getchatadministrators).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetChatAdministrators {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for GetChatAdministrators {
|
||||
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>> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "getChatAdministrators", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChatAdministrators {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, ChatMember},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to get information about a member of a chat.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#getchatmember).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetChatMember {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub user_id: i32,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for GetChatMember {
|
||||
type Output = ChatMember;
|
||||
|
||||
async fn send(&self) -> ResponseResult<ChatMember> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "getChatMember", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChatMember {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, user_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Unique identifier of the target user.
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::ChatId,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to get the number of members in a chat.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#getchatmemberscount).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetChatMembersCount {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for GetChatMembersCount {
|
||||
type Output = i32;
|
||||
|
||||
async fn send(&self) -> ResponseResult<i32> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "getChatMembersCount", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChatMembersCount {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::File,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// The file can then be downloaded via the link
|
||||
/// `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
|
||||
/// for at least `1` hour. When the link expires, a new one can be requested by
|
||||
/// calling [`GetFile`] again.
|
||||
///
|
||||
/// **Note**: This function may not preserve the original file name and MIME
|
||||
/// type. You should save the file's MIME type and name (if available) when the
|
||||
/// [`File`] object is received.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#getfile).
|
||||
///
|
||||
/// [`File`]: crate::types::File
|
||||
/// [`GetFile`]: self::GetFile
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetFile {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub file_id: String,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for GetFile {
|
||||
type Output = File;
|
||||
|
||||
async fn send(&self) -> ResponseResult<File> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "getFile", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetFile {
|
||||
pub(crate) fn new<F>(bot: Bot, file_id: F) -> Self
|
||||
where
|
||||
F: Into<String>,
|
||||
{
|
||||
Self { bot, file_id: file_id.into() }
|
||||
}
|
||||
|
||||
/// File identifier to get info about.
|
||||
pub fn file_id<F>(mut self, value: F) -> Self
|
||||
where
|
||||
F: Into<String>,
|
||||
{
|
||||
self.file_id = value.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{GameHighScore, TargetMessage},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to get data for high score tables.
|
||||
///
|
||||
/// Will return the score of the specified user and several of his neighbors in
|
||||
/// a game.
|
||||
///
|
||||
/// ## 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)
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetGameHighScores {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
#[serde(flatten)]
|
||||
pub target: TargetMessage,
|
||||
pub user_id: i32,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for GetGameHighScores {
|
||||
type Output = Vec<GameHighScore>;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Vec<GameHighScore>> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "getGameHighScores", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetGameHighScores {
|
||||
pub(crate) fn new<T>(bot: Bot, target: T, user_id: i32) -> Self
|
||||
where
|
||||
T: Into<TargetMessage>,
|
||||
{
|
||||
let target = target.into();
|
||||
Self { bot, target, user_id }
|
||||
}
|
||||
|
||||
/// Target message, either chat id and message id or inline message id.
|
||||
pub fn target<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<TargetMessage>,
|
||||
{
|
||||
self.target = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Target user id.
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::Me,
|
||||
Bot,
|
||||
};
|
||||
use serde::Serialize;
|
||||
|
||||
/// A simple method for testing your bot's auth token. Requires no parameters.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#getme).
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetMe {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for GetMe {
|
||||
type Output = Me;
|
||||
|
||||
/// Returns basic information about the bot.
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
async fn send(&self) -> ResponseResult<Me> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "getMe", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetMe {
|
||||
pub(crate) fn new(bot: Bot) -> Self {
|
||||
Self { bot }
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::BotCommand,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to get the current list of the bot's commands.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#getmycommands).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetMyCommands {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for GetMyCommands {
|
||||
type Output = Vec<BotCommand>;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Self::Output> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "getMyCommands", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetMyCommands {
|
||||
pub(crate) fn new(bot: Bot) -> Self {
|
||||
Self { bot }
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::StickerSet,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to get a sticker set.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#getstickerset).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetStickerSet {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for GetStickerSet {
|
||||
type Output = StickerSet;
|
||||
|
||||
async fn send(&self) -> ResponseResult<StickerSet> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "getStickerSet", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetStickerSet {
|
||||
pub(crate) fn new<N>(bot: Bot, name: N) -> Self
|
||||
where
|
||||
N: Into<String>,
|
||||
{
|
||||
let name = name.into();
|
||||
Self { bot, name }
|
||||
}
|
||||
|
||||
/// Name of the sticker set.
|
||||
pub fn name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.name = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{AllowedUpdate, Update},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to receive incoming updates using long polling ([wiki]).
|
||||
///
|
||||
/// **Notes:**
|
||||
/// 1. This method will not work if an outgoing webhook is set up.
|
||||
/// 2. In order to avoid getting duplicate updates,
|
||||
/// 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
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetUpdates {
|
||||
#[serde(skip_serializing)]
|
||||
pub(crate) bot: Bot,
|
||||
pub offset: Option<i32>,
|
||||
pub limit: Option<u8>,
|
||||
pub timeout: Option<u32>,
|
||||
pub allowed_updates: Option<Vec<AllowedUpdate>>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for GetUpdates {
|
||||
type Output = Vec<Update>;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Self::Output> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "getUpdates", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetUpdates {
|
||||
pub(crate) fn new(bot: Bot) -> Self {
|
||||
Self { bot, offset: None, limit: None, timeout: None, allowed_updates: None }
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
self.offset = Some(value);
|
||||
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 {
|
||||
self.limit = Some(value);
|
||||
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 {
|
||||
self.timeout = Some(value);
|
||||
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
|
||||
where
|
||||
T: Into<Vec<AllowedUpdate>>,
|
||||
{
|
||||
self.allowed_updates = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{GetUpdates, RequestOld, ResponseResult},
|
||||
types::{AllowedUpdate, NonStrictVec, Update},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// This is non strict version of [`GetUpdates`], this means that if it will
|
||||
/// fail to deserialize some updates, it won't fail entirely, but will just
|
||||
/// return some errors.
|
||||
///
|
||||
/// Note: this is not a 'real' telegram method, this is simply [`GetUpdates`]
|
||||
/// with changed return type.
|
||||
///
|
||||
/// [`GetUpdates`]: crate::requests::GetUpdates
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct GetUpdatesNonStrict(pub GetUpdates);
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for GetUpdatesNonStrict {
|
||||
type Output = NonStrictVec<Update>;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Self::Output> {
|
||||
net::request_json(self.0.bot.client(), self.0.bot.token(), "getUpdates", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetUpdatesNonStrict {
|
||||
pub(crate) fn new(bot: Bot) -> Self {
|
||||
Self(GetUpdates::new(bot))
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
self.0.offset = Some(value);
|
||||
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 {
|
||||
self.0.limit = Some(value);
|
||||
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 {
|
||||
self.0.timeout = Some(value);
|
||||
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
|
||||
where
|
||||
T: Into<Vec<AllowedUpdate>>,
|
||||
{
|
||||
self.0.allowed_updates = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::UserProfilePhotos,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to get a list of profile pictures for a user.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#getuserprofilephotos).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetUserProfilePhotos {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub user_id: i32,
|
||||
pub offset: Option<i32>,
|
||||
pub limit: Option<i32>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for GetUserProfilePhotos {
|
||||
type Output = UserProfilePhotos;
|
||||
|
||||
async fn send(&self) -> ResponseResult<UserProfilePhotos> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "getUserProfilePhotos", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetUserProfilePhotos {
|
||||
pub(crate) fn new(bot: Bot, user_id: i32) -> Self {
|
||||
Self { bot, user_id, offset: None, limit: None }
|
||||
}
|
||||
|
||||
/// Unique identifier of the target user.
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sequential number of the first photo to be returned. By default, all
|
||||
/// photos are returned.
|
||||
pub fn offset(mut self, val: i32) -> Self {
|
||||
self.offset = Some(val);
|
||||
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 {
|
||||
self.limit = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::WebhookInfo,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to get current webhook status.
|
||||
///
|
||||
/// If the bot is using [`Bot::get_updates`], will return an object with the url
|
||||
/// field empty.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#getwebhookinfo).
|
||||
///
|
||||
/// [`Bot::get_updates`]: crate::Bot::get_updates
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetWebhookInfo {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for GetWebhookInfo {
|
||||
type Output = WebhookInfo;
|
||||
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
async fn send(&self) -> ResponseResult<WebhookInfo> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "getWebhookInfo", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetWebhookInfo {
|
||||
pub(crate) fn new(bot: Bot) -> Self {
|
||||
Self { bot }
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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 the group on their own using invite links, etc., unless [unbanned] first.
|
||||
/// 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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct KickChatMember {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub user_id: i32,
|
||||
pub until_date: Option<i32>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for KickChatMember {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "kickChatMember", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl KickChatMember {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, user_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id, user_id, 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Unique identifier of the target user.
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
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 {
|
||||
self.until_date = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method for your bot to leave a group, supergroup or channel.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#leavechat).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct LeaveChat {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for LeaveChat {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "leaveChat", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl LeaveChat {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,154 +0,0 @@
|
|||
mod add_sticker_to_set;
|
||||
mod answer_callback_query;
|
||||
mod answer_inline_query;
|
||||
mod answer_pre_checkout_query;
|
||||
mod answer_shipping_query;
|
||||
mod create_new_sticker_set;
|
||||
mod delete_chat_photo;
|
||||
mod delete_chat_sticker_set;
|
||||
mod delete_message;
|
||||
mod delete_sticker_from_set;
|
||||
mod delete_webhook;
|
||||
mod edit_inline_message_caption;
|
||||
mod edit_inline_message_live_location;
|
||||
mod edit_inline_message_media;
|
||||
mod edit_inline_message_reply_markup;
|
||||
mod edit_inline_message_text;
|
||||
mod edit_message_caption;
|
||||
mod edit_message_live_location;
|
||||
mod edit_message_media;
|
||||
mod edit_message_reply_markup;
|
||||
mod edit_message_text;
|
||||
mod export_chat_invite_link;
|
||||
mod forward_message;
|
||||
mod get_chat;
|
||||
mod get_chat_administrators;
|
||||
mod get_chat_member;
|
||||
mod get_chat_members_count;
|
||||
mod get_file;
|
||||
mod get_game_high_scores;
|
||||
mod get_me;
|
||||
mod get_my_commands;
|
||||
mod get_sticker_set;
|
||||
mod get_updates;
|
||||
mod get_updates_non_strict;
|
||||
mod get_user_profile_photos;
|
||||
mod get_webhook_info;
|
||||
mod kick_chat_member;
|
||||
mod leave_chat;
|
||||
mod pin_chat_message;
|
||||
mod promote_chat_member;
|
||||
mod restrict_chat_member;
|
||||
mod send_animation;
|
||||
mod send_audio;
|
||||
mod send_chat_action;
|
||||
mod send_contact;
|
||||
mod send_dice;
|
||||
mod send_document;
|
||||
mod send_game;
|
||||
mod send_invoice;
|
||||
mod send_location;
|
||||
mod send_media_group;
|
||||
mod send_message;
|
||||
mod send_photo;
|
||||
mod send_poll;
|
||||
mod send_sticker;
|
||||
mod send_venue;
|
||||
mod send_video;
|
||||
mod send_video_note;
|
||||
mod send_voice;
|
||||
mod set_chat_administrator_custom_title;
|
||||
mod set_chat_description;
|
||||
mod set_chat_permissions;
|
||||
mod set_chat_photo;
|
||||
mod set_chat_sticker_set;
|
||||
mod set_chat_title;
|
||||
mod set_game_score;
|
||||
mod set_my_commands;
|
||||
mod set_sticker_position_in_set;
|
||||
mod set_sticker_set_thumb;
|
||||
mod set_webhook;
|
||||
mod stop_inline_message_live_location;
|
||||
mod stop_message_live_location;
|
||||
mod stop_poll;
|
||||
mod unban_chat_member;
|
||||
mod unpin_chat_message;
|
||||
mod upload_sticker_file;
|
||||
|
||||
pub use add_sticker_to_set::*;
|
||||
pub use answer_callback_query::*;
|
||||
pub use answer_inline_query::*;
|
||||
pub use answer_pre_checkout_query::*;
|
||||
pub use answer_shipping_query::*;
|
||||
pub use create_new_sticker_set::*;
|
||||
pub use delete_chat_photo::*;
|
||||
pub use delete_chat_sticker_set::*;
|
||||
pub use delete_message::*;
|
||||
pub use delete_sticker_from_set::*;
|
||||
pub use delete_webhook::*;
|
||||
pub use edit_inline_message_caption::*;
|
||||
pub use edit_inline_message_live_location::*;
|
||||
pub use edit_inline_message_media::*;
|
||||
pub use edit_inline_message_reply_markup::*;
|
||||
pub use edit_inline_message_text::*;
|
||||
pub use edit_message_caption::*;
|
||||
pub use edit_message_live_location::*;
|
||||
pub use edit_message_media::*;
|
||||
pub use edit_message_reply_markup::*;
|
||||
pub use edit_message_text::*;
|
||||
pub use export_chat_invite_link::*;
|
||||
pub use forward_message::*;
|
||||
pub use get_chat::*;
|
||||
pub use get_chat_administrators::*;
|
||||
pub use get_chat_member::*;
|
||||
pub use get_chat_members_count::*;
|
||||
pub use get_file::*;
|
||||
pub use get_game_high_scores::*;
|
||||
pub use get_me::*;
|
||||
pub use get_my_commands::*;
|
||||
pub use get_sticker_set::*;
|
||||
pub use get_updates::*;
|
||||
pub use get_updates_non_strict::*;
|
||||
pub use get_user_profile_photos::*;
|
||||
pub use get_webhook_info::*;
|
||||
pub use kick_chat_member::*;
|
||||
pub use leave_chat::*;
|
||||
pub use pin_chat_message::*;
|
||||
pub use promote_chat_member::*;
|
||||
pub use restrict_chat_member::*;
|
||||
pub use send_animation::*;
|
||||
pub use send_audio::*;
|
||||
pub use send_chat_action::*;
|
||||
pub use send_contact::*;
|
||||
pub use send_dice::*;
|
||||
pub use send_document::*;
|
||||
pub use send_game::*;
|
||||
pub use send_invoice::*;
|
||||
pub use send_location::*;
|
||||
pub use send_media_group::*;
|
||||
pub use send_message::*;
|
||||
pub use send_photo::*;
|
||||
pub use send_poll::*;
|
||||
pub use send_sticker::*;
|
||||
pub use send_venue::*;
|
||||
pub use send_video::*;
|
||||
pub use send_video_note::*;
|
||||
pub use send_voice::*;
|
||||
pub use set_chat_administrator_custom_title::*;
|
||||
pub use set_chat_description::*;
|
||||
pub use set_chat_permissions::*;
|
||||
pub use set_chat_photo::*;
|
||||
pub use set_chat_sticker_set::*;
|
||||
pub use set_chat_title::*;
|
||||
pub use set_game_score::*;
|
||||
pub use set_my_commands::*;
|
||||
pub use set_sticker_position_in_set::*;
|
||||
pub use set_sticker_set_thumb::*;
|
||||
pub use set_webhook::*;
|
||||
pub use std::pin::Pin;
|
||||
pub use stop_inline_message_live_location::*;
|
||||
pub use stop_message_live_location::*;
|
||||
pub use stop_poll::*;
|
||||
pub use unban_chat_member::*;
|
||||
pub use unpin_chat_message::*;
|
||||
pub use upload_sticker_file::*;
|
|
@ -1,69 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to pin 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 `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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct PinChatMessage {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub message_id: i32,
|
||||
pub disable_notification: Option<bool>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for PinChatMessage {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "pinChatMessage", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl PinChatMessage {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, message_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id, message_id, 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Identifier of a message to pin.
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.message_id = val;
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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 appropriate admin rights. Pass False for all boolean parameters to
|
||||
/// demote a user.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#promotechatmember).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct PromoteChatMember {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub user_id: i32,
|
||||
pub can_change_info: Option<bool>,
|
||||
pub can_post_messages: Option<bool>,
|
||||
pub can_edit_messages: Option<bool>,
|
||||
pub can_delete_messages: Option<bool>,
|
||||
pub can_invite_users: Option<bool>,
|
||||
pub can_restrict_members: Option<bool>,
|
||||
pub can_pin_messages: Option<bool>,
|
||||
pub can_promote_members: Option<bool>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for PromoteChatMember {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "promoteChatMember", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl PromoteChatMember {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, user_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
user_id,
|
||||
can_change_info: None,
|
||||
can_post_messages: None,
|
||||
can_edit_messages: None,
|
||||
can_delete_messages: None,
|
||||
can_invite_users: None,
|
||||
can_restrict_members: None,
|
||||
can_pin_messages: None,
|
||||
can_promote_members: 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Unique identifier of the target user.
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// Pass `true`, if the administrator can change chat title, photo and other
|
||||
/// settings.
|
||||
pub fn can_change_info(mut self, val: bool) -> Self {
|
||||
self.can_change_info = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Pass `true`, if the administrator can create channel posts, channels
|
||||
/// only.
|
||||
pub fn can_post_messages(mut self, val: bool) -> Self {
|
||||
self.can_post_messages = Some(val);
|
||||
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 {
|
||||
self.can_edit_messages = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Pass `true`, if the administrator can delete messages of other users.
|
||||
pub fn can_delete_messages(mut self, val: bool) -> Self {
|
||||
self.can_delete_messages = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Pass `true`, if the administrator can invite new users to the chat.
|
||||
pub fn can_invite_users(mut self, val: bool) -> Self {
|
||||
self.can_invite_users = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Pass `true`, if the administrator can restrict, ban or unban chat
|
||||
/// members.
|
||||
pub fn can_restrict_members(mut self, val: bool) -> Self {
|
||||
self.can_restrict_members = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Pass `true`, if the administrator can pin messages, supergroups only.
|
||||
pub fn can_pin_messages(mut self, val: bool) -> Self {
|
||||
self.can_pin_messages = Some(val);
|
||||
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 {
|
||||
self.can_promote_members = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, ChatPermissions, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to restrict a user in a supergroup.
|
||||
///
|
||||
/// The bot must be an administrator in the supergroup for this to work and must
|
||||
/// 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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct RestrictChatMember {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub user_id: i32,
|
||||
pub permissions: ChatPermissions,
|
||||
pub until_date: Option<i32>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for RestrictChatMember {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "restrictChatMember", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl RestrictChatMember {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, user_id: i32, permissions: ChatPermissions) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id, user_id, permissions, until_date: None }
|
||||
}
|
||||
|
||||
/// 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Unique identifier of the target user.
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// New user permissions.
|
||||
pub fn permissions(mut self, val: ChatPermissions) -> Self {
|
||||
self.permissions = val;
|
||||
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 {
|
||||
self.until_date = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,158 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send animation files (GIF or H.264/MPEG-4 AVC video
|
||||
/// without sound).
|
||||
///
|
||||
/// Bots can currently send animation files of up to 50 MB in size, this limit
|
||||
/// may be changed in the future.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#sendanimation).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendAnimation {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub animation: InputFile,
|
||||
pub duration: Option<u32>,
|
||||
pub width: Option<u32>,
|
||||
pub height: Option<u32>,
|
||||
pub thumb: Option<InputFile>,
|
||||
pub caption: Option<String>,
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendAnimation {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_multipart(self.bot.client(), self.bot.token(), "sendAnimation", self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendAnimation {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, animation: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
animation,
|
||||
duration: None,
|
||||
width: None,
|
||||
height: None,
|
||||
thumb: None,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: 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, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
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 {
|
||||
self.duration = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
/// Animation width.
|
||||
pub fn width(mut self, value: u32) -> Self {
|
||||
self.width = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
/// Animation height.
|
||||
pub fn height(mut self, value: u32) -> Self {
|
||||
self.height = Some(value);
|
||||
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
|
||||
/// thumbnail‘s width and height should not exceed 320. Ignored if the
|
||||
/// file is not uploaded using [`InputFile::File`]. Thumbnails can’t 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 {
|
||||
self.thumb = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
/// Animation caption, `0`-`1024` characters.
|
||||
pub fn caption<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(value.into());
|
||||
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 {
|
||||
self.parse_mode = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sends the message silently. Users will receive a notification with no
|
||||
/// sound.
|
||||
pub fn disable_notification(mut self, value: bool) -> Self {
|
||||
self.disable_notification = Some(value);
|
||||
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 {
|
||||
self.reply_to_message_id = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
/// Additional interface options.
|
||||
pub fn reply_markup<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ReplyMarkup>,
|
||||
{
|
||||
self.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,183 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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. Bots can currently send audio
|
||||
/// files of up to 50 MB in size, this limit may be changed in the future.
|
||||
///
|
||||
/// 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
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendAudio {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub audio: InputFile,
|
||||
pub caption: Option<String>,
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
pub duration: Option<i32>,
|
||||
pub performer: Option<String>,
|
||||
pub title: Option<String>,
|
||||
pub thumb: Option<InputFile>,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendAudio {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_multipart(self.bot.client(), self.bot.token(), "sendAudio", self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendAudio {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, audio: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
audio,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
duration: None,
|
||||
performer: None,
|
||||
title: None,
|
||||
thumb: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
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 {
|
||||
self.audio = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// Audio caption, 0-1024 characters.
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(val.into());
|
||||
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 {
|
||||
self.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Duration of the audio in seconds.
|
||||
pub fn duration(mut self, val: i32) -> Self {
|
||||
self.duration = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Performer.
|
||||
pub fn performer<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.performer = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Track name.
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.title = Some(val.into());
|
||||
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
|
||||
/// thumbnail‘s width and height should not exceed 320. Ignored if the
|
||||
/// file is not uploaded using `multipart/form-data`. Thumbnails can’t
|
||||
/// 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 {
|
||||
self.thumb = Some(val);
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the message is a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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 arrives from your
|
||||
/// bot, Telegram clients clear its typing status).
|
||||
///
|
||||
/// ## Note
|
||||
/// Example: The [ImageBot] needs some time to process a request and upload the
|
||||
/// 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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendChatAction {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub action: SendChatActionKind,
|
||||
}
|
||||
|
||||
/// A type of action used in [`SendChatAction`].
|
||||
///
|
||||
/// [`SendChatAction`]: crate::requests::SendChatAction
|
||||
#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum SendChatActionKind {
|
||||
/// For [text messages](crate::Bot::send_message).
|
||||
Typing,
|
||||
|
||||
/// For [photos](crate::Bot::send_photo).
|
||||
UploadPhoto,
|
||||
|
||||
/// For [videos](crate::Bot::send_video).
|
||||
RecordVideo,
|
||||
|
||||
/// For [videos](crate::Bot::send_video).
|
||||
UploadVideo,
|
||||
|
||||
/// For [audio files](crate::Bot::send_audio).
|
||||
RecordAudio,
|
||||
|
||||
/// For [audio files](crate::Bot::send_audio).
|
||||
UploadAudio,
|
||||
|
||||
/// For [general files](crate::Bot::send_document).
|
||||
UploadDocument,
|
||||
|
||||
/// For [location data](crate::Bot::send_location).
|
||||
FindLocation,
|
||||
|
||||
/// For [video notes](crate::Bot::send_video_note).
|
||||
RecordVideoNote,
|
||||
|
||||
/// For [video notes](crate::Bot::send_video_note).
|
||||
UploadVideoNote,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendChatAction {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "sendChatAction", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendChatAction {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, action: SendChatActionKind) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self { bot, chat_id: chat_id.into(), 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Type of action to broadcast.
|
||||
pub fn action(mut self, val: SendChatActionKind) -> Self {
|
||||
self.action = val;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, Message, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send phone contacts.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#sendcontact).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendContact {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub phone_number: String,
|
||||
pub first_name: String,
|
||||
pub last_name: Option<String>,
|
||||
pub vcard: Option<String>,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendContact {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "sendContact", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendContact {
|
||||
pub(crate) fn new<C, P, F>(bot: Bot, chat_id: C, phone_number: P, first_name: F) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
P: Into<String>,
|
||||
F: Into<String>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let phone_number = phone_number.into();
|
||||
let first_name = first_name.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
phone_number,
|
||||
first_name,
|
||||
last_name: None,
|
||||
vcard: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Contact's phone number.
|
||||
pub fn phone_number<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.phone_number = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Contact's first name.
|
||||
pub fn first_name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.first_name = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Contact's last name.
|
||||
pub fn last_name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.last_name = Some(val.into());
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.vcard = Some(val.into());
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the message is a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Additional interface options.
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, DiceEmoji, Message, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send an animated emoji that will display a random value.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#senddice).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendDice {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
#[serde(flatten)]
|
||||
pub emoji: Option<DiceEmoji>,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendDice {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "sendDice", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendDice {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
emoji: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: 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, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Emoji on which the dice throw animation is based.
|
||||
pub fn emoji(mut self, val: DiceEmoji) -> Self {
|
||||
self.emoji = Some(val);
|
||||
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 {
|
||||
self.disable_notification = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the message is a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, value: i32) -> Self {
|
||||
self.reply_to_message_id = Some(value);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,140 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send general files.
|
||||
///
|
||||
/// Bots can currently send files of any type of up to 50 MB in size, this limit
|
||||
/// may be changed in the future.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#senddocument).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendDocument {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub document: InputFile,
|
||||
pub thumb: Option<InputFile>,
|
||||
pub caption: Option<String>,
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendDocument {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_multipart(self.bot.client(), self.bot.token(), "sendDocument", self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendDocument {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, document: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
document,
|
||||
thumb: None,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
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 {
|
||||
self.document = val;
|
||||
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
|
||||
/// thumbnail‘s width and height should not exceed 320. Ignored if the
|
||||
/// file is not uploaded using `multipart/form-data`. Thumbnails can’t
|
||||
/// 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 {
|
||||
self.thumb = Some(val);
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(val.into());
|
||||
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 {
|
||||
self.parse_mode = Some(val);
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the message is a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Additional interface options.
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{InlineKeyboardMarkup, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send a game.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#sendgame).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendGame {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: i32,
|
||||
pub game_short_name: String,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendGame {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "sendGame", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendGame {
|
||||
pub(crate) fn new<G>(bot: Bot, chat_id: i32, game_short_name: G) -> Self
|
||||
where
|
||||
G: Into<String>,
|
||||
{
|
||||
let game_short_name = game_short_name.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
game_short_name,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Unique identifier for the target chat.
|
||||
pub fn chat_id(mut self, val: i32) -> Self {
|
||||
self.chat_id = val;
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.game_short_name = val.into();
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the message is a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,299 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{InlineKeyboardMarkup, LabeledPrice, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send invoices.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#sendinvoice).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendInvoice {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: i32,
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub payload: String,
|
||||
pub provider_token: String,
|
||||
pub start_parameter: String,
|
||||
pub currency: String,
|
||||
pub prices: Vec<LabeledPrice>,
|
||||
pub provider_data: Option<String>,
|
||||
pub photo_url: Option<String>,
|
||||
pub photo_size: Option<i32>,
|
||||
pub photo_width: Option<i32>,
|
||||
pub photo_height: Option<i32>,
|
||||
pub need_name: Option<bool>,
|
||||
pub need_phone_number: Option<bool>,
|
||||
pub need_email: Option<bool>,
|
||||
pub need_shipping_address: Option<bool>,
|
||||
pub send_phone_number_to_provider: Option<bool>,
|
||||
pub send_email_to_provider: Option<bool>,
|
||||
pub is_flexible: Option<bool>,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendInvoice {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "sendInvoice", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendInvoice {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn new<T, D, Pl, Pt, S, C, Pr>(
|
||||
bot: Bot,
|
||||
chat_id: i32,
|
||||
title: T,
|
||||
description: D,
|
||||
payload: Pl,
|
||||
provider_token: Pt,
|
||||
start_parameter: S,
|
||||
currency: C,
|
||||
prices: Pr,
|
||||
) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
D: Into<String>,
|
||||
Pl: Into<String>,
|
||||
Pt: Into<String>,
|
||||
S: Into<String>,
|
||||
C: Into<String>,
|
||||
Pr: Into<Vec<LabeledPrice>>,
|
||||
{
|
||||
let title = title.into();
|
||||
let description = description.into();
|
||||
let payload = payload.into();
|
||||
let provider_token = provider_token.into();
|
||||
let start_parameter = start_parameter.into();
|
||||
let currency = currency.into();
|
||||
let prices = prices.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
title,
|
||||
description,
|
||||
payload,
|
||||
provider_token,
|
||||
start_parameter,
|
||||
currency,
|
||||
prices,
|
||||
provider_data: None,
|
||||
photo_url: None,
|
||||
photo_size: None,
|
||||
photo_width: None,
|
||||
photo_height: None,
|
||||
need_name: None,
|
||||
need_phone_number: None,
|
||||
need_email: None,
|
||||
need_shipping_address: None,
|
||||
send_phone_number_to_provider: None,
|
||||
send_email_to_provider: None,
|
||||
is_flexible: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Unique identifier for the target private chat.
|
||||
pub fn chat_id(mut self, val: i32) -> Self {
|
||||
self.chat_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// Product name, 1-32 characters.
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.title = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Product description, 1-255 characters.
|
||||
pub fn description<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.description = val.into();
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Payments provider token, obtained via [@Botfather].
|
||||
///
|
||||
/// [@Botfather]: https://t.me/botfather
|
||||
pub fn provider_token<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.provider_token = val.into();
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.start_parameter = val.into();
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.currency = val.into();
|
||||
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
|
||||
where
|
||||
T: Into<Vec<LabeledPrice>>,
|
||||
{
|
||||
self.prices = val.into();
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.provider_data = Some(val.into());
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.photo_url = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Photo size.
|
||||
pub fn photo_size(mut self, val: i32) -> Self {
|
||||
self.photo_size = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Photo width.
|
||||
pub fn photo_width(mut self, val: i32) -> Self {
|
||||
self.photo_width = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Photo height.
|
||||
pub fn photo_height(mut self, val: i32) -> Self {
|
||||
self.photo_height = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Pass `true`, if you require the user's full name to complete the order.
|
||||
pub fn need_name(mut self, val: bool) -> Self {
|
||||
self.need_name = Some(val);
|
||||
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 {
|
||||
self.need_phone_number = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Pass `true`, if you require the user's email address to complete the
|
||||
/// order.
|
||||
pub fn need_email(mut self, val: bool) -> Self {
|
||||
self.need_email = Some(val);
|
||||
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 {
|
||||
self.need_shipping_address = Some(val);
|
||||
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 {
|
||||
self.send_phone_number_to_provider = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Pass `true`, if user's email address should be sent to provider.
|
||||
pub fn send_email_to_provider(mut self, val: bool) -> Self {
|
||||
self.send_email_to_provider = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Pass `true`, if the final price depends on the shipping method.
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
pub fn is_flexible(mut self, val: bool) -> Self {
|
||||
self.is_flexible = Some(val);
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the message is a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, Message, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send point on the map.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#sendlocation).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendLocation {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub latitude: f32,
|
||||
pub longitude: f32,
|
||||
pub live_period: Option<i64>,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendLocation {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "sendLocation", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendLocation {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, latitude: f32, longitude: f32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
latitude,
|
||||
longitude,
|
||||
live_period: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Latitude of the location.
|
||||
pub fn latitude(mut self, val: f32) -> Self {
|
||||
self.latitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// Longitude of the location.
|
||||
pub fn longitude(mut self, val: f32) -> Self {
|
||||
self.longitude = val;
|
||||
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 {
|
||||
self.live_period = Some(val);
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the message is a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InputMedia, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send a group of photos or videos as an album.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#sendmediagroup).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendMediaGroup {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub media: Vec<InputMedia>, // TODO: InputMediaPhoto and InputMediaVideo
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendMediaGroup {
|
||||
type Output = Vec<Message>;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Vec<Message>> {
|
||||
net::request_multipart(self.bot.client(), self.bot.token(), "sendMediaGroup", self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendMediaGroup {
|
||||
pub(crate) fn new<C, M>(bot: Bot, chat_id: C, media: M) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
M: Into<Vec<InputMedia>>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let media = media.into();
|
||||
Self { bot, chat_id, media, disable_notification: None, reply_to_message_id: 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// A JSON-serialized array describing photos and videos to be sent, must
|
||||
/// include 2–10 items.
|
||||
pub fn media<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<Vec<InputMedia>>,
|
||||
{
|
||||
self.media = val.into();
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the messages are a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, Message, ParseMode, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send text messages.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#sendmessage).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendMessage {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub text: String,
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
pub disable_web_page_preview: Option<bool>,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendMessage {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "sendMessage", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendMessage {
|
||||
pub(crate) fn new<C, T>(bot: Bot, chat_id: C, text: T) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
T: Into<String>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
text: text.into(),
|
||||
parse_mode: None,
|
||||
disable_web_page_preview: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: 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, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Text of the message to be sent.
|
||||
pub fn text<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.text = value.into();
|
||||
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 {
|
||||
self.parse_mode = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
/// Disables link previews for links in this message.
|
||||
pub fn disable_web_page_preview(mut self, value: bool) -> Self {
|
||||
self.disable_web_page_preview = Some(value);
|
||||
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 {
|
||||
self.disable_notification = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the message is a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, value: i32) -> Self {
|
||||
self.reply_to_message_id = Some(value);
|
||||
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
|
||||
where
|
||||
T: Into<ReplyMarkup>,
|
||||
{
|
||||
self.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send photos.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#sendphoto).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendPhoto {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub photo: InputFile,
|
||||
pub caption: Option<String>,
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendPhoto {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_multipart(self.bot.client(), self.bot.token(), "sendPhoto", self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendPhoto {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, photo: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
photo,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
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 {
|
||||
self.photo = val;
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(val.into());
|
||||
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 {
|
||||
self.parse_mode = Some(val);
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the message is a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,217 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, Message, ParseMode, PollType, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send a native poll.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#sendpoll).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendPoll {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub question: String,
|
||||
pub options: Vec<String>,
|
||||
pub is_anonymous: Option<bool>,
|
||||
pub poll_type: Option<PollType>,
|
||||
pub allows_multiple_answers: Option<bool>,
|
||||
pub correct_option_id: Option<i32>,
|
||||
pub explanation: Option<String>,
|
||||
pub explanation_parse_mode: Option<ParseMode>,
|
||||
pub open_period: Option<i32>,
|
||||
pub close_date: Option<i32>,
|
||||
pub is_closed: Option<bool>,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendPoll {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "sendPoll", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendPoll {
|
||||
pub(crate) fn new<C, Q, O>(bot: Bot, chat_id: C, question: Q, options: O) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
Q: Into<String>,
|
||||
O: Into<Vec<String>>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let question = question.into();
|
||||
let options = options.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
question,
|
||||
options,
|
||||
is_anonymous: None,
|
||||
poll_type: None,
|
||||
allows_multiple_answers: None,
|
||||
correct_option_id: None,
|
||||
explanation: None,
|
||||
explanation_parse_mode: None,
|
||||
is_closed: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
close_date: None,
|
||||
open_period: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Poll question, 1-255 characters.
|
||||
pub fn question<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.question = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// List of answer options, 2-10 strings 1-100 characters each.
|
||||
pub fn options<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<Vec<String>>,
|
||||
{
|
||||
self.options = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// `true`, if the poll needs to be anonymous, defaults to `true`.
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
pub fn is_anonymous<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.is_anonymous = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Poll type, `quiz` or `regular`, defaults to `regular`.
|
||||
pub fn poll_type(mut self, val: PollType) -> Self {
|
||||
self.poll_type = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// `true`, if the poll allows multiple answers, ignored for polls in quiz
|
||||
/// mode.
|
||||
///
|
||||
/// Defaults to `false`.
|
||||
pub fn allows_multiple_answers<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.allows_multiple_answers = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// 0-based identifier of the correct answer option, required for polls in
|
||||
/// quiz mode.
|
||||
pub fn correct_option_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.correct_option_id = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Text that is shown when a user chooses an incorrect answer or taps on
|
||||
/// the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line
|
||||
/// feeds after entities parsing.
|
||||
pub fn explanation<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.explanation = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Mode for parsing entities in the explanation. See [formatting options]
|
||||
/// for more details.
|
||||
///
|
||||
/// [formatting options]: https://core.telegram.org/bots/api#formatting-options
|
||||
pub fn explanation_parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.explanation_parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Amount of time in seconds the poll will be active after creation, 5-600.
|
||||
/// Can't be used together with `close_date`.
|
||||
pub fn open_period(mut self, val: i32) -> Self {
|
||||
self.open_period = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Point in time (Unix timestamp) when the poll will be automatically
|
||||
/// closed. Must be at least 5 and no more than 600 seconds in the future.
|
||||
/// Can't be used together with `open_period`.
|
||||
pub fn close_date(mut self, val: i32) -> Self {
|
||||
self.close_date = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Pass `true`, if the poll needs to be immediately closed.
|
||||
///
|
||||
/// This can be useful for poll preview.
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
pub fn is_closed<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.is_closed = Some(val.into());
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the message is a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send static .WEBP or [animated] .TGS stickers.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#sendsticker).
|
||||
///
|
||||
/// [animated]: https://telegram.org/blog/animated-stickers
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendSticker {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub sticker: InputFile,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendSticker {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_multipart(self.bot.client(), self.bot.token(), "sendSticker", self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendSticker {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, sticker: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
sticker,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
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 {
|
||||
self.sticker = val;
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the message is a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,159 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, Message, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send information about a venue.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#sendvenue).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendVenue {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub latitude: f32,
|
||||
pub longitude: f32,
|
||||
pub title: String,
|
||||
pub address: String,
|
||||
pub foursquare_id: Option<String>,
|
||||
pub foursquare_type: Option<String>,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendVenue {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "sendVenue", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendVenue {
|
||||
pub(crate) fn new<C, T, A>(
|
||||
bot: Bot,
|
||||
chat_id: C,
|
||||
latitude: f32,
|
||||
longitude: f32,
|
||||
title: T,
|
||||
address: A,
|
||||
) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
T: Into<String>,
|
||||
A: Into<String>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let title = title.into();
|
||||
let address = address.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
latitude,
|
||||
longitude,
|
||||
title,
|
||||
address,
|
||||
foursquare_id: None,
|
||||
foursquare_type: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Latitude of the venue.
|
||||
pub fn latitude(mut self, val: f32) -> Self {
|
||||
self.latitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// Longitude of the venue.
|
||||
pub fn longitude(mut self, val: f32) -> Self {
|
||||
self.longitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// Name of the venue.
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.title = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Address of the venue.
|
||||
pub fn address<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.address = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Foursquare identifier of the venue.
|
||||
pub fn foursquare_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.foursquare_id = Some(val.into());
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.foursquare_type = Some(val.into());
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the message is a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,182 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send video files, Telegram clients support mp4 videos
|
||||
/// (other formats may be sent as Document).
|
||||
///
|
||||
/// Bots can currently send video files of up to 50 MB in size, this
|
||||
/// limit may be changed in the future.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#sendvideo).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendVideo {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub video: InputFile,
|
||||
pub duration: Option<i32>,
|
||||
pub width: Option<i32>,
|
||||
pub height: Option<i32>,
|
||||
pub thumb: Option<InputFile>,
|
||||
pub caption: Option<String>,
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
pub supports_streaming: Option<bool>,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendVideo {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_multipart(self.bot.client(), self.bot.token(), "sendVideo", self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendVideo {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, video: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
video,
|
||||
duration: None,
|
||||
width: None,
|
||||
height: None,
|
||||
thumb: None,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
supports_streaming: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
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 {
|
||||
self.video = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// Duration of sent video in seconds.
|
||||
pub fn duration(mut self, val: i32) -> Self {
|
||||
self.duration = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Video width.
|
||||
pub fn width(mut self, val: i32) -> Self {
|
||||
self.width = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Video height.
|
||||
pub fn height(mut self, val: i32) -> Self {
|
||||
self.height = Some(val);
|
||||
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
|
||||
/// thumbnail‘s width and height should not exceed 320. Ignored if the
|
||||
/// file is not uploaded using `multipart/form-data`. Thumbnails can’t 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 {
|
||||
self.thumb = Some(val);
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(val.into());
|
||||
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 {
|
||||
self.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Pass `true`, if the uploaded video is suitable for streaming.
|
||||
pub fn supports_streaming(mut self, val: bool) -> Self {
|
||||
self.supports_streaming = Some(val);
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the message is a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#sendvideonote).
|
||||
///
|
||||
/// [v.4.0]: https://telegram.org/blog/video-messages-and-telescope
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendVideoNote {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub video_note: InputFile,
|
||||
pub duration: Option<i32>,
|
||||
pub length: Option<i32>,
|
||||
pub thumb: Option<InputFile>,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendVideoNote {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_multipart(self.bot.client(), self.bot.token(), "sendVideoNote", self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendVideoNote {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, video_note: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
video_note,
|
||||
duration: None,
|
||||
length: None,
|
||||
thumb: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
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 {
|
||||
self.video_note = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// Duration of sent video in seconds.
|
||||
pub fn duration(mut self, val: i32) -> Self {
|
||||
self.duration = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Video width and height, i.e. diameter of the video message.
|
||||
pub fn length(mut self, val: i32) -> Self {
|
||||
self.length = Some(val);
|
||||
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
|
||||
/// thumbnail‘s width and height should not exceed 320. Ignored if the
|
||||
/// file is not uploaded using `multipart/form-data`. Thumbnails can’t
|
||||
/// 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 {
|
||||
self.thumb = Some(val);
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the message is a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,144 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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 in an .ogg file encoded with OPUS
|
||||
/// (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.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#sendvoice).
|
||||
///
|
||||
/// [`Audio`]: crate::types::Audio
|
||||
/// [`Document`]: crate::types::Document
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendVoice {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub voice: InputFile,
|
||||
pub caption: Option<String>,
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
pub duration: Option<i32>,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SendVoice {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_multipart(self.bot.client(), self.bot.token(), "sendVoice", self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendVoice {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, voice: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
voice,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
duration: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
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 {
|
||||
self.voice = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// Voice message caption, 0-1024 characters.
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(val.into());
|
||||
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 {
|
||||
self.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// Duration of the voice message in seconds.
|
||||
pub fn duration(mut self, val: i32) -> Self {
|
||||
self.duration = Some(val);
|
||||
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 {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
/// If the message is a reply, ID of the original message.
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to set a custom title for an administrator in a supergroup
|
||||
/// promoted by the bot.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#setchatadministratorcustomtitle).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetChatAdministratorCustomTitle {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub user_id: i32,
|
||||
pub custom_title: String,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SetChatAdministratorCustomTitle {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"setChatAdministratorCustomTitle",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatAdministratorCustomTitle {
|
||||
pub(crate) fn new<C, CT>(bot: Bot, chat_id: C, user_id: i32, custom_title: CT) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
CT: Into<String>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let custom_title = custom_title.into();
|
||||
Self { bot, chat_id, user_id, 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Unique identifier of the target user.
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// New custom title for the administrator; 0-16 characters, emoji are not
|
||||
/// allowed.
|
||||
pub fn custom_title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.custom_title = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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 must have
|
||||
/// the appropriate admin rights.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#setchatdescription).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetChatDescription {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SetChatDescription {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "setChatDescription", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatDescription {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id, 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// New chat description, 0-255 characters.
|
||||
pub fn description<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.description = Some(val.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, ChatPermissions, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to set default chat permissions for all members.
|
||||
///
|
||||
/// 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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetChatPermissions {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub permissions: ChatPermissions,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SetChatPermissions {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "sendChatPermissions", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatPermissions {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, permissions: ChatPermissions) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id, 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// New default chat permissions.
|
||||
pub fn permissions(mut self, val: ChatPermissions) -> Self {
|
||||
self.permissions = val;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InputFile, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to set a new profile photo for the chat.
|
||||
///
|
||||
/// Photos 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#setchatphoto).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetChatPhoto {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub photo: InputFile,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SetChatPhoto {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "setChatPhoto", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatPhoto {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, photo: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id, 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// New chat photo, uploaded using `multipart/form-data`.
|
||||
pub fn photo(mut self, val: InputFile) -> Self {
|
||||
self.photo = val;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to set a new group sticker set for a supergroup.
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#setchatstickerset).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetChatStickerSet {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub sticker_set_name: String,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SetChatStickerSet {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "setChatStickerSet", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatStickerSet {
|
||||
pub(crate) fn new<C, S>(bot: Bot, chat_id: C, sticker_set_name: S) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
S: Into<String>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let sticker_set_name = sticker_set_name.into();
|
||||
Self { bot, chat_id, 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
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
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.sticker_set_name = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to change the title of a chat.
|
||||
///
|
||||
/// 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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetChatTitle {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub title: String,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SetChatTitle {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "setChatTitle", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatTitle {
|
||||
pub(crate) fn new<C, T>(bot: Bot, chat_id: C, title: T) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
T: Into<String>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let title = title.into();
|
||||
Self { bot, chat_id, 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// New chat title, 1-255 characters.
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.title = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{Message, TargetMessage},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to set the score of the specified user in a game.
|
||||
///
|
||||
/// On 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 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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetGameScore {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
#[serde(flatten)]
|
||||
pub target: TargetMessage,
|
||||
pub user_id: i32,
|
||||
pub score: i32,
|
||||
pub force: Option<bool>,
|
||||
pub disable_edit_message: Option<bool>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SetGameScore {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "setGameScore", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetGameScore {
|
||||
pub(crate) fn new<T>(bot: Bot, target: T, user_id: i32, score: i32) -> Self
|
||||
where
|
||||
T: Into<TargetMessage>,
|
||||
{
|
||||
let target = target.into();
|
||||
Self { bot, target, user_id, score, force: None, disable_edit_message: None }
|
||||
}
|
||||
|
||||
/// Target message, either chat id and message id or inline message id.
|
||||
pub fn target<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<TargetMessage>,
|
||||
{
|
||||
self.target = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// User identifier.
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// New score, must be non-negative.
|
||||
pub fn score(mut self, val: i32) -> Self {
|
||||
self.score = val;
|
||||
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 {
|
||||
self.force = Some(val);
|
||||
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 {
|
||||
self.disable_edit_message = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{BotCommand, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to change the list of the bot's commands.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#setmycommands).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetMyCommands {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub commands: Vec<BotCommand>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SetMyCommands {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Self::Output> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "setMyCommands", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetMyCommands {
|
||||
pub(crate) fn new<C>(bot: Bot, commands: C) -> Self
|
||||
where
|
||||
C: Into<Vec<BotCommand>>,
|
||||
{
|
||||
Self { bot, commands: commands.into() }
|
||||
}
|
||||
|
||||
/// A JSON-serialized list of bot commands to be set as the list of the
|
||||
/// bot's commands.
|
||||
///
|
||||
/// At most 100 commands can be specified.
|
||||
pub fn commands<C>(mut self, commands: C) -> Self
|
||||
where
|
||||
C: Into<Vec<BotCommand>>,
|
||||
{
|
||||
self.commands = commands.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::True,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to move a sticker in a set created by the bot to a specific
|
||||
/// position.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#setstickerpositioninset).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetStickerPositionInSet {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub sticker: String,
|
||||
pub position: i32,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SetStickerPositionInSet {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "setStickerPositionInSet", &self)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetStickerPositionInSet {
|
||||
pub(crate) fn new<S>(bot: Bot, sticker: S, position: i32) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
let sticker = sticker.into();
|
||||
Self { bot, sticker, position }
|
||||
}
|
||||
|
||||
/// File identifier of the sticker.
|
||||
pub fn sticker<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.sticker = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// New sticker position in the set, zero-based.
|
||||
pub fn position(mut self, val: i32) -> Self {
|
||||
self.position = val;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{InputFile, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to set the thumbnail of a sticker set. Animated thumbnails
|
||||
/// can be set for animated sticker sets only.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#setstickersetthumb).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetStickerSetThumb {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub name: String,
|
||||
pub user_id: i32,
|
||||
pub thumb: Option<InputFile>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SetStickerSetThumb {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Self::Output> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "setStickerSetThumb", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetStickerSetThumb {
|
||||
pub(crate) fn new<S>(bot: Bot, name: S, user_id: i32) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
Self { bot, name: name.into(), user_id, thumb: None }
|
||||
}
|
||||
|
||||
/// Sticker set name.
|
||||
pub fn name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.name = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// User identifier of the sticker set owner.
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
/// A PNG image with the thumbnail, must be up to 128 kilobytes in size and
|
||||
/// have width and height exactly 100px, or a TGS animation with the
|
||||
/// thumbnail up to 32 kilobytes in size; see https://core.telegram.org/animated_stickers#technical-requirements
|
||||
/// for animated sticker technical requirements.
|
||||
///
|
||||
/// Pass [`InputFile::FileId`] as a String to send a file that already
|
||||
/// exists on the Telegram servers, pass [`InputFile::Url`] for Telegram
|
||||
/// to get a file from the Internet, or upload a new one using
|
||||
/// multipart/form-data. More info on Sending Files ». Animated sticker
|
||||
/// set thumbnail can't be uploaded via HTTP URL.
|
||||
///
|
||||
/// [`InputFile::FileId`]: crate::types::InputFile::FileId
|
||||
/// [`InputFile::Url]: crate::types::InputFile::Url
|
||||
pub fn thumb(mut self, val: InputFile) -> Self {
|
||||
self.thumb = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{AllowedUpdate, InputFile, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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
|
||||
/// HTTPS POST request to the specified url, containing a JSON-serialized
|
||||
/// [`Update`]. In case of an unsuccessful request, we will give up after a
|
||||
/// reasonable amount of attempts.
|
||||
///
|
||||
/// If you'd like to 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 bot‘s
|
||||
/// token, you can be pretty sure it’s us.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#setwebhook).
|
||||
///
|
||||
/// [`Update`]: crate::types::Update
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetWebhook {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub url: String,
|
||||
pub certificate: Option<InputFile>,
|
||||
pub max_connections: Option<i32>,
|
||||
pub allowed_updates: Option<Vec<AllowedUpdate>>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for SetWebhook {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "setWebhook", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetWebhook {
|
||||
pub(crate) fn new<U>(bot: Bot, url: U) -> Self
|
||||
where
|
||||
U: Into<String>,
|
||||
{
|
||||
let url = url.into();
|
||||
Self { bot, url, certificate: None, max_connections: None, allowed_updates: None }
|
||||
}
|
||||
|
||||
/// HTTPS url to send updates to.
|
||||
///
|
||||
/// Use an empty string to remove webhook integration.
|
||||
pub fn url<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.url = val.into();
|
||||
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 {
|
||||
self.certificate = Some(val);
|
||||
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 bot‘s server,
|
||||
/// and higher values to increase your bot’s throughput.
|
||||
pub fn max_connections(mut self, val: i32) -> Self {
|
||||
self.max_connections = Some(val);
|
||||
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
|
||||
where
|
||||
T: Into<Vec<AllowedUpdate>>,
|
||||
{
|
||||
self.allowed_updates = Some(val.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{InlineKeyboardMarkup, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to stop updating a live location message (sent via the bot)
|
||||
/// before `live_period` expires.
|
||||
///
|
||||
/// On success, [`True`] is returned.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#stopmessagelivelocation).
|
||||
///
|
||||
/// [`True`]: crate::types::True
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct StopInlineMessageLiveLocation {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub inline_message_id: String,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for StopInlineMessageLiveLocation {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "stopMessageLiveLocation", &self)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl StopInlineMessageLiveLocation {
|
||||
pub(crate) fn new<I>(bot: Bot, inline_message_id: I) -> Self
|
||||
where
|
||||
I: Into<String>,
|
||||
{
|
||||
let inline_message_id = inline_message_id.into();
|
||||
Self { bot, inline_message_id, reply_markup: None }
|
||||
}
|
||||
|
||||
/// Identifier of the inline message.
|
||||
pub fn inline_message_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.inline_message_id = val.into();
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InlineKeyboardMarkup, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to stop updating a live location message before
|
||||
/// `live_period` expires.
|
||||
///
|
||||
/// On success, the sent [`Message`] is returned.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#stopmessagelivelocation).
|
||||
///
|
||||
/// [`Message`]: crate::types::Message
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct StopMessageLiveLocation {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub message_id: i32,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for StopMessageLiveLocation {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "stopMessageLiveLocation", &self)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl StopMessageLiveLocation {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, message_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id, message_id, 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Identifier of the message to edit
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.message_id = val;
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, InlineKeyboardMarkup, Poll},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to stop a poll which was sent by the bot.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#stoppoll).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct StopPoll {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub message_id: i32,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for StopPoll {
|
||||
type Output = Poll;
|
||||
|
||||
/// On success, the stopped [`Poll`] with the final results is returned.
|
||||
///
|
||||
/// [`Poll`]: crate::types::Poll
|
||||
async fn send(&self) -> ResponseResult<Poll> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "stopPoll", &self).await
|
||||
}
|
||||
}
|
||||
impl StopPoll {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, message_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id, message_id, 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Identifier of the original message with the poll.
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.message_id = val;
|
||||
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 {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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 will be able to join via link, etc. The bot must be an administrator for
|
||||
/// this to work.
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#unbanchatmember).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct UnbanChatMember {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
pub user_id: i32,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for UnbanChatMember {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "unbanChatMember", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl UnbanChatMember {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C, user_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Unique identifier of the target user.
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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 `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#unpinchatmessage).
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct UnpinChatMessage {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for UnpinChatMessage {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "unpinChatMessage", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl UnpinChatMessage {
|
||||
pub(crate) fn new<C>(bot: Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { 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
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
net,
|
||||
requests::{RequestOld, ResponseResult},
|
||||
types::{File, InputFile},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to upload a .png file with a sticker for later use in
|
||||
/// [`Bot::create_new_sticker_set`] and [`Bot::add_sticker_to_set`] methods (can
|
||||
/// 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]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct UploadStickerFile {
|
||||
#[serde(skip_serializing)]
|
||||
bot: Bot,
|
||||
pub user_id: i32,
|
||||
pub png_sticker: InputFile,
|
||||
}
|
||||
#[async_trait::async_trait]
|
||||
impl RequestOld for UploadStickerFile {
|
||||
type Output = File;
|
||||
|
||||
async fn send(&self) -> ResponseResult<File> {
|
||||
net::request_json(self.bot.client(), self.bot.token(), "uploadStickerFile", &self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl UploadStickerFile {
|
||||
pub(crate) fn new(bot: Bot, user_id: i32, png_sticker: InputFile) -> Self {
|
||||
Self { bot, user_id, png_sticker }
|
||||
}
|
||||
|
||||
/// User identifier of sticker file owner.
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
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 {
|
||||
self.png_sticker = val;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,23 +1,9 @@
|
|||
//! Telegram API requests.
|
||||
|
||||
mod has_payload;
|
||||
mod payload;
|
||||
mod request;
|
||||
|
||||
pub use self::{has_payload::HasPayload, payload::Payload, request::Request};
|
||||
|
||||
mod all;
|
||||
mod json;
|
||||
mod multipart;
|
||||
mod requester;
|
||||
mod requester_ext;
|
||||
mod utils;
|
||||
|
||||
pub use all::*;
|
||||
pub use json::JsonRequest;
|
||||
pub use multipart::MultipartRequest;
|
||||
pub use requester::Requester;
|
||||
pub use requester_ext::RequesterExt;
|
||||
pub use self::{
|
||||
has_payload::HasPayload, json::JsonRequest, multipart::MultipartRequest, payload::Payload,
|
||||
request::Request, requester::Requester, requester_ext::RequesterExt,
|
||||
};
|
||||
|
||||
/// A type that is returned after making a request to Telegram.
|
||||
pub type ResponseResult<T> = Result<T, crate::RequestError>;
|
||||
|
@ -26,12 +12,11 @@ pub type ResponseResult<T> = Result<T, crate::RequestError>;
|
|||
/// `<<T as HasPayload>::Payload as Payload>::Output`.
|
||||
pub type Output<T> = <<T as HasPayload>::Payload as Payload>::Output;
|
||||
|
||||
/// Designates an API request.
|
||||
#[async_trait::async_trait]
|
||||
pub trait RequestOld {
|
||||
/// A data structure returned if success.
|
||||
type Output;
|
||||
|
||||
/// Asynchronously sends this request to Telegram and returns the result.
|
||||
async fn send(&self) -> ResponseResult<Self::Output>;
|
||||
}
|
||||
mod has_payload;
|
||||
mod json;
|
||||
mod multipart;
|
||||
mod payload;
|
||||
mod request;
|
||||
mod requester;
|
||||
mod requester_ext;
|
||||
mod utils;
|
||||
|
|
|
@ -18,9 +18,9 @@ pub struct Chat {
|
|||
#[serde(flatten)]
|
||||
pub kind: ChatKind,
|
||||
|
||||
/// A chat photo. Returned only in [`Bot::get_chat`].
|
||||
/// A chat photo. Returned only in [`GetChat`].
|
||||
///
|
||||
/// [`Bot::get_chat`]: crate::Bot::get_chat
|
||||
/// [`GetChat`]: crate::payloads::GetChat
|
||||
pub photo: Option<ChatPhoto>,
|
||||
}
|
||||
|
||||
|
@ -63,27 +63,27 @@ pub struct ChatPublic {
|
|||
pub kind: PublicChatKind,
|
||||
|
||||
/// A description, for groups, supergroups and channel chats. Returned
|
||||
/// only in [`Bot::get_chat`].
|
||||
/// only in [`GetChat`].
|
||||
///
|
||||
/// [`Bot::get_chat`]: crate::Bot::get_chat
|
||||
/// [`GetChat`]: crate::payloads::GetChat
|
||||
pub description: Option<String>,
|
||||
|
||||
/// A chat invite link, for groups, supergroups and channel chats. Each
|
||||
/// administrator in a chat generates their own invite links, so the
|
||||
/// bot must first generate the link using
|
||||
/// [`Bot::export_chat_invite_link`]. Returned only in
|
||||
/// [`Bot::get_chat`].
|
||||
/// [`ExportChatInviteLink`]. Returned only in
|
||||
/// [`GetChat`].
|
||||
///
|
||||
/// [`Bot::export_chat_invite_link`]:
|
||||
/// crate::Bot::export_chat_invite_link
|
||||
/// [`ExportChatInviteLink`]:
|
||||
/// crate::payloads::ExportChatInviteLink
|
||||
///
|
||||
/// [`Bot::get_chat`]: crate::Bot::get_chat
|
||||
/// [`GetChat`]: crate::payloads::GetChat
|
||||
pub invite_link: Option<String>,
|
||||
|
||||
/// Pinned message, for groups, supergroups and channels. Returned only
|
||||
/// in [`Bot::get_chat`].
|
||||
/// in [`GetChat`].
|
||||
///
|
||||
/// [`Bot::get_chat`]: crate::Bot::get_chat
|
||||
/// [`GetChat`]: crate::payloads::GetChat
|
||||
pub pinned_message: Option<Box<Message>>,
|
||||
}
|
||||
|
||||
|
@ -199,9 +199,9 @@ impl PublicChatChannel {
|
|||
#[derive(Clone, Default, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PublicChatGroup {
|
||||
/// A default chat member permissions, for groups and supergroups. Returned
|
||||
/// only from [`Bot::get_chat`].
|
||||
/// only from [`GetChat`].
|
||||
///
|
||||
/// [`Bot::get_chat`]: crate::Bot::get_chat
|
||||
/// [`GetChat`]: crate::payloads::GetChat
|
||||
pub permissions: Option<ChatPermissions>,
|
||||
}
|
||||
|
||||
|
@ -219,27 +219,27 @@ pub struct PublicChatSupergroup {
|
|||
pub username: Option<String>,
|
||||
|
||||
/// For supergroups, name of group sticker set. Returned only from
|
||||
/// [`Bot::get_chat`].
|
||||
/// [`GetChat`].
|
||||
///
|
||||
/// [`Bot::get_chat`]: crate::Bot::get_chat
|
||||
/// [`GetChat`]: crate::payloads::GetChat
|
||||
pub sticker_set_name: Option<String>,
|
||||
|
||||
/// `true`, if the bot can change the group sticker set. Returned only
|
||||
/// from [`Bot::get_chat`].
|
||||
/// from [`GetChat`].
|
||||
///
|
||||
/// [`Bot::get_chat`]: crate::Bot::get_chat
|
||||
/// [`GetChat`]: crate::payloads::GetChat
|
||||
pub can_set_sticker_set: Option<bool>,
|
||||
|
||||
/// A default chat member permissions, for groups and supergroups.
|
||||
/// Returned only from [`Bot::get_chat`].
|
||||
/// Returned only from [`GetChat`].
|
||||
///
|
||||
/// [`Bot::get_chat`]: crate::Bot::get_chat
|
||||
/// [`GetChat`]: crate::payloads::GetChat
|
||||
pub permissions: Option<ChatPermissions>,
|
||||
|
||||
/// The minimum allowed delay between consecutive messages sent by each
|
||||
/// unpriviledged user. Returned only from [`Bot::get_chat`].
|
||||
/// unpriviledged user. Returned only from [`GetChat`].
|
||||
///
|
||||
/// [`Bot::get_chat`]: crate::Bot::get_chat
|
||||
/// [`GetChat`]: crate::payloads::GetChat
|
||||
pub slow_mode_delay: Option<i32>,
|
||||
}
|
||||
|
||||
|
|
|
@ -4,11 +4,11 @@ use serde::{Deserialize, Serialize};
|
|||
///
|
||||
/// The file can be downloaded via the link `https://api.telegram.org/file/bot<token>/<file_path>`.
|
||||
/// It is guaranteed that the link will be valid for at least 1 hour. When the
|
||||
/// link expires, a new one can be requested by calling [`Bot::get_file`].
|
||||
/// link expires, a new one can be requested by calling [`GetFile`].
|
||||
///
|
||||
/// [The official docs](https://core.telegram.org/bots/api#file).
|
||||
///
|
||||
/// [`Bot::get_file`]: crate::Bot::get_file
|
||||
/// [`GetFile`]: crate::payloads::GetFile
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||
pub struct File {
|
||||
/// Identifier for this file.
|
||||
|
|
|
@ -20,14 +20,15 @@ pub struct Game {
|
|||
/// Photo that will be displayed in the game message in chats.
|
||||
pub photo: Vec<PhotoSize>,
|
||||
|
||||
// FIXME(waffle): SetGameScore method is missing for some reason O_o
|
||||
#[allow(broken_intra_doc_links)]
|
||||
/// Brief description of the game or high scores included in the game
|
||||
/// message. Can be automatically edited to include current high scores
|
||||
/// for the game when the bot calls [`Bot::set_game_score`], or manually
|
||||
/// edited using [`Bot::edit_message_text`]. 0-4096 characters.
|
||||
/// for the game when the bot calls [`SetGameScore`], or manually
|
||||
/// edited using [`EditMessageText`]. 0-4096 characters.
|
||||
///
|
||||
/// [`Bot::set_game_score`]: crate::Bot::set_game_score
|
||||
///
|
||||
/// [`Bot::edit_message_text`]: crate::Bot::edit_message_text
|
||||
/// [`SetGameScore`]: crate::payloads::SetGameScore
|
||||
/// [`EditMessageText`]: crate::payloads::EditMessageText
|
||||
pub text: Option<String>,
|
||||
|
||||
/// Special entities that appear in text, such as usernames, URLs, bot
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use crate::types::User;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Returned only in [`Bot::get_me`].
|
||||
/// Returned only in [`GetMe`].
|
||||
///
|
||||
/// [`Bot::get_me`]: crate::Bot::get_me
|
||||
/// [`GetMe`]: crate::payloads::GetMe
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Me {
|
||||
#[serde(flatten)]
|
||||
|
|
|
@ -16,13 +16,11 @@ use crate::types::{
|
|||
pub struct Update {
|
||||
/// The update‘s unique identifier. Update identifiers start from a certain
|
||||
/// positive number and increase sequentially. This ID becomes especially
|
||||
/// handy if you’re using [Webhooks], since it allows you to ignore
|
||||
/// handy if you’re using webhooks, since it allows you to ignore
|
||||
/// repeated updates or to restore the correct update sequence, should
|
||||
/// they get out of order. If there are no new updates for at least a
|
||||
/// week, then identifier of the next update will be chosen randomly
|
||||
/// instead of sequentially.
|
||||
///
|
||||
/// [Webhooks]: crate::Bot::set_webhook
|
||||
#[serde(rename = "update_id")]
|
||||
pub id: i32,
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue