Add Bot::{get_updates, get_me, send_message, send_animation}

This commit is contained in:
Waffle 2019-11-05 19:45:56 +03:00
parent fa220a6883
commit c0953893b5
3 changed files with 55 additions and 4 deletions

View file

@ -0,0 +1,51 @@
use crate::{
Bot,
requests::{
simple, json, multipart,
payloads::{GetMe, GetUpdates, SendMessage, SendAnimation}
},
types::{ChatId, InputFile},
};
impl Bot {
// Methods are sorted as in tg docs (https://core.telegram.org/bots/api)
// Getting updates
/// For tg-method documentation see [`GetUpdates`]
///
/// [`GetUpdates`]: crate::requests::payloads::GetUpdates
pub fn get_updates(&self) -> json::Request<GetUpdates> {
json::Request::new(self, GetUpdates::new())
}
// Available methods
/// For tg-method documentation see [`GetMe`]
///
/// [`GetMe`]: crate::requests::payloads::GetMe
pub fn get_me(&self) -> simple::Request<GetMe> {
simple::Request::new(self)
}
/// For tg-method documentation see [`SendMessage`]
///
/// [`SendMessage`]: crate::requests::payloads::SendMessage
pub fn send_message<C, T>(&self, chat_id: C, text: T)
-> json::Request<SendMessage>
where
C: Into<ChatId>,
T: Into<String>,
{
json::Request::new(self, SendMessage::new(chat_id, text))
}
/// For tg-method documentation see [`SendAnimation`]
///
/// [`SendAnimation`]: crate::requests::payloads::SendAnimation
pub fn send_animation<C>(&self, chat_id: C, animation: InputFile)
-> multipart::Request<SendAnimation>
where
C: Into<ChatId>,
{
multipart::Request::new(self, SendAnimation::new(chat_id, animation))
}
}

View file

@ -87,8 +87,8 @@ impl dynamic::Payload for SendAnimation {
impl SendAnimation {
pub fn new<C>(chat_id: C, animation: InputFile) -> Self
where
C: Into<ChatId>,
where
C: Into<ChatId>,
{
Self {
chat_id: chat_id.into(),

View file

@ -51,10 +51,10 @@ impl dynamic::Payload for SendMessage {
}
impl SendMessage {
pub fn new<C, S>(chat_id: C, text: S) -> Self
pub fn new<C, T>(chat_id: C, text: T) -> Self
where
C: Into<ChatId>,
S: Into<String>, // TODO: into?
T: Into<String>, // TODO: into?
{
SendMessage {
chat_id: chat_id.into(),