mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
Add the missing methods to Bot (bot/api.h)
This commit is contained in:
parent
8b4fbe4bb5
commit
852b89be88
8 changed files with 58 additions and 29 deletions
|
@ -1,7 +1,8 @@
|
|||
use crate::bot::Bot;
|
||||
use crate::requests::{
|
||||
AnswerCallbackQuery, DeleteChatStickerSet, GetChatMember,
|
||||
GetChatMembersCount, SetChatStickerSet,
|
||||
GetChatMembersCount, SendAnimation, SendDocument, SendVideo,
|
||||
SetChatStickerSet,
|
||||
};
|
||||
use crate::{
|
||||
requests::{
|
||||
|
@ -10,7 +11,8 @@ use crate::{
|
|||
PinChatMessage, PromoteChatMember, RestrictChatMember, SendAudio,
|
||||
SendChatAction, SendContact, SendLocation, SendMediaGroup, SendMessage,
|
||||
SendPhoto, SendPoll, SendVenue, SendVideoNote, SendVoice,
|
||||
SetChatDescription, StopMessageLiveLocation, UnbanChatMember, UnpinChatMessage,
|
||||
SetChatDescription, StopMessageLiveLocation, UnbanChatMember,
|
||||
UnpinChatMessage,
|
||||
},
|
||||
types::{ChatAction, ChatId, ChatPermissions, InputFile, InputMedia},
|
||||
};
|
||||
|
@ -329,4 +331,32 @@ impl Bot {
|
|||
{
|
||||
GetChatMembersCount::new(self, chat_id)
|
||||
}
|
||||
|
||||
pub fn send_video<C, V>(&self, chat_id: C, video: V) -> SendVideo
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
V: Into<InputFile>,
|
||||
{
|
||||
SendVideo::new(self, chat_id, video)
|
||||
}
|
||||
|
||||
pub fn send_document<C, D>(&self, chat_id: C, document: D) -> SendDocument
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
D: Into<InputFile>,
|
||||
{
|
||||
SendDocument::new(self, chat_id, document)
|
||||
}
|
||||
|
||||
pub fn send_animation<C, S>(
|
||||
&self,
|
||||
chat_id: C,
|
||||
animation: S,
|
||||
) -> SendAnimation
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
S: Into<InputFile>,
|
||||
{
|
||||
SendAnimation::new(self, chat_id, animation)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ pub use send_venue::*;
|
|||
pub use send_video::*;
|
||||
pub use send_video_note::*;
|
||||
pub use send_voice::*;
|
||||
pub use set_chat_sticker_set::*;
|
||||
pub use set_chat_description::*;
|
||||
pub use set_chat_sticker_set::*;
|
||||
pub use stop_message_live_location::*;
|
||||
pub use unban_chat_member::*;
|
||||
pub use unpin_chat_message::*;
|
||||
|
@ -74,8 +74,8 @@ mod send_venue;
|
|||
mod send_video;
|
||||
mod send_video_note;
|
||||
mod send_voice;
|
||||
mod set_chat_sticker_set;
|
||||
mod set_chat_description;
|
||||
mod set_chat_sticker_set;
|
||||
mod stop_message_live_location;
|
||||
mod unban_chat_member;
|
||||
mod unpin_chat_message;
|
||||
|
|
|
@ -3,9 +3,8 @@ use async_trait::async_trait;
|
|||
use crate::bot::Bot;
|
||||
use crate::network;
|
||||
use crate::requests::{Request, ResponseResult};
|
||||
use crate::types::{ChatId, Message, ParseMode, ReplyMarkup, InputFile};
|
||||
use crate::types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup};
|
||||
|
||||
///TODO: add to bot api
|
||||
///Use this method to send animation files (GIF or H.264/MPEG-4 AVC video
|
||||
/// without sound). On success, the sent Message is returned. Bots can currently
|
||||
/// send animation files of up to 50 MB in size, this limit may be changed in
|
||||
|
|
|
@ -4,11 +4,9 @@ use crate::bot::Bot;
|
|||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message, ParseMode, ReplyMarkup, InputFile},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
};
|
||||
|
||||
// TODO: add method to bot/api
|
||||
|
||||
///Use this method to send general files. On success, the sent Message is
|
||||
/// returned. Bots can currently send files of any type of up to 50 MB in size,
|
||||
/// this limit may be changed in the future.
|
||||
|
|
|
@ -3,9 +3,8 @@ use async_trait::async_trait;
|
|||
use crate::bot::Bot;
|
||||
use crate::network;
|
||||
use crate::requests::{Request, ResponseResult};
|
||||
use crate::types::{ChatId, Message, ParseMode, ReplyMarkup, InputFile};
|
||||
use crate::types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup};
|
||||
|
||||
//TODO: add action to bot api
|
||||
///Use this method to send video files, Telegram clients support mp4 videos
|
||||
/// (other formats may be sent as Document). On success, the sent Message is
|
||||
/// returned. Bots can currently send video files of up to 50 MB in size, this
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::bot::Bot;
|
|||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message, ReplyMarkup, InputFile},
|
||||
types::{ChatId, InputFile, Message, ReplyMarkup},
|
||||
};
|
||||
|
||||
///As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::bot::Bot;
|
|||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message, ParseMode, ReplyMarkup, InputFile},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
};
|
||||
|
||||
///Use this method to send audio files, if you want Telegram clients to display
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{True, ChatId},
|
||||
bot::Bot,
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
@ -32,34 +32,35 @@ impl SetChatDescription<'_> {
|
|||
&self.bot.client(),
|
||||
&self.bot.token(),
|
||||
"setChatDescription",
|
||||
&self
|
||||
).await
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SetChatDescription<'a> {
|
||||
pub(crate) fn new<C>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
) -> Self
|
||||
where C: Into<ChatId>
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
description: None
|
||||
description: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, chat_id: T) -> Self
|
||||
where T: Into<ChatId>
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = chat_id.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn description<T>(mut self, description: T) -> Self
|
||||
where T: Into<String>
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.description = Some(description.into());
|
||||
self
|
||||
|
@ -77,7 +78,8 @@ mod tests {
|
|||
let method = SetChatDescription::new(&bot, chat_id);
|
||||
|
||||
let expected = r#"{"chat_id":123}"#;
|
||||
let actual = serde_json::to_string::<SetChatDescription>(&method).unwrap();
|
||||
let actual =
|
||||
serde_json::to_string::<SetChatDescription>(&method).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
|
@ -86,11 +88,12 @@ mod tests {
|
|||
let bot = Bot::new("token");
|
||||
let chat_id = 123;
|
||||
let description = "description";
|
||||
let method = SetChatDescription::new(&bot, chat_id)
|
||||
.description(description);
|
||||
let method =
|
||||
SetChatDescription::new(&bot, chat_id).description(description);
|
||||
|
||||
let expected = r#"{"chat_id":123,"description":"description"}"#;
|
||||
let actual = serde_json::to_string::<SetChatDescription>(&method).unwrap();
|
||||
let actual =
|
||||
serde_json::to_string::<SetChatDescription>(&method).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue