mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-22 06:45:37 +01:00
Merge pull request #40 from async-telegram-bot/add_methods_to_bot
Add some methods to `Bot`
This commit is contained in:
commit
1812ab10bf
2 changed files with 195 additions and 3 deletions
196
src/bot/api.rs
196
src/bot/api.rs
|
@ -3,9 +3,12 @@ use crate::{
|
||||||
requests::{
|
requests::{
|
||||||
ChatId, EditMessageLiveLocation, ForwardMessage, GetFile, GetMe,
|
ChatId, EditMessageLiveLocation, ForwardMessage, GetFile, GetMe,
|
||||||
SendAudio, SendLocation, SendMediaGroup, SendMessage, SendPhoto,
|
SendAudio, SendLocation, SendMediaGroup, SendMessage, SendPhoto,
|
||||||
StopMessageLiveLocation,
|
StopMessageLiveLocation, AnswerPreCheckoutQuery, AnswerShippingQuery,
|
||||||
|
KickChatMember, PinChatMessage, PromoteChatMember, RestrictChatMember,
|
||||||
|
SendChatAction, SendContact, SendPoll, SendVenue, SendVideoNote,
|
||||||
|
SendVoice, UnbanChatMember, UnpinChatMessage, ChatAction
|
||||||
},
|
},
|
||||||
types::{InputFile, InputMedia},
|
types::{InputFile, InputMedia, ChatPermissions},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Telegram functions
|
/// Telegram functions
|
||||||
|
@ -110,4 +113,193 @@ impl Bot {
|
||||||
{
|
{
|
||||||
GetFile::new(self.ctx(), file_id.into())
|
GetFile::new(self.ctx(), file_id.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn answer_pre_checkout_query<I, O>(
|
||||||
|
&self,
|
||||||
|
pre_checkout_query_id: I,
|
||||||
|
ok: O,
|
||||||
|
) -> AnswerPreCheckoutQuery
|
||||||
|
where
|
||||||
|
I: Into<String>,
|
||||||
|
O: Into<bool>
|
||||||
|
{
|
||||||
|
AnswerPreCheckoutQuery::new(
|
||||||
|
self.ctx(),
|
||||||
|
pre_checkout_query_id.into(),
|
||||||
|
ok.into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn answer_shipping_query<I, O>(
|
||||||
|
&self,
|
||||||
|
shipping_query_id: I,
|
||||||
|
ok: O,
|
||||||
|
) -> AnswerShippingQuery
|
||||||
|
where
|
||||||
|
I: Into<String>,
|
||||||
|
O: Into<bool>
|
||||||
|
{
|
||||||
|
AnswerShippingQuery::new(
|
||||||
|
self.ctx(),
|
||||||
|
shipping_query_id.into(),
|
||||||
|
ok.into()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn kick_chat_member<C, U>(
|
||||||
|
&self,
|
||||||
|
chat_id: C,
|
||||||
|
user_id: U,
|
||||||
|
) -> KickChatMember
|
||||||
|
where
|
||||||
|
C: Into<ChatId>,
|
||||||
|
U: Into<i32>,
|
||||||
|
{
|
||||||
|
KickChatMember::new(self.ctx(), chat_id.into(), user_id.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pin_chat_message<C, M>(
|
||||||
|
&self,
|
||||||
|
chat_id: C,
|
||||||
|
message_id: M
|
||||||
|
) -> PinChatMessage
|
||||||
|
where
|
||||||
|
C: Into<ChatId>,
|
||||||
|
M: Into<i32>,
|
||||||
|
{
|
||||||
|
PinChatMessage::new(self.ctx(), chat_id.into(), message_id.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn promote_chat_member<C, U>(
|
||||||
|
&self,
|
||||||
|
chat_id: C,
|
||||||
|
user_id: U,
|
||||||
|
) -> PromoteChatMember
|
||||||
|
where
|
||||||
|
C: Into<ChatId>,
|
||||||
|
U: Into<i32>,
|
||||||
|
{
|
||||||
|
PromoteChatMember::new(self.ctx(), chat_id.into(), user_id.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn restrict_chat_member<C, U, P>(
|
||||||
|
&self,
|
||||||
|
chat_id: C,
|
||||||
|
user_id: U,
|
||||||
|
permissions: P
|
||||||
|
) -> RestrictChatMember
|
||||||
|
where
|
||||||
|
C: Into<ChatId>,
|
||||||
|
U: Into<i32>,
|
||||||
|
P: Into<ChatPermissions>
|
||||||
|
{
|
||||||
|
RestrictChatMember::new(
|
||||||
|
self.ctx(),
|
||||||
|
chat_id.into(),
|
||||||
|
user_id.into(),
|
||||||
|
permissions.into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_chat_action<C, A>(&self, chat_id: C, action: A) -> SendChatAction
|
||||||
|
where
|
||||||
|
C: Into<ChatId>,
|
||||||
|
A: Into<ChatAction>,
|
||||||
|
{
|
||||||
|
SendChatAction::new(self.ctx(), chat_id.into(), action.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_contact<C, P, F>(
|
||||||
|
&self,
|
||||||
|
chat_id: C,
|
||||||
|
phone_number: P,
|
||||||
|
first_name: F,
|
||||||
|
) -> SendContact
|
||||||
|
where
|
||||||
|
C: Into<ChatId>,
|
||||||
|
P: Into<String>,
|
||||||
|
F: Into<String>
|
||||||
|
{
|
||||||
|
SendContact::new(
|
||||||
|
self.ctx(),
|
||||||
|
chat_id.into(),
|
||||||
|
phone_number.into(),
|
||||||
|
first_name.into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_poll<C, Q, O>(
|
||||||
|
&self,
|
||||||
|
chat_id: C,
|
||||||
|
question: Q,
|
||||||
|
options: O,
|
||||||
|
) -> SendPoll
|
||||||
|
where
|
||||||
|
C: Into<ChatId>,
|
||||||
|
Q: Into<String>,
|
||||||
|
O: Into<Vec<String>>
|
||||||
|
{
|
||||||
|
SendPoll::new(
|
||||||
|
self.ctx(),
|
||||||
|
chat_id.into(),
|
||||||
|
question.into(),
|
||||||
|
options.into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_venue<C, Lt, Lg, T, A>(
|
||||||
|
&self,
|
||||||
|
chat_id: C,
|
||||||
|
latitude: Lt,
|
||||||
|
longitude: Lg,
|
||||||
|
title: T,
|
||||||
|
address: A,
|
||||||
|
) -> SendVenue
|
||||||
|
where
|
||||||
|
C: Into<ChatId>,
|
||||||
|
Lt: Into<f64>,
|
||||||
|
Lg: Into<f64>,
|
||||||
|
T: Into<String>,
|
||||||
|
A: Into<String>,
|
||||||
|
{
|
||||||
|
SendVenue::new(
|
||||||
|
self.ctx(),
|
||||||
|
chat_id.into(),
|
||||||
|
latitude.into(),
|
||||||
|
longitude.into(),
|
||||||
|
title.into(),
|
||||||
|
address.into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_video_note<C, V>(&self, chat_id: C, video_note: V) -> SendVideoNote
|
||||||
|
where
|
||||||
|
C: Into<ChatId>,
|
||||||
|
V: Into<String>, // TODO: InputFile
|
||||||
|
{
|
||||||
|
SendVideoNote::new(self.ctx(), chat_id.into(), video_note.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_voice<C, V>(&self, chat_id: C, voice: V) -> SendVoice
|
||||||
|
where
|
||||||
|
C: Into<ChatId>,
|
||||||
|
V: Into<String>, // TODO: InputFile
|
||||||
|
{
|
||||||
|
SendVoice::new(self.ctx(), chat_id.into(), voice.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unban_chat_member<C, U>(&self, chat_id: C, user_id: U) -> UnbanChatMember
|
||||||
|
where
|
||||||
|
C: Into<ChatId>,
|
||||||
|
U: Into<i32>,
|
||||||
|
{
|
||||||
|
UnbanChatMember::new(self.ctx(), chat_id.into(), user_id.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unpin_chat_message<C>(&self, chat_id: C) -> UnpinChatMessage
|
||||||
|
where
|
||||||
|
C: Into<ChatId>,
|
||||||
|
{
|
||||||
|
UnpinChatMessage::new(self.ctx(), chat_id.into())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub use self::{
|
||||||
kick_chat_member::KickChatMember, pin_chat_message::PinChatMessage,
|
kick_chat_member::KickChatMember, pin_chat_message::PinChatMessage,
|
||||||
promote_chat_member::PromoteChatMember,
|
promote_chat_member::PromoteChatMember,
|
||||||
restrict_chat_member::RestrictChatMember, send_animation::SendAnimation,
|
restrict_chat_member::RestrictChatMember, send_animation::SendAnimation,
|
||||||
send_audio::SendAudio, send_chat_action::SendChatAction,
|
send_audio::SendAudio, send_chat_action::{SendChatAction, ChatAction},
|
||||||
send_contact::SendContact, send_document::SendDocument,
|
send_contact::SendContact, send_document::SendDocument,
|
||||||
send_location::SendLocation, send_media_group::SendMediaGroup,
|
send_location::SendLocation, send_media_group::SendMediaGroup,
|
||||||
send_message::SendMessage, send_photo::SendPhoto, send_poll::SendPoll,
|
send_message::SendMessage, send_photo::SendPhoto, send_poll::SendPoll,
|
||||||
|
|
Loading…
Add table
Reference in a new issue