Replace 'RequestContext' with 'Bot'

This commit is contained in:
Temirkhan Myrzamadi 2019-10-17 10:36:30 +06:00
parent 5a399778c7
commit 4ce7ceb831
36 changed files with 247 additions and 234 deletions

View file

@ -1,5 +1,4 @@
use crate::{
bot::Bot,
requests::{
AnswerPreCheckoutQuery, AnswerShippingQuery, EditMessageLiveLocation,
ForwardMessage, GetFile, GetMe, KickChatMember, PinChatMessage,
@ -10,15 +9,16 @@ use crate::{
},
types::{ChatAction, ChatId, ChatPermissions, InputFile, InputMedia},
};
use crate::bot::Bot;
/// Telegram functions
impl Bot {
pub fn get_me(&self) -> GetMe {
GetMe::new(self.ctx())
GetMe::new(&self)
}
pub fn get_updates(&self) -> GetUpdates {
GetUpdates::new(self.ctx())
GetUpdates::new(&self)
}
pub fn send_message<C, T>(&self, chat_id: C, text: T) -> SendMessage
@ -26,7 +26,7 @@ impl Bot {
C: Into<ChatId>,
T: Into<String>,
{
SendMessage::new(self.ctx(), chat_id, text)
SendMessage::new(&self, chat_id, text)
}
pub fn edit_message_live_location<Lt, Lg>(
@ -38,7 +38,7 @@ impl Bot {
Lt: Into<f64>,
Lg: Into<f64>,
{
EditMessageLiveLocation::new(self.ctx(), latitude, longitude)
EditMessageLiveLocation::new(&self, latitude, longitude)
}
pub fn forward_message<C, F, M>(
@ -52,7 +52,7 @@ impl Bot {
F: Into<ChatId>,
M: Into<i32>,
{
ForwardMessage::new(self.ctx(), chat_id, from_chat_id, message_id)
ForwardMessage::new(&self, chat_id, from_chat_id, message_id)
}
pub fn send_audio<C, A>(&self, chat_id: C, audio: A) -> SendAudio
@ -60,7 +60,7 @@ impl Bot {
C: Into<ChatId>,
A: Into<InputFile>,
{
SendAudio::new(self.ctx(), chat_id, audio)
SendAudio::new(&self, chat_id, audio)
}
pub fn send_location<C, Lt, Lg>(
@ -74,7 +74,7 @@ impl Bot {
Lt: Into<f64>,
Lg: Into<f64>,
{
SendLocation::new(self.ctx(), chat_id, latitude, longitude)
SendLocation::new(&self, chat_id, latitude, longitude)
}
pub fn send_media_group<C, M>(&self, chat_id: C, media: M) -> SendMediaGroup
@ -82,7 +82,7 @@ impl Bot {
C: Into<ChatId>,
M: Into<Vec<InputMedia>>,
{
SendMediaGroup::new(self.ctx(), chat_id, media)
SendMediaGroup::new(&self, chat_id, media)
}
pub fn send_photo<C, P>(&self, chat_id: C, photo: P) -> SendPhoto
@ -90,18 +90,18 @@ impl Bot {
C: Into<ChatId>,
P: Into<InputFile>,
{
SendPhoto::new(self.ctx(), chat_id, photo)
SendPhoto::new(&self, chat_id, photo)
}
pub fn stop_message_live_location(&self) -> StopMessageLiveLocation {
StopMessageLiveLocation::new(self.ctx())
StopMessageLiveLocation::new(&self)
}
pub fn get_file<F>(&self, file_id: F) -> GetFile
where
F: Into<String>,
{
GetFile::new(self.ctx(), file_id)
GetFile::new(&self, file_id)
}
pub fn answer_pre_checkout_query<I, O>(
@ -113,7 +113,7 @@ impl Bot {
I: Into<String>,
O: Into<bool>,
{
AnswerPreCheckoutQuery::new(self.ctx(), pre_checkout_query_id, ok)
AnswerPreCheckoutQuery::new(&self, pre_checkout_query_id, ok)
}
pub fn answer_shipping_query<I, O>(
@ -125,7 +125,7 @@ impl Bot {
I: Into<String>,
O: Into<bool>,
{
AnswerShippingQuery::new(self.ctx(), shipping_query_id, ok)
AnswerShippingQuery::new(&self, shipping_query_id, ok)
}
pub fn kick_chat_member<C, U>(
@ -137,7 +137,7 @@ impl Bot {
C: Into<ChatId>,
U: Into<i32>,
{
KickChatMember::new(self.ctx(), chat_id, user_id)
KickChatMember::new(&self, chat_id, user_id)
}
pub fn pin_chat_message<C, M>(
@ -149,7 +149,7 @@ impl Bot {
C: Into<ChatId>,
M: Into<i32>,
{
PinChatMessage::new(self.ctx(), chat_id, message_id)
PinChatMessage::new(&self, chat_id, message_id)
}
pub fn promote_chat_member<C, U>(
@ -161,7 +161,7 @@ impl Bot {
C: Into<ChatId>,
U: Into<i32>,
{
PromoteChatMember::new(self.ctx(), chat_id, user_id)
PromoteChatMember::new(&self, chat_id, user_id)
}
pub fn restrict_chat_member<C, U, P>(
@ -175,7 +175,7 @@ impl Bot {
U: Into<i32>,
P: Into<ChatPermissions>,
{
RestrictChatMember::new(self.ctx(), chat_id, user_id, permissions)
RestrictChatMember::new(&self, chat_id, user_id, permissions)
}
pub fn send_chat_action<C, A>(
@ -187,7 +187,7 @@ impl Bot {
C: Into<ChatId>,
A: Into<ChatAction>,
{
SendChatAction::new(self.ctx(), chat_id, action)
SendChatAction::new(&self, chat_id, action)
}
pub fn send_contact<C, P, F>(
@ -201,7 +201,7 @@ impl Bot {
P: Into<String>,
F: Into<String>,
{
SendContact::new(self.ctx(), chat_id, phone_number, first_name)
SendContact::new(&self, chat_id, phone_number, first_name)
}
pub fn send_poll<C, Q, O>(
@ -215,7 +215,7 @@ impl Bot {
Q: Into<String>,
O: Into<Vec<String>>,
{
SendPoll::new(self.ctx(), chat_id, question, options)
SendPoll::new(&self, chat_id, question, options)
}
pub fn send_venue<C, Lt, Lg, T, A>(
@ -233,7 +233,7 @@ impl Bot {
T: Into<String>,
A: Into<String>,
{
SendVenue::new(self.ctx(), chat_id, latitude, longitude, title, address)
SendVenue::new(&self, chat_id, latitude, longitude, title, address)
}
pub fn send_video_note<C, V>(
@ -245,7 +245,7 @@ impl Bot {
C: Into<ChatId>,
V: Into<String>, // TODO: InputFile
{
SendVideoNote::new(self.ctx(), chat_id, video_note)
SendVideoNote::new(&self, chat_id, video_note)
}
pub fn send_voice<C, V>(&self, chat_id: C, voice: V) -> SendVoice
@ -253,7 +253,7 @@ impl Bot {
C: Into<ChatId>,
V: Into<String>, // TODO: InputFile
{
SendVoice::new(self.ctx(), chat_id, voice)
SendVoice::new(&self, chat_id, voice)
}
pub fn unban_chat_member<C, U>(
@ -265,13 +265,13 @@ impl Bot {
C: Into<ChatId>,
U: Into<i32>,
{
UnbanChatMember::new(self.ctx(), chat_id, user_id)
UnbanChatMember::new(&self, chat_id, user_id)
}
pub fn unpin_chat_message<C>(&self, chat_id: C) -> UnpinChatMessage
where
C: Into<ChatId>,
{
UnpinChatMessage::new(self.ctx(), chat_id)
UnpinChatMessage::new(&self, chat_id)
}
}

View file

@ -5,7 +5,8 @@ use ::{bytes::Bytes, tokio::stream::Stream};
#[cfg(feature = "unstable-stream")]
use crate::network::download_file_stream;
use crate::{bot::Bot, network::download_file, DownloadError};
use crate::{network::download_file, DownloadError};
use crate::bot::Bot;
impl Bot {
/// Download file from telegram into `destination`.
@ -17,7 +18,7 @@ impl Bot {
///
/// ```no_run
/// use telebofr::{
/// bot::Bot, requests::Request, types::File as TgFile,
/// bot:: requests::Request, types::File as TgFile,
/// };
/// use tokio::fs::File;
/// # use telebofr::RequestError;

View file

@ -2,11 +2,10 @@
use reqwest::Client;
use crate::requests::RequestContext;
mod api;
mod download;
#[derive(Debug, Clone)]
pub struct Bot {
token: String,
client: Client,
@ -30,10 +29,11 @@ impl Bot {
}
impl Bot {
fn ctx(&self) -> RequestContext {
RequestContext {
token: &self.token,
client: &self.client,
}
pub fn token(&self) -> &str {
&self.token
}
pub fn client(&self) -> &Client {
&self.client
}
}

View file

@ -41,7 +41,7 @@ type Handlers<'a, T, E> = Vec<(Box<dyn Filter<T> + 'a>, Box<dyn Handler<'a, T, E
/// # async fn run() {
/// use std::convert::Infallible;
/// use telebofr::{
/// bot::Bot,
/// bot::
/// types::Message,
/// dispatcher::{
/// updater::polling,

View file

@ -7,10 +7,10 @@ use pin_project::pin_project;
use futures::{Stream, StreamExt, stream};
use crate::{
bot::Bot,
types::Update,
RequestError,
};
use crate::bot::Bot;
// Currently just a placeholder, but I'll add here some methods
/// Updater is stream of updates.
@ -148,4 +148,4 @@ pub fn polling<'a>(bot: &'a Bot) -> impl Updater<Error = RequestError> + 'a {
// TODO implement webhook (this actually require webserver and probably we
// should add cargo feature that adds webhook)
//pub fn webhook<'a>(bot: &'a Bot, cfg: WebhookConfig) -> Updater<impl Stream<Item=Result<Update, ???>> + 'a> {}
//pub fn webhook<'a>(bot: &'a cfg: WebhookConfig) -> Updater<impl Stream<Item=Result<Update, ???>> + 'a> {}

View file

@ -2,9 +2,10 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::True,
};
use crate::bot::Bot;
#[derive(Debug, Serialize, Clone)]
/// Once the user has confirmed their payment and shipping details, the Bot API
@ -16,7 +17,7 @@ use crate::{
/// [`Update`]: crate::types::Update
pub struct AnswerPreCheckoutQuery<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Unique identifier for the query to be answered
pub pre_checkout_query_id: String,
@ -48,8 +49,8 @@ impl Request for AnswerPreCheckoutQuery<'_> {
impl AnswerPreCheckoutQuery<'_> {
pub async fn send(self) -> ResponseResult<True> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"answerPreCheckoutQuery",
&self,
)
@ -59,7 +60,7 @@ impl AnswerPreCheckoutQuery<'_> {
impl<'a> AnswerPreCheckoutQuery<'a> {
pub(crate) fn new<S, B>(
ctx: RequestContext<'a>,
bot: &'a Bot,
pre_checkout_query_id: S,
ok: B,
) -> Self
@ -68,7 +69,7 @@ impl<'a> AnswerPreCheckoutQuery<'a> {
B: Into<bool>,
{
Self {
ctx,
bot,
pre_checkout_query_id: pre_checkout_query_id.into(),
ok: ok.into(),
error_message: None,

View file

@ -2,9 +2,10 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ShippingOption, True},
};
use crate::bot::Bot;
#[derive(Debug, Clone, Serialize)]
/// If you sent an invoice requesting a shipping address and the parameter
@ -15,7 +16,7 @@ use crate::{
/// [`Update`]: crate::types::Update
pub struct AnswerShippingQuery<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Unique identifier for the query to be answered
pub shipping_query_id: String,
@ -49,8 +50,8 @@ impl Request for AnswerShippingQuery<'_> {
impl AnswerShippingQuery<'_> {
pub async fn send(self) -> ResponseResult<True> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"answerShippingQuery",
&self,
)
@ -60,7 +61,7 @@ impl AnswerShippingQuery<'_> {
impl<'a> AnswerShippingQuery<'a> {
pub(crate) fn new<S, B>(
ctx: RequestContext<'a>,
bot: &'a Bot,
shipping_query_id: S,
ok: B,
) -> Self
@ -69,7 +70,7 @@ impl<'a> AnswerShippingQuery<'a> {
B: Into<bool>,
{
Self {
ctx,
bot,
shipping_query_id: shipping_query_id.into(),
ok: ok.into(),
shipping_options: None,

View file

@ -2,9 +2,10 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, Message, ReplyMarkup},
};
use crate::bot::Bot;
#[derive(Debug, Clone, Serialize)]
/// Use this method to edit live location messages. A location can be edited
@ -17,7 +18,7 @@ use crate::{
/// [`Message`]: crate::types::Message
pub struct EditMessageLiveLocation<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
#[serde(skip_serializing_if = "Option::is_none")]
/// Required if inline_message_id is not specified. Unique identifier for
@ -53,8 +54,8 @@ impl Request for EditMessageLiveLocation<'_> {
impl EditMessageLiveLocation<'_> {
pub async fn send(self) -> ResponseResult<Message> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"editMessageLiveLocation",
&self,
)
@ -64,7 +65,7 @@ impl EditMessageLiveLocation<'_> {
impl<'a> EditMessageLiveLocation<'a> {
pub(crate) fn new<Lt, Lg>(
ctx: RequestContext<'a>,
bot: &'a Bot,
latitude: Lt,
longitude: Lg,
) -> Self
@ -73,7 +74,7 @@ impl<'a> EditMessageLiveLocation<'a> {
Lg: Into<f64>,
{
Self {
ctx,
bot,
chat_id: None,
message_id: None,
inline_message_id: None,

View file

@ -2,16 +2,17 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, Message},
};
use crate::bot::Bot;
#[derive(Debug, Clone, Serialize)]
/// Use this method to forward messages of any kind. On success, the sent
/// [`Message`] is returned.
pub struct ForwardMessage<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
@ -40,8 +41,8 @@ impl Request for ForwardMessage<'_> {
impl ForwardMessage<'_> {
pub async fn send(self) -> ResponseResult<Message> {
network::request_json(
self.ctx.client,
self.ctx.token,
self.bot.client(),
self.bot.token(),
"forwardMessage",
&self,
)
@ -51,7 +52,7 @@ impl ForwardMessage<'_> {
impl<'a> ForwardMessage<'a> {
pub(crate) fn new<C, Fc, M>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
from_chat_id: Fc,
message_id: M,
@ -62,7 +63,7 @@ impl<'a> ForwardMessage<'a> {
M: Into<i32>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
from_chat_id: from_chat_id.into(),
message_id: message_id.into(),

View file

@ -2,9 +2,10 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{Chat, ChatId},
};
use crate::bot::Bot;
/// Use this method to get up to date information about the chat
/// (current name of the user for one-on-one conversations,
@ -13,7 +14,7 @@ use crate::{
#[derive(Debug, Clone, Serialize)]
pub struct GetChat<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Unique identifier for the target chat or username
/// of the target supergroup or channel (in the format @channelusername)
chat_id: ChatId,
@ -31,8 +32,8 @@ impl Request for GetChat<'_> {
impl GetChat<'_> {
pub async fn send(self) -> ResponseResult<Chat> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"getChat",
&self,
)

View file

@ -2,9 +2,10 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::File,
};
use crate::bot::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.
@ -16,7 +17,7 @@ use crate::{
#[derive(Debug, Clone, Serialize)]
pub struct GetFile<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// File identifier to get info about
pub file_id: String,
}
@ -33,8 +34,8 @@ impl Request for GetFile<'_> {
impl GetFile<'_> {
pub async fn send(self) -> ResponseResult<File> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"getFile",
&self,
)
@ -43,12 +44,12 @@ impl GetFile<'_> {
}
impl<'a> GetFile<'a> {
pub(crate) fn new<F>(ctx: RequestContext<'a>, value: F) -> Self
pub(crate) fn new<F>(bot: &'a Bot, value: F) -> Self
where
F: Into<String>,
{
Self {
ctx,
bot,
file_id: value.into(),
}
}

View file

@ -2,15 +2,16 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::User,
};
use crate::bot::Bot;
#[derive(Debug, Clone)]
/// A simple method for testing your bot's auth token. Requires no parameters.
/// Returns basic information about the bot in form of a [`User`] object.
pub struct GetMe<'a> {
ctx: RequestContext<'a>,
bot: &'a Bot,
}
#[async_trait]
@ -24,12 +25,12 @@ impl Request for GetMe<'_> {
impl GetMe<'_> {
pub async fn send(self) -> ResponseResult<User> {
network::request_simple(self.ctx.client, self.ctx.token, "getMe").await
network::request_simple(self.bot.client(), self.bot.token(), "getMe").await
}
}
impl<'a> GetMe<'a> {
pub(crate) fn new(ctx: RequestContext<'a>) -> Self {
GetMe { ctx }
pub(crate) fn new(bot: &'a Bot) -> Self {
GetMe { bot }
}
}

View file

@ -2,14 +2,15 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::Update,
};
use crate::bot::Bot;
#[derive(Debug, Clone, Serialize)]
pub struct GetUpdates<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
pub offset: Option<i32>,
pub limit: Option<u8>,
@ -41,8 +42,8 @@ impl Request for GetUpdates<'_> {
impl GetUpdates<'_> {
pub async fn send(self) -> ResponseResult<Vec<Update>> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"getUpdates",
&self,
)
@ -51,9 +52,9 @@ impl GetUpdates<'_> {
}
impl<'a> GetUpdates<'a> {
pub(crate) fn new(ctx: RequestContext<'a>) -> Self {
pub(crate) fn new(bot: &'a Bot) -> Self {
Self {
ctx,
bot,
offset: None,
limit: None,
timeout: None,

View file

@ -2,16 +2,17 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::UserProfilePhotos,
};
use crate::bot::Bot;
///Use this method to get a list of profile pictures for a user. Returns a
/// UserProfilePhotos object.
#[derive(Debug, Clone, Serialize)]
pub struct GetUserProfilePhotos<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Unique identifier of the target user
pub user_id: i32,
/// Sequential number of the first photo to be returned. By default, all
@ -36,8 +37,8 @@ impl Request for GetUserProfilePhotos<'_> {
impl GetUserProfilePhotos<'_> {
async fn send(self) -> ResponseResult<UserProfilePhotos> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"getUserProfilePhotos",
&self,
)
@ -46,12 +47,12 @@ impl GetUserProfilePhotos<'_> {
}
impl<'a> GetUserProfilePhotos<'a> {
pub fn new<U>(ctx: RequestContext<'a>, user_id: U) -> Self
pub fn new<U>(bot: &'a Bot, user_id: U) -> Self
where
U: Into<i32>,
{
Self {
ctx,
bot,
user_id: user_id.into(),
offset: None,
limit: None,

View file

@ -2,9 +2,10 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, True},
};
use crate::bot::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
@ -14,7 +15,7 @@ use crate::{
#[derive(Debug, Clone, Serialize)]
pub struct KickChatMember<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
///Unique identifier for the target group or username of the target
/// supergroup or channel (in the format @channelusername)
pub chat_id: ChatId,
@ -39,8 +40,8 @@ impl Request for KickChatMember<'_> {
impl KickChatMember<'_> {
async fn send(self) -> ResponseResult<True> {
network::request_json(
self.ctx.client,
self.ctx.token,
self.bot.client(),
self.bot.token(),
"kickChatMember",
&self,
)
@ -50,7 +51,7 @@ impl KickChatMember<'_> {
impl<'a> KickChatMember<'a> {
pub(crate) fn new<C, U>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
user_id: U,
) -> Self
@ -59,7 +60,7 @@ impl<'a> KickChatMember<'a> {
U: Into<i32>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
user_id: user_id.into(),
until_date: None,

View file

@ -1,6 +1,5 @@
//! Raw API functions.
use reqwest::Client;
use serde::de::DeserializeOwned;
use async_trait::async_trait;
@ -72,13 +71,4 @@ pub trait Request {
/// Send this request.
async fn send_boxed(self) -> ResponseResult<Self::Output>;
}
/// A context used to send all the requests.
#[derive(Debug, Clone)]
pub struct RequestContext<'a> {
/// An HTTPS client.
pub client: &'a Client,
/// A token of your bot.
pub token: &'a str,
}
}

View file

@ -2,9 +2,10 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, True},
};
use crate::bot::Bot;
/// Use this method to get up to date information about the chat
/// (current name of the user for one-on-one conversations,
@ -13,7 +14,7 @@ use crate::{
#[derive(Debug, Clone, Serialize)]
pub struct PinChatMessage<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Unique identifier for the target chat or username
/// of the target supergroup or channel (in the format @channelusername)
pub chat_id: ChatId,
@ -23,7 +24,7 @@ pub struct PinChatMessage<'a> {
impl<'a> PinChatMessage<'a> {
pub(crate) fn new<C, M>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
message_id: M,
) -> Self
@ -32,7 +33,7 @@ impl<'a> PinChatMessage<'a> {
M: Into<i32>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
message_id: message_id.into(),
disable_notification: None,
@ -59,8 +60,8 @@ impl Request for PinChatMessage<'_> {
impl PinChatMessage<'_> {
async fn send(self) -> ResponseResult<True> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"pinChatMessage",
&self,
)

View file

@ -2,9 +2,10 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, True},
};
use crate::bot::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
@ -13,7 +14,7 @@ use crate::{
#[derive(Debug, Clone, Serialize)]
pub struct PromoteChatMember<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
///Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
pub chat_id: ChatId,
@ -62,8 +63,8 @@ impl Request for PromoteChatMember<'_> {
impl PromoteChatMember<'_> {
pub async fn send(self) -> ResponseResult<True> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"promoteChatMember",
&self,
)
@ -73,7 +74,7 @@ impl PromoteChatMember<'_> {
impl<'a> PromoteChatMember<'a> {
pub(crate) fn new<C, U>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
user_id: U,
) -> Self
@ -82,7 +83,7 @@ impl<'a> PromoteChatMember<'a> {
U: Into<i32>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
user_id: user_id.into(),
can_change_info: None,

View file

@ -2,9 +2,10 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, ChatPermissions, True},
};
use crate::bot::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
@ -13,7 +14,7 @@ use crate::{
#[derive(Debug, Clone, Serialize)]
pub struct RestrictChatMember<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
///Unique identifier for the target chat or username of the target
/// supergroup (in the format @supergroupusername)
pub chat_id: ChatId,
@ -40,8 +41,8 @@ impl Request for RestrictChatMember<'_> {
impl RestrictChatMember<'_> {
async fn send(self) -> ResponseResult<True> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"restrictChatMember",
&self,
)
@ -51,7 +52,7 @@ impl RestrictChatMember<'_> {
impl<'a> RestrictChatMember<'a> {
pub(crate) fn new<C, U, P>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
user_id: U,
permissions: P,
@ -62,7 +63,7 @@ impl<'a> RestrictChatMember<'a> {
P: Into<ChatPermissions>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
user_id: user_id.into(),
permissions: permissions.into(),

View file

@ -1,8 +1,9 @@
use async_trait::async_trait;
use crate::network;
use crate::requests::{Request, RequestContext, ResponseResult};
use crate::requests::{Request, ResponseResult};
use crate::types::{ChatId, Message, ParseMode, ReplyMarkup};
use crate::bot::Bot;
///TODO: add to bot api
///Use this method to send animation files (GIF or H.264/MPEG-4 AVC video
@ -12,7 +13,7 @@ use crate::types::{ChatId, Message, ParseMode, ReplyMarkup};
#[derive(Debug, Clone, Serialize)]
pub struct SendAnimation<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
///Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
pub chat_id: ChatId,
@ -76,8 +77,8 @@ impl Request for SendAnimation<'_> {
impl SendAnimation<'_> {
async fn send(self) -> ResponseResult<Message> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"sendAnimation",
&self,
)
@ -87,7 +88,7 @@ impl SendAnimation<'_> {
impl<'a> SendAnimation<'a> {
pub(crate) fn new<C, S>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
animation: S,
) -> Self
@ -96,7 +97,7 @@ impl<'a> SendAnimation<'a> {
S: Into<String>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
animation: animation.into(),
duration: None,

View file

@ -3,10 +3,11 @@ use async_trait::async_trait;
use crate::{
network,
requests::{
form_builder::FormBuilder, Request, RequestContext, ResponseResult,
form_builder::FormBuilder, Request, ResponseResult,
},
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
};
use crate::bot::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 format. On success,
@ -18,7 +19,7 @@ use crate::{
/// [`Message`]: crate::types::Message
/// [`SendVoice`]: crate::requests::SendVoice
pub struct SendAudio<'a> {
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
@ -88,8 +89,8 @@ impl SendAudio<'_> {
network::request_multipart(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"sendAudio",
params.build(),
)
@ -99,7 +100,7 @@ impl SendAudio<'_> {
impl<'a> SendAudio<'a> {
pub(crate) fn new<C, A>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
audio: A,
) -> Self
@ -108,7 +109,7 @@ impl<'a> SendAudio<'a> {
A: Into<InputFile>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
audio: audio.into(),
caption: None,

View file

@ -2,9 +2,10 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatAction, ChatId, True},
};
use crate::bot::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
@ -13,7 +14,7 @@ use crate::{
#[derive(Debug, Clone, Serialize)]
pub struct SendChatAction<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Unique identifier for the target chat or
/// username of the target channel (in the format @channelusername)
pub chat_id: ChatId,
@ -37,8 +38,8 @@ impl Request for SendChatAction<'_> {
impl SendChatAction<'_> {
pub async fn send(self) -> ResponseResult<True> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"sendChatAction",
&self,
)
@ -47,17 +48,13 @@ impl SendChatAction<'_> {
}
impl<'a> SendChatAction<'a> {
pub(crate) fn new<Cid, Ca>(
ctx: RequestContext<'a>,
chat_id: Cid,
action: Ca,
) -> Self
pub(crate) fn new<Cid, Ca>(bot: &'a Bot, chat_id: Cid, action: Ca,) -> Self
where
Cid: Into<ChatId>,
Ca: Into<ChatAction>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
action: action.into(),
}

View file

@ -2,16 +2,17 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, Message, ReplyMarkup},
};
use crate::bot::Bot;
/// Use this method to send phone contacts.
/// returned.
#[derive(Debug, Clone, Serialize)]
pub struct SendContact<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Unique identifier for the target chat or
/// username of the target channel (in the format @channelusername)
pub chat_id: ChatId,
@ -54,8 +55,8 @@ impl Request for SendContact<'_> {
impl SendContact<'_> {
pub async fn send(self) -> ResponseResult<Message> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"sendContact",
&self,
)
@ -65,7 +66,7 @@ impl SendContact<'_> {
impl<'a> SendContact<'a> {
pub(crate) fn new<C, P, F>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
phone_number: P,
first_name: F,
@ -76,7 +77,7 @@ impl<'a> SendContact<'a> {
F: Into<String>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
phone_number: phone_number.into(),
first_name: first_name.into(),

View file

@ -2,9 +2,10 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, Message, ParseMode, ReplyMarkup},
};
use crate::bot::Bot;
// TODO: add method to bot/api
@ -14,7 +15,7 @@ use crate::{
#[derive(Debug, Clone, Serialize)]
pub struct SendDocument<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target
/// channel (in the format @channelusername)
pub chat_id: ChatId,
@ -69,8 +70,8 @@ impl Request for SendDocument<'_> {
impl SendDocument<'_> {
pub async fn send(self) -> ResponseResult<Message> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"sendDocument",
&self,
)
@ -80,7 +81,7 @@ impl SendDocument<'_> {
impl<'a> SendDocument<'a> {
pub(crate) fn new<C, D>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
document: D,
) -> Self
@ -89,7 +90,7 @@ impl<'a> SendDocument<'a> {
D: Into<String>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
document: document.into(),
thumb: None,

View file

@ -4,16 +4,17 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, Message, ReplyMarkup},
};
use crate::bot::Bot;
#[derive(Debug, Clone, Serialize)]
/// Use this method to send point on the map. On success, the sent [`Message`]
/// is returned.
pub struct SendLocation<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
@ -50,8 +51,8 @@ impl Request for SendLocation<'_> {
impl SendLocation<'_> {
pub async fn send(self) -> ResponseResult<Message> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"sendLocation",
&self,
)
@ -61,7 +62,7 @@ impl SendLocation<'_> {
impl<'a> SendLocation<'a> {
pub(crate) fn new<Lt, Lg, C>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
latitude: Lt,
longitude: Lg,
@ -72,7 +73,7 @@ impl<'a> SendLocation<'a> {
C: Into<ChatId>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
latitude: latitude.into(),
longitude: longitude.into(),

View file

@ -3,15 +3,16 @@ use async_trait::async_trait;
use crate::{
network::request_multipart,
requests::{
form_builder::FormBuilder, Request, RequestContext, ResponseResult,
form_builder::FormBuilder, Request, ResponseResult,
},
types::{ChatId, InputMedia, Message, InputFile},
};
use crate::bot::Bot;
/// Use this method to send a group of photos or videos as an album.
#[derive(Debug, Clone)]
pub struct SendMediaGroup<'a> {
ctx: RequestContext<'a>,
bot: &'a Bot,
pub chat_id: ChatId,
pub media: Vec<InputMedia>,
@ -46,8 +47,8 @@ impl SendMediaGroup<'_> {
);
request_multipart(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"sendMediaGroup",
form.build(),
)
@ -57,7 +58,7 @@ impl SendMediaGroup<'_> {
impl<'a> SendMediaGroup<'a> {
pub(crate) fn new<C, M>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
media: M,
) -> Self
@ -66,7 +67,7 @@ impl<'a> SendMediaGroup<'a> {
M: Into<Vec<InputMedia>>,
{
SendMediaGroup {
ctx,
bot,
chat_id: chat_id.into(),
media: media.into(),
disable_notification: None,

View file

@ -2,16 +2,17 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, Message, ParseMode, ReplyMarkup},
};
use crate::bot::Bot;
#[derive(Debug, Clone, Serialize)]
/// Use this method to send text messages. On success, the sent [`Message`] is
/// returned.
pub struct SendMessage<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
@ -55,8 +56,8 @@ impl Request for SendMessage<'_> {
impl SendMessage<'_> {
pub async fn send(self) -> ResponseResult<Message> {
network::request_json(
self.ctx.client,
self.ctx.token,
self.bot.client(),
self.bot.token(),
"sendMessage",
&self,
)
@ -65,17 +66,13 @@ impl SendMessage<'_> {
}
impl<'a> SendMessage<'a> {
pub(crate) fn new<C, S>(
ctx: RequestContext<'a>,
chat_id: C,
text: S,
) -> Self
pub(crate) fn new<C, S>(bot: &'a Bot, chat_id: C, text: S,) -> Self
where
C: Into<ChatId>,
S: Into<String>,
{
SendMessage {
ctx,
bot,
chat_id: chat_id.into(),
text: text.into(),
parse_mode: None,

View file

@ -3,16 +3,17 @@ use async_trait::async_trait;
use crate::{
network,
requests::{
form_builder::FormBuilder, Request, RequestContext, ResponseResult,
form_builder::FormBuilder, Request, ResponseResult,
},
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
};
use crate::bot::Bot;
#[derive(Debug, Clone)]
/// Use this method to send photos. On success, the sent [`Message`] is
/// returned.
pub struct SendPhoto<'a> {
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
@ -64,8 +65,8 @@ impl SendPhoto<'_> {
.add("photo", self.photo);
network::request_multipart(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"sendPhoto",
params.build(),
)
@ -75,7 +76,7 @@ impl SendPhoto<'_> {
impl<'a> SendPhoto<'a> {
pub(crate) fn new<C, P>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
photo: P,
) -> Self
@ -84,7 +85,7 @@ impl<'a> SendPhoto<'a> {
P: Into<InputFile>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
photo: photo.into(),
caption: None,

View file

@ -2,16 +2,17 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, Message, ReplyMarkup},
};
use crate::bot::Bot;
/// Use this method to send a native poll. A native poll can't be sent to a
/// private chat. On success, the sent Message is returned.
#[derive(Debug, Clone, Serialize)]
pub struct SendPoll<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// 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.
@ -44,8 +45,8 @@ impl Request for SendPoll<'_> {
impl SendPoll<'_> {
pub async fn send(self) -> ResponseResult<Message> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"sendPoll",
&self,
)
@ -55,7 +56,7 @@ impl SendPoll<'_> {
impl<'a> SendPoll<'a> {
pub(crate) fn new<C, Q, O>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
question: Q,
options: O,
@ -66,7 +67,7 @@ impl<'a> SendPoll<'a> {
O: Into<Vec<String>>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
question: question.into(),
options: options.into(),

View file

@ -2,16 +2,17 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, Message, ReplyMarkup},
};
use crate::bot::Bot;
/// Use this method to send information about a venue.
/// Message is returned.
#[derive(Debug, Clone, Serialize)]
pub struct SendVenue<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Unique identifier for the target chat or
/// username of the target channel (in the format @channelusername)
pub chat_id: ChatId,
@ -59,8 +60,8 @@ impl Request for SendVenue<'_> {
impl SendVenue<'_> {
pub async fn send(self) -> ResponseResult<Message> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"sendVenue",
&self,
)
@ -70,7 +71,7 @@ impl SendVenue<'_> {
impl<'a> SendVenue<'a> {
pub(crate) fn new<Lt, Lg, C, T, A>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
latitude: Lt,
longitude: Lg,
@ -85,7 +86,7 @@ impl<'a> SendVenue<'a> {
A: Into<String>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
latitude: latitude.into(),
longitude: longitude.into(),

View file

@ -1,8 +1,9 @@
use async_trait::async_trait;
use crate::network;
use crate::requests::{Request, RequestContext, ResponseResult};
use crate::requests::{Request, ResponseResult};
use crate::types::{ChatId, Message, ParseMode, ReplyMarkup};
use crate::bot::Bot;
//TODO: add action to bot api
///Use this method to send video files, Telegram clients support mp4 videos
@ -12,7 +13,7 @@ use crate::types::{ChatId, Message, ParseMode, ReplyMarkup};
#[derive(Debug, Clone, Serialize)]
pub struct SendVideo<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
///Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
pub chat_id: ChatId,
@ -78,8 +79,8 @@ impl Request for SendVideo<'_> {
impl SendVideo<'_> {
async fn send(self) -> ResponseResult<Message> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"sendVideo",
&self,
)
@ -89,7 +90,7 @@ impl SendVideo<'_> {
impl<'a> SendVideo<'a> {
pub(crate) fn new<C, V>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
video: V,
) -> Self
@ -98,7 +99,7 @@ impl<'a> SendVideo<'a> {
V: Into<String>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
video: video.into(),
duration: None,

View file

@ -2,9 +2,10 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, Message, ReplyMarkup},
};
use crate::bot::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. On success, the sent
@ -12,7 +13,7 @@ use crate::{
#[derive(Debug, Clone, Serialize)]
pub struct SendVideoNote<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
///Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
pub chat_id: ChatId,
@ -65,8 +66,8 @@ impl Request for SendVideoNote<'_> {
impl SendVideoNote<'_> {
pub async fn send(self) -> ResponseResult<Message> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"sendVideoNote",
&self,
)
@ -76,7 +77,7 @@ impl SendVideoNote<'_> {
impl<'a> SendVideoNote<'a> {
pub(crate) fn new<C, V>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
video_note: V,
) -> Self
@ -85,7 +86,7 @@ impl<'a> SendVideoNote<'a> {
V: Into<String>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
video_note: video_note.into(),
duration: None,

View file

@ -2,9 +2,10 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, Message, ParseMode, ReplyMarkup},
};
use crate::bot::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
@ -15,7 +16,7 @@ use crate::{
#[derive(Debug, Clone, Serialize)]
pub struct SendVoice<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
pub chat_id: ChatId,
@ -62,8 +63,8 @@ impl Request for SendVoice<'_> {
impl SendVoice<'_> {
pub async fn send(self) -> ResponseResult<Message> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"sendVoice",
&self,
)
@ -73,7 +74,7 @@ impl SendVoice<'_> {
impl<'a> SendVoice<'a> {
pub(crate) fn new<C, V>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
voice: V,
) -> Self
@ -82,7 +83,7 @@ impl<'a> SendVoice<'a> {
V: Into<String>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
voice: voice.into(),
caption: None,

View file

@ -2,9 +2,10 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, InlineKeyboardMarkup, Message},
};
use crate::bot::Bot;
/// Use this method to stop updating a live location message before live_period
/// expires. On success, if the message was sent by the bot, the sent Message is
@ -12,7 +13,7 @@ use crate::{
#[derive(Debug, Clone, Serialize)]
pub struct StopMessageLiveLocation<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
/// Required if inline_message_id is not specified. Unique identifier for
/// the target chat or username of the target channel (in the format
/// @channelusername)
@ -44,8 +45,8 @@ impl Request for StopMessageLiveLocation<'_> {
impl StopMessageLiveLocation<'_> {
pub async fn send(self) -> ResponseResult<Message> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"stopMessageLiveLocation",
&self,
)
@ -54,9 +55,9 @@ impl StopMessageLiveLocation<'_> {
}
impl<'a> StopMessageLiveLocation<'a> {
pub(crate) fn new(ctx: RequestContext<'a>) -> Self {
pub(crate) fn new(bot: &'a Bot) -> Self {
Self {
ctx,
bot,
chat_id: None,
message_id: None,
inline_message_id: None,

View file

@ -2,9 +2,10 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::ChatId,
};
use crate::bot::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
@ -13,7 +14,7 @@ use crate::{
#[derive(Debug, Clone, Serialize)]
pub struct UnbanChatMember<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
bot: &'a Bot,
///Unique identifier for the target group or username of the target
/// supergroup or channel (in the format @channelusername)
pub chat_id: ChatId,
@ -33,8 +34,8 @@ impl Request for UnbanChatMember<'_> {
impl UnbanChatMember<'_> {
pub async fn send(self) -> ResponseResult<bool> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"unbanChatMember",
&self,
)
@ -44,7 +45,7 @@ impl UnbanChatMember<'_> {
impl<'a> UnbanChatMember<'a> {
pub(crate) fn new<C, U>(
ctx: RequestContext<'a>,
bot: &'a Bot,
chat_id: C,
user_id: U,
) -> Self
@ -53,7 +54,7 @@ impl<'a> UnbanChatMember<'a> {
U: Into<i32>,
{
Self {
ctx,
bot,
chat_id: chat_id.into(),
user_id: user_id.into(),
}

View file

@ -2,14 +2,15 @@ use async_trait::async_trait;
use crate::{
network,
requests::{Request, RequestContext, ResponseResult},
requests::{Request, ResponseResult},
types::{ChatId, True},
};
use crate::bot::Bot;
#[derive(Debug, Clone, Serialize)]
pub struct UnpinChatMessage<'a> {
#[serde(skip_serializing)]
pub ctx: RequestContext<'a>,
pub bot: &'a Bot,
pub chat_id: ChatId,
}
@ -26,8 +27,8 @@ impl Request for UnpinChatMessage<'_> {
impl UnpinChatMessage<'_> {
pub async fn send(self) -> ResponseResult<True> {
network::request_json(
&self.ctx.client,
&self.ctx.token,
self.bot.client(),
self.bot.token(),
"unpinChatMessage",
&self,
)
@ -36,12 +37,12 @@ impl UnpinChatMessage<'_> {
}
impl<'a> UnpinChatMessage<'a> {
pub(crate) fn new<C>(ctx: RequestContext<'a>, value: C) -> Self
pub(crate) fn new<C>(bot: &'a Bot, value: C) -> Self
where
C: Into<ChatId>,
{
Self {
ctx,
bot,
chat_id: value.into(),
}
}