mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
Prototype hing-level api.
This commit is contained in:
parent
42c961b595
commit
8030fe4418
2 changed files with 47 additions and 0 deletions
46
src/bot/mod.rs
Normal file
46
src/bot/mod.rs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
use reqwest::r#async::Client;
|
||||||
|
use crate::core::requests::{
|
||||||
|
get_me::GetMe,
|
||||||
|
send_message::SendMessage,
|
||||||
|
RequestInfo,
|
||||||
|
ChatId,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
pub struct Bot {
|
||||||
|
token: String,
|
||||||
|
client: Client,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Bot {
|
||||||
|
pub fn new(token: &str) -> Self {
|
||||||
|
Bot {
|
||||||
|
token: String::from(token),
|
||||||
|
client: Client::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_client(token: &str, client: Client) -> Self {
|
||||||
|
Bot {
|
||||||
|
token: String::from(token),
|
||||||
|
client
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Telegram functions
|
||||||
|
impl Bot {
|
||||||
|
pub fn get_me(&self) -> GetMe {
|
||||||
|
GetMe::new(RequestInfo { token: &self.token, client: &self.client })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_message<C, T>(&self, chat_id: C, text: T) -> SendMessage
|
||||||
|
where C: Into<ChatId>, T: Into<String>
|
||||||
|
{
|
||||||
|
SendMessage::new(
|
||||||
|
RequestInfo { token: &self.token, client: &self.client },
|
||||||
|
chat_id.into(),
|
||||||
|
text.into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,3 +4,4 @@ extern crate derive_more;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
|
||||||
pub mod core;
|
pub mod core;
|
||||||
|
pub mod bot;
|
Loading…
Reference in a new issue