mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
commit
c2677929f1
168 changed files with 7483 additions and 5104 deletions
|
@ -17,6 +17,7 @@ pin-project = "0.4.0-alpha.7"
|
|||
futures-preview = "0.3.0-alpha.19"
|
||||
async-trait = "0.1.13"
|
||||
thiserror = "1.0.2"
|
||||
serde_with_macros = "1.0.1"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
|
1265
src/bot/api.rs
1265
src/bot/api.rs
File diff suppressed because it is too large
Load diff
105
src/bot/execute.rs
Normal file
105
src/bot/execute.rs
Normal file
|
@ -0,0 +1,105 @@
|
|||
use serde::de::DeserializeOwned;
|
||||
|
||||
use crate::{
|
||||
network::{request_dynamic, request_json, request_multipart},
|
||||
requests::{dynamic, json, multipart, ResponseResult},
|
||||
Bot,
|
||||
};
|
||||
|
||||
impl Bot {
|
||||
/// Execute dyn-request
|
||||
///
|
||||
/// ## Example
|
||||
/// ```no_run
|
||||
/// # use telebofr::{Bot, requests::payloads::SendMessage};
|
||||
/// # #[tokio::main] async fn main_() {
|
||||
/// let bot = Bot::new("TOKEN");
|
||||
/// let payload = SendMessage::new(123456, "text");
|
||||
/// bot.execute_dyn(&payload).await;
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// **NOTES**:
|
||||
/// 1. we recommend to use `bot.send_message(id, "text").send().await`
|
||||
/// instead
|
||||
/// 2. this is _dynamic_ version of execute, so it has a _little_ overhead,
|
||||
/// prefer using [`execute_json`] or [`execute_multipart`] depending on
|
||||
/// type of payload when possible.
|
||||
///
|
||||
/// [`execute_json`]: self::Bot::execute_json
|
||||
/// [`execute_multipart`]: self::Bot::execute_multipart
|
||||
pub async fn execute_dyn<O>(
|
||||
&self,
|
||||
payload: &dyn dynamic::Payload<Output = O>,
|
||||
) -> ResponseResult<O>
|
||||
where
|
||||
O: DeserializeOwned,
|
||||
{
|
||||
request_dynamic(
|
||||
self.client(),
|
||||
self.token(),
|
||||
payload.name(),
|
||||
payload.kind(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Execute json-request
|
||||
///
|
||||
/// ## Example
|
||||
/// ```no_run
|
||||
/// # use telebofr::{Bot, requests::payloads::SendMessage};
|
||||
/// # #[tokio::main] async fn main_() {
|
||||
/// let bot = Bot::new("TOKEN");
|
||||
/// let payload = SendMessage::new(123456, "text");
|
||||
/// bot.execute_json(&payload).await;
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// **NOTE**: we recommend to use
|
||||
/// `bot.send_message(id, "text").send().await` instead
|
||||
pub async fn execute_json<P>(
|
||||
&self,
|
||||
payload: &P,
|
||||
) -> ResponseResult<P::Output>
|
||||
where
|
||||
P: json::Payload,
|
||||
P::Output: DeserializeOwned,
|
||||
{
|
||||
request_json(self.client(), self.token(), P::NAME, payload).await
|
||||
}
|
||||
|
||||
/// Execute multipart-request
|
||||
///
|
||||
/// ## Example
|
||||
/// ```no_run
|
||||
/// # use telebofr::{Bot, requests::payloads::SendAnimation, types::InputFile};
|
||||
/// # #[tokio::main] async fn main_() {
|
||||
/// let bot = Bot::new("TOKEN");
|
||||
/// let payload = SendAnimation::new(
|
||||
/// 123456,
|
||||
/// InputFile::Url(String::from("https://example.com"))
|
||||
/// );
|
||||
/// bot.execute_multipart(&payload).await;
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// **NOTE**: we recommend to use
|
||||
/// `bot.send_animation(id, InputFile::...).send().await` instead
|
||||
pub async fn execute_multipart<P>(
|
||||
&self,
|
||||
payload: &P,
|
||||
) -> ResponseResult<P::Output>
|
||||
where
|
||||
P: multipart::Payload,
|
||||
P::Output: DeserializeOwned,
|
||||
{
|
||||
request_multipart(
|
||||
self.client(),
|
||||
self.token(),
|
||||
P::NAME,
|
||||
payload.payload(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ use reqwest::Client;
|
|||
|
||||
mod api;
|
||||
mod download;
|
||||
mod execute;
|
||||
|
||||
/// A Telegram bot used to build requests.
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
@ -41,7 +41,6 @@ type FiltersAndHandlers<'a, T, E> = Vec<FilterAndHandler<'a, T, E>>;
|
|||
/// - Error (`E` generic parameter) _must_ implement [`std::fmt::Debug`]
|
||||
/// - All 'handlers' are boxed
|
||||
/// - Handler's fututres are also boxed
|
||||
/// - [Custom error policy] is also boxed
|
||||
/// - All errors from [updater] are ignored (TODO: remove this limitation)
|
||||
/// - All handlers executed in order (this means that in dispatching have 2
|
||||
/// upadtes it will first execute some handler into complition with first
|
||||
|
@ -89,9 +88,7 @@ type FiltersAndHandlers<'a, T, E> = Vec<FilterAndHandler<'a, T, E>>;
|
|||
/// ```
|
||||
///
|
||||
/// [`std::fmt::Debug`]: std::fmt::Debug
|
||||
/// [Custom error policy]:
|
||||
/// crate::dispatching::filter::error_policy::ErrorPolicy::Custom [updater]:
|
||||
/// crate::dispatching::updater
|
||||
/// [updater]: crate::dispatching::updater
|
||||
pub struct FilterDispatcher<'a, E, Ep> {
|
||||
message_handlers: FiltersAndHandlers<'a, Message, E>,
|
||||
edited_message_handlers: FiltersAndHandlers<'a, Message, E>,
|
||||
|
|
|
@ -79,7 +79,7 @@ where
|
|||
/// assert_eq!(and(true, false).test(&()), false);
|
||||
/// ```
|
||||
///
|
||||
/// [`And::new`]: crate::dispatching::filter::And::new
|
||||
/// [`And::new`]: crate::dispatching::filters::And::new
|
||||
pub fn and<A, B>(a: A, b: B) -> And<A, B> {
|
||||
And::new(a, b)
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ where
|
|||
/// assert_eq!(or(false, false).test(&()), false);
|
||||
/// ```
|
||||
///
|
||||
/// [`Or::new`]: crate::dispatching::filter::Or::new
|
||||
/// [`Or::new`]: crate::dispatching::filters::Or::new
|
||||
pub fn or<A, B>(a: A, b: B) -> Or<A, B> {
|
||||
Or::new(a, b)
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ where
|
|||
/// assert_eq!(not(true).test(&()), false);
|
||||
/// ```
|
||||
///
|
||||
/// [`Not::new`]: crate::dispatching::filter::Not::new
|
||||
/// [`Not::new`]: crate::dispatching::filters::Not::new
|
||||
pub fn not<A>(a: A) -> Not<A> {
|
||||
Not::new(a)
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ pub fn not<A>(a: A) -> Not<A> {
|
|||
/// assert_eq!(all![false, false].test(&()), false);
|
||||
/// ```
|
||||
///
|
||||
/// [filter]: crate::dispatching::filter::Filter
|
||||
/// [filter]: crate::dispatching::filters::Filter
|
||||
#[macro_export]
|
||||
macro_rules! all {
|
||||
($one:expr) => { $one };
|
||||
|
@ -230,7 +230,7 @@ macro_rules! all {
|
|||
/// assert_eq!(any![false, false, false].test(&()), false);
|
||||
/// ```
|
||||
///
|
||||
/// [filter]: crate::dispatching::filter::Filter
|
||||
/// [filter]: crate::dispatching::filters::Filter
|
||||
#[macro_export]
|
||||
macro_rules! any {
|
||||
($one:expr) => { $one };
|
||||
|
@ -277,7 +277,7 @@ pub struct F<A>(A);
|
|||
|
||||
/// Constructor fn for [F]
|
||||
///
|
||||
/// [F]: crate::dispatching::filter::F;
|
||||
/// [F]: crate::dispatching::filters::F;
|
||||
pub fn f<A>(a: A) -> F<A> {
|
||||
F(a)
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ pub trait FilterExt<T> {
|
|||
/// assert_eq!(flt.test(&1), false);
|
||||
/// ```
|
||||
///
|
||||
/// [`Not::new`]: crate::dispatching::filter::Not::new
|
||||
/// [`Not::new`]: crate::dispatching::filters::Not::new
|
||||
fn not(self) -> Not<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
|
@ -344,7 +344,7 @@ pub trait FilterExt<T> {
|
|||
/// assert_eq!(flt.test(&43), false);
|
||||
/// ```
|
||||
///
|
||||
/// [`Not::new`]: crate::dispatching::filter::And::new
|
||||
/// [`Not::new`]: crate::dispatching::filters::And::new
|
||||
fn and<B>(self, other: B) -> And<Self, B>
|
||||
where
|
||||
Self: Sized,
|
||||
|
@ -366,7 +366,7 @@ pub trait FilterExt<T> {
|
|||
/// assert_eq!(flt.test(&17), false);
|
||||
/// ```
|
||||
///
|
||||
/// [`Not::new`]: crate::dispatching::filter::Or::new
|
||||
/// [`Not::new`]: crate::dispatching::filters::Or::new
|
||||
fn or<B>(self, other: B) -> Or<Self, B>
|
||||
where
|
||||
Self: Sized,
|
||||
|
|
|
@ -13,9 +13,9 @@ use crate::{dispatching::Filter, types::Message};
|
|||
/// If you want to compare text and caption use
|
||||
/// [MessageTextCaptionFilter]
|
||||
///
|
||||
/// [MessageTextFilter]: telebofr::dispatching::filters::MessageTextFilter
|
||||
/// [MessageTextFilter]: crate::dispatching::filters::MessageTextFilter
|
||||
/// [MessageTextCaptionFilter]:
|
||||
/// telebofr::dispatching::filters::MessageTextCaptionFilter
|
||||
/// crate::dispatching::filters::MessageTextCaptionFilter
|
||||
pub struct MessageCaptionFilter {
|
||||
text: String,
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@ use crate::{dispatching::Filter, types::Message};
|
|||
/// If you want to compare text and caption use
|
||||
/// [MessageTextCaptionFilter]
|
||||
///
|
||||
/// [MessageCaptionFilter]: telebofr::dispatching::filters::MessageCaptionFilter
|
||||
/// [MessageCaptionFilter]: crate::dispatching::filters::MessageCaptionFilter
|
||||
/// [MessageTextCaptionFilter]:
|
||||
/// telebofr::dispatching::filters::MessageTextCaptionFilter
|
||||
/// crate::dispatching::filters::MessageTextCaptionFilter
|
||||
pub struct MessageTextFilter {
|
||||
text: String,
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ use crate::{dispatching::Filter, types::Message};
|
|||
/// If you want to compare only text use
|
||||
/// [MessageTextFilter]
|
||||
///
|
||||
/// [MessageCaptionFilter]: telebofr::dispatching::filters::MessageCaptionFilter
|
||||
/// [MessageTextFilter]: telebofr::filter::filters::MessageTextFilter
|
||||
/// [MessageCaptionFilter]: crate::dispatching::filters::MessageCaptionFilter
|
||||
/// [MessageTextFilter]: crate::dispatching::filters::MessageTextFilter
|
||||
pub struct MessageTextCaptionFilter {
|
||||
text: String,
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ use std::{
|
|||
};
|
||||
|
||||
use futures::{stream, Stream, StreamExt};
|
||||
|
||||
use pin_project::pin_project;
|
||||
|
||||
use crate::{bot::Bot, types::Update, RequestError};
|
||||
|
@ -94,7 +93,7 @@ use crate::{bot::Bot, types::Update, RequestError};
|
|||
/// <a id="4" href="#4b">^4</a> `offset = N` means that we've already received
|
||||
/// updates `0..=N`
|
||||
///
|
||||
/// [GetUpdates]: crate::requests::GetUpdates
|
||||
/// [GetUpdates]: crate::requests::payloads::GetUpdates
|
||||
/// [getting updates]: https://core.telegram.org/bots/api#getting-updates
|
||||
/// [wiki]: https://en.wikipedia.org/wiki/Push_technology#Long_polling
|
||||
pub trait Updater:
|
||||
|
@ -139,7 +138,6 @@ where
|
|||
pub fn polling<'a>(bot: &'a Bot) -> impl Updater<Error = RequestError> + 'a {
|
||||
let stream = stream::unfold((bot, 0), |(bot, mut offset)| {
|
||||
async move {
|
||||
// this match converts Result<Vec<_>, _> -> Vec<Result<_, _>>
|
||||
let updates = match bot.get_updates().offset(offset).send().await {
|
||||
Ok(updates) => {
|
||||
if let Some(upd) = updates.last() {
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#![allow(clippy::unit_arg)] // TODO
|
||||
#![allow(clippy::ptr_arg)] // TODO
|
||||
|
||||
#[macro_use]
|
||||
extern crate derive_more;
|
||||
#[macro_use]
|
||||
|
|
|
@ -3,7 +3,7 @@ pub use download::download_file_stream;
|
|||
|
||||
pub use self::{
|
||||
download::download_file,
|
||||
request::{request_json, request_multipart, request_simple},
|
||||
request::{request_dynamic, request_json, request_multipart},
|
||||
telegram_response::TelegramResponse,
|
||||
};
|
||||
|
||||
|
|
|
@ -14,33 +14,14 @@ pub async fn request_multipart<T>(
|
|||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
process_response(
|
||||
client
|
||||
let response = client
|
||||
.post(&super::method_url(TELEGRAM_API_URL, token, method_name))
|
||||
.multipart(params)
|
||||
.send()
|
||||
.await
|
||||
.map_err(RequestError::NetworkError)?,
|
||||
)
|
||||
.await
|
||||
}
|
||||
.map_err(RequestError::NetworkError)?;
|
||||
|
||||
pub async fn request_simple<T>(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
method_name: &str,
|
||||
) -> ResponseResult<T>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
process_response(
|
||||
client
|
||||
.post(&super::method_url(TELEGRAM_API_URL, token, method_name))
|
||||
.send()
|
||||
.await
|
||||
.map_err(RequestError::NetworkError)?,
|
||||
)
|
||||
.await
|
||||
process_response(response).await
|
||||
}
|
||||
|
||||
pub async fn request_json<T, P>(
|
||||
|
@ -53,15 +34,52 @@ where
|
|||
T: DeserializeOwned,
|
||||
P: Serialize,
|
||||
{
|
||||
process_response(
|
||||
client
|
||||
let response = client
|
||||
.post(&super::method_url(TELEGRAM_API_URL, token, method_name))
|
||||
.json(params)
|
||||
.send()
|
||||
.await
|
||||
.map_err(RequestError::NetworkError)?,
|
||||
)
|
||||
.map_err(RequestError::NetworkError)?;
|
||||
|
||||
process_response(response).await
|
||||
}
|
||||
|
||||
pub async fn request_body<T>(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
method_name: &str,
|
||||
params: String,
|
||||
) -> ResponseResult<T>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let response = client
|
||||
.post(&super::method_url(TELEGRAM_API_URL, token, method_name))
|
||||
.body(params)
|
||||
.send()
|
||||
.await
|
||||
.map_err(RequestError::NetworkError)?;
|
||||
|
||||
process_response(response).await
|
||||
}
|
||||
|
||||
pub async fn request_dynamic<T>(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
method_name: &str,
|
||||
params: crate::requests::dynamic::Kind,
|
||||
) -> ResponseResult<T>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
use crate::requests::dynamic::Kind;
|
||||
|
||||
match params {
|
||||
Kind::Json(str) => request_body(client, token, method_name, str).await,
|
||||
Kind::Multipart(form) => {
|
||||
request_multipart(client, token, method_name, form).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn process_response<T>(response: Response) -> ResponseResult<T>
|
||||
|
|
|
@ -1,125 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::True,
|
||||
};
|
||||
|
||||
/// Use this method to send answers to callback queries sent from inline
|
||||
/// keyboards. The answer will be displayed to the user as a notification at the
|
||||
/// top of the chat screen or as an alert. On success, True is returned.
|
||||
///
|
||||
/// Alternatively, the user can be redirected to the specified Game URL. For
|
||||
/// this option to work, you must first create a game for your bot via
|
||||
/// @Botfather and accept the terms. Otherwise, you may use links like
|
||||
/// t.me/your_bot?start=XXXX that open your bot with a parameter.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct AnswerCallbackQuery<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the query to be answered.
|
||||
callback_query_id: String,
|
||||
|
||||
/// Text of the notification. If not specified, nothing will be shown to
|
||||
/// the user, 0-200 characters
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
text: Option<String>,
|
||||
|
||||
/// If true, an alert will be shown by the client instead of a notification
|
||||
/// at the top of the chat screen. Defaults to false.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
show_alert: Option<bool>,
|
||||
|
||||
/// URL that will be opened by the user's client. If you have created a
|
||||
/// Game and accepted the conditions via @Botfather, specify the URL that
|
||||
/// opens your game – note that this will only work if the query comes from
|
||||
/// a callback_game button.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
url: Option<String>,
|
||||
|
||||
/// The maximum amount of time in seconds that the result of the callback
|
||||
/// query may be cached client-side. Telegram apps will support caching
|
||||
/// starting in version 3.14. Defaults to 0.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
cache_time: Option<i32>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for AnswerCallbackQuery<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl AnswerCallbackQuery<'_> {
|
||||
pub async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"answerCallbackQuery",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AnswerCallbackQuery<'a> {
|
||||
pub(crate) fn new<S>(bot: &'a Bot, callback_query_id: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
callback_query_id: callback_query_id.into(),
|
||||
text: None,
|
||||
show_alert: None,
|
||||
url: None,
|
||||
cache_time: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn callback_query_id<S>(mut self, value: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.callback_query_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn text<S>(mut self, value: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.text = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn show_alert<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.show_alert = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn url<S>(mut self, value: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.url = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn cache_time<I>(mut self, value: I) -> Self
|
||||
where
|
||||
I: Into<i32>,
|
||||
{
|
||||
self.cache_time = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::True,
|
||||
};
|
||||
|
||||
#[derive(Debug, Serialize, Clone)]
|
||||
/// Once the user has confirmed their payment and shipping details, the Bot API
|
||||
/// sends the final confirmation in the form of an [`Update`] with the field
|
||||
/// pre_checkout_query. Use this method to respond to such pre-checkout queries.
|
||||
/// On success, True is returned. Note: The Bot API must receive an answer
|
||||
/// within 10 seconds after the pre-checkout query was sent.
|
||||
///
|
||||
/// [`Update`]: crate::types::Update
|
||||
pub struct AnswerPreCheckoutQuery<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the query to be answered
|
||||
pub pre_checkout_query_id: String,
|
||||
|
||||
/// Specify True if everything is alright (goods are available, etc.) and
|
||||
/// the bot is ready to proceed with the order. Use False if there are any
|
||||
/// problems.
|
||||
pub ok: bool,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Required if ok is False. Error message in human readable form that
|
||||
/// explains the reason for failure to proceed with the checkout (e.g.
|
||||
/// "Sorry, somebody just bought the last of our amazing black T-shirts
|
||||
/// while you were busy filling out your payment details. Please choose a
|
||||
/// different color or garment!"). Telegram will display this message to
|
||||
/// the user.
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for AnswerPreCheckoutQuery<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl AnswerPreCheckoutQuery<'_> {
|
||||
pub async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"answerPreCheckoutQuery",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AnswerPreCheckoutQuery<'a> {
|
||||
pub(crate) fn new<S, B>(
|
||||
bot: &'a Bot,
|
||||
pre_checkout_query_id: S,
|
||||
ok: B,
|
||||
) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
B: Into<bool>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
pre_checkout_query_id: pre_checkout_query_id.into(),
|
||||
ok: ok.into(),
|
||||
error_message: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pre_checkout_query_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.pre_checkout_query_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ok<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.ok = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn error_message<S>(mut self, value: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.error_message = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ShippingOption, True},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
/// If you sent an invoice requesting a shipping address and the parameter
|
||||
/// is_flexible was specified, the Bot API will send an [`Update`] with a
|
||||
/// shipping_query field to the bot. Use this method to reply to shipping
|
||||
/// queries. On success, True is returned.
|
||||
///
|
||||
/// [`Update`]: crate::types::Update
|
||||
pub struct AnswerShippingQuery<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the query to be answered
|
||||
pub shipping_query_id: String,
|
||||
/// Specify True if delivery to the specified address is possible and False
|
||||
/// if there are any problems (for example, if delivery to the specified
|
||||
/// address is not possible)
|
||||
pub ok: bool,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Required if ok is True. A JSON-serialized array of available shipping
|
||||
/// options.
|
||||
pub shipping_options: Option<Vec<ShippingOption>>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Required if ok is False. Error message in human readable form that
|
||||
/// explains why it is impossible to complete the order (e.g. "Sorry,
|
||||
/// delivery to your desired address is unavailable'). Telegram will
|
||||
/// display this message to the user.
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for AnswerShippingQuery<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl AnswerShippingQuery<'_> {
|
||||
pub async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"answerShippingQuery",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AnswerShippingQuery<'a> {
|
||||
pub(crate) fn new<S, B>(bot: &'a Bot, shipping_query_id: S, ok: B) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
B: Into<bool>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
shipping_query_id: shipping_query_id.into(),
|
||||
ok: ok.into(),
|
||||
shipping_options: None,
|
||||
error_message: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shipping_query_id<S>(mut self, value: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.shipping_query_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ok<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.ok = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn shipping_options<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<Vec<ShippingOption>>,
|
||||
{
|
||||
self.shipping_options = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn error_message<S>(mut self, value: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.error_message = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct DeleteChatPhoto<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for DeleteChatPhoto<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl DeleteChatPhoto<'_> {
|
||||
async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"deleteChatPhoto",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DeleteChatPhoto<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = chat_id.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn serialize() {
|
||||
let bot = Bot::new("token");
|
||||
let chat_id = 123;
|
||||
let method = DeleteChatPhoto::new(&bot, chat_id);
|
||||
|
||||
let expected = r#"{"chat_id":123}"#;
|
||||
let actual = serde_json::to_string::<DeleteChatPhoto>(&method).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
/// Use this method to delete a group sticker set from a supergroup. The bot
|
||||
/// must be an administrator in the chat for this to work and must have the
|
||||
/// appropriate admin rights. Use the field can_set_sticker_set optionally
|
||||
/// returned in getChat requests to check if the bot can use this method.
|
||||
/// Returns True on success.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct DeleteChatStickerSet<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target
|
||||
/// supergroup (in the format @supergroupusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for DeleteChatStickerSet<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl DeleteChatStickerSet<'_> {
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"deleteChatStickerSet",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DeleteChatStickerSet<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
}
|
55
src/requests/dynamic.rs
Normal file
55
src/requests/dynamic.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
use reqwest::multipart;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
use super::{DynMethod, ResponseResult};
|
||||
use crate::{network, Bot};
|
||||
|
||||
/// [`Payload`] kind. Used to determinate the way for sending request.
|
||||
pub enum Kind {
|
||||
Json(String),
|
||||
Multipart(multipart::Form),
|
||||
}
|
||||
|
||||
pub trait Payload: DynMethod {
|
||||
fn kind(&self) -> Kind;
|
||||
}
|
||||
|
||||
/// Dynamic ready-to-send telegram request.
|
||||
///
|
||||
/// This type is useful for storing different requests in one place, however
|
||||
/// this type has _little_ overhead, so prefer using [json] or [multipart]
|
||||
/// requests when possible.
|
||||
///
|
||||
/// See [GetUpdates], [SendMessage] and [SendAnimation] for reference
|
||||
/// implementations.
|
||||
///
|
||||
/// [json]: crate::requests::json::Request
|
||||
/// [multipart]: crate::requests::multipart::Request
|
||||
/// [GetUpdates]: crate::requests::payloads::GetUpdates
|
||||
/// [SendMessage]: crate::requests::payloads::SendMessage
|
||||
/// [SendAnimation]: crate::requests::payloads::SendAnimation
|
||||
#[must_use = "requests do nothing until sent"]
|
||||
pub struct Request<'b, O> {
|
||||
bot: &'b Bot,
|
||||
pub(crate) payload: &'b dyn Payload<Output = O>, // TODO: Box?
|
||||
}
|
||||
|
||||
impl<'b, O> Request<'b, O>
|
||||
where
|
||||
O: DeserializeOwned,
|
||||
{
|
||||
pub fn new(bot: &'b Bot, payload: &'b dyn Payload<Output = O>) -> Self {
|
||||
Self { bot, payload }
|
||||
}
|
||||
|
||||
/// Send request to telegram
|
||||
pub async fn send(&self) -> ResponseResult<O> {
|
||||
network::request_dynamic(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
self.payload.name(),
|
||||
self.payload.kind(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message, ReplyMarkup},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
/// Use this method to edit live location messages. A location can be edited
|
||||
/// until its live_period expires or editing is explicitly disabled by a
|
||||
/// call to [`StopMessageLiveLocation`]. On success, if the edited message
|
||||
/// was sent by the bot, the edited [`Message`] is returned, otherwise True
|
||||
/// is returned.
|
||||
///
|
||||
/// [`StopMessageLiveLocation`]: crate::requests::StopMessageLiveLocation
|
||||
/// [`Message`]: crate::types::Message
|
||||
pub struct EditMessageLiveLocation<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Required if inline_message_id is not specified. Unique identifier for
|
||||
/// the target chat or username of the target channel (in the format
|
||||
/// @channelusername)
|
||||
chat_id: Option<ChatId>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Required if inline_message_id is not specified. Identifier of the
|
||||
/// message to edit
|
||||
message_id: Option<i32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Required if chat_id and message_id are not specified. Identifier of
|
||||
/// the inline message
|
||||
inline_message_id: Option<String>,
|
||||
/// Latitude of new location
|
||||
latitude: f64,
|
||||
/// Longitude of new location
|
||||
longitude: f64,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// A JSON-serialized object for a new inline keyboard.
|
||||
reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for EditMessageLiveLocation<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageLiveLocation<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"editMessageLiveLocation",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> EditMessageLiveLocation<'a> {
|
||||
pub(crate) fn new<Lt, Lg>(bot: &'a Bot, latitude: Lt, longitude: Lg) -> Self
|
||||
where
|
||||
Lt: Into<f64>,
|
||||
Lg: Into<f64>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: None,
|
||||
message_id: None,
|
||||
inline_message_id: None,
|
||||
latitude: latitude.into(),
|
||||
longitude: longitude.into(),
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn inline_message_id<S>(mut self, value: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.inline_message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn latitude<Lt>(mut self, value: Lt) -> Self
|
||||
where
|
||||
Lt: Into<f64>,
|
||||
{
|
||||
self.latitude = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn longitude<Lg>(mut self, value: Lg) -> Self
|
||||
where
|
||||
Lg: Into<f64>,
|
||||
{
|
||||
self.longitude = value.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::ChatId,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct ExportCharInviteLink<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for ExportCharInviteLink<'_> {
|
||||
type Output = String;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl ExportCharInviteLink<'_> {
|
||||
async fn send(self) -> ResponseResult<String> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"exportChatInviteLink",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExportCharInviteLink<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = chat_id.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn serialize() {
|
||||
let bot = Bot::new("token");
|
||||
let chat_id = 123;
|
||||
let method = ExportCharInviteLink::new(&bot, chat_id);
|
||||
|
||||
let expected = r#"{"chat_id":123}"#;
|
||||
let actual =
|
||||
serde_json::to_string::<ExportCharInviteLink>(&method).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
|
@ -4,7 +4,10 @@ use reqwest::multipart::Form;
|
|||
|
||||
use crate::{
|
||||
requests::utils::file_to_part,
|
||||
types::{ChatId, InputFile, InputMedia, ParseMode},
|
||||
types::{
|
||||
ChatId, InlineKeyboardMarkup, InputFile, InputMedia, MaskPosition,
|
||||
ParseMode, ReplyMarkup,
|
||||
},
|
||||
};
|
||||
|
||||
/// This is a convenient struct that builds `reqwest::multipart::Form`
|
||||
|
@ -19,7 +22,7 @@ impl FormBuilder {
|
|||
}
|
||||
|
||||
/// Add the supplied key-value pair to this `FormBuilder`.
|
||||
pub fn add<'a, T, N>(self, name: N, value: T) -> Self
|
||||
pub fn add<'a, T, N>(self, name: N, value: &T) -> Self
|
||||
where
|
||||
N: Into<Cow<'a, str>>,
|
||||
T: IntoFormValue,
|
||||
|
@ -57,15 +60,15 @@ pub(crate) enum FormValue {
|
|||
}
|
||||
|
||||
pub(crate) trait IntoFormValue {
|
||||
fn into_form_value(self) -> Option<FormValue>;
|
||||
fn into_form_value(&self) -> Option<FormValue>;
|
||||
}
|
||||
|
||||
macro_rules! impl_for_struct {
|
||||
($($name:ty),*) => {
|
||||
$(
|
||||
impl IntoFormValue for $name {
|
||||
fn into_form_value(self) -> Option<FormValue> {
|
||||
let json = serde_json::to_string(&self)
|
||||
fn into_form_value(&self) -> Option<FormValue> {
|
||||
let json = serde_json::to_string(self)
|
||||
.expect("serde_json::to_string failed");
|
||||
Some(FormValue::Str(json))
|
||||
}
|
||||
|
@ -74,33 +77,51 @@ macro_rules! impl_for_struct {
|
|||
};
|
||||
}
|
||||
|
||||
impl_for_struct!(bool, i32, i64);
|
||||
impl_for_struct!(
|
||||
bool,
|
||||
i32,
|
||||
i64,
|
||||
u32,
|
||||
ReplyMarkup,
|
||||
InlineKeyboardMarkup,
|
||||
MaskPosition
|
||||
);
|
||||
|
||||
impl<T> IntoFormValue for Option<T>
|
||||
where
|
||||
T: IntoFormValue,
|
||||
{
|
||||
fn into_form_value(self) -> Option<FormValue> {
|
||||
self.and_then(IntoFormValue::into_form_value)
|
||||
fn into_form_value(&self) -> Option<FormValue> {
|
||||
self.as_ref().and_then(IntoFormValue::into_form_value)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoFormValue for &[InputMedia] {
|
||||
fn into_form_value(self) -> Option<FormValue> {
|
||||
// TODO: fix InputMedia implementation of IntoFormValue (for now it doesn't
|
||||
// encode files :|)
|
||||
impl IntoFormValue for Vec<InputMedia> {
|
||||
fn into_form_value(&self) -> Option<FormValue> {
|
||||
let json =
|
||||
serde_json::to_string(self).expect("serde_json::to_string failed");
|
||||
Some(FormValue::Str(json))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoFormValue for &str {
|
||||
fn into_form_value(self) -> Option<FormValue> {
|
||||
impl IntoFormValue for InputMedia {
|
||||
fn into_form_value(&self) -> Option<FormValue> {
|
||||
let json =
|
||||
serde_json::to_string(self).expect("serde_json::to_string failed");
|
||||
Some(FormValue::Str(json))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoFormValue for str {
|
||||
fn into_form_value(&self) -> Option<FormValue> {
|
||||
Some(FormValue::Str(self.to_owned()))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoFormValue for ParseMode {
|
||||
fn into_form_value(self) -> Option<FormValue> {
|
||||
fn into_form_value(&self) -> Option<FormValue> {
|
||||
let string = match self {
|
||||
ParseMode::HTML => String::from("HTML"),
|
||||
ParseMode::Markdown => String::from("Markdown"),
|
||||
|
@ -110,27 +131,27 @@ impl IntoFormValue for ParseMode {
|
|||
}
|
||||
|
||||
impl IntoFormValue for ChatId {
|
||||
fn into_form_value(self) -> Option<FormValue> {
|
||||
fn into_form_value(&self) -> Option<FormValue> {
|
||||
let string = match self {
|
||||
ChatId::Id(id) => id.to_string(),
|
||||
ChatId::ChannelUsername(username) => username,
|
||||
ChatId::ChannelUsername(username) => username.clone(),
|
||||
};
|
||||
Some(FormValue::Str(string))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoFormValue for String {
|
||||
fn into_form_value(self) -> Option<FormValue> {
|
||||
Some(FormValue::Str(self))
|
||||
fn into_form_value(&self) -> Option<FormValue> {
|
||||
Some(FormValue::Str(self.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoFormValue for InputFile {
|
||||
fn into_form_value(self) -> Option<FormValue> {
|
||||
fn into_form_value(&self) -> Option<FormValue> {
|
||||
match self {
|
||||
InputFile::File(path) => Some(FormValue::File(path)),
|
||||
InputFile::Url(url) => Some(FormValue::Str(url)),
|
||||
InputFile::FileId(file_id) => Some(FormValue::Str(file_id)),
|
||||
InputFile::File(path) => Some(FormValue::File(path.clone())),
|
||||
InputFile::Url(url) => Some(FormValue::Str(url.clone())),
|
||||
InputFile::FileId(file_id) => Some(FormValue::Str(file_id.clone())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message},
|
||||
};
|
||||
|
||||
#[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)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target channel
|
||||
/// (in the format @channelusername)
|
||||
pub chat_id: ChatId,
|
||||
/// Unique identifier for the target chat or username of the target channel
|
||||
/// (in the format @channelusername)
|
||||
pub from_chat_id: ChatId,
|
||||
/// Message identifier in the chat specified in from_chat_id
|
||||
pub message_id: i32,
|
||||
|
||||
/// Sends the message silently. Users will receive a notification with no
|
||||
/// sound.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub disable_notification: Option<bool>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for ForwardMessage<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl ForwardMessage<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"forwardMessage",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ForwardMessage<'a> {
|
||||
pub(crate) fn new<C, Fc, M>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
from_chat_id: Fc,
|
||||
message_id: M,
|
||||
) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
Fc: Into<ChatId>,
|
||||
M: Into<i32>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
from_chat_id: from_chat_id.into(),
|
||||
message_id: message_id.into(),
|
||||
disable_notification: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
pub fn from_chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.from_chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id<M>(mut self, value: M) -> Self
|
||||
where
|
||||
M: Into<i32>,
|
||||
{
|
||||
self.message_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{Chat, ChatId},
|
||||
};
|
||||
|
||||
/// Use this method to get up to date information about the chat
|
||||
/// (current name of the user for one-on-one conversations,
|
||||
/// current username of a user, group or channel, etc.).
|
||||
/// Returns a Chat object on success.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetChat<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
/// Unique identifier for the target chat or username
|
||||
/// of the target supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetChat<'_> {
|
||||
type Output = Chat;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChat<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Chat> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getChat",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetChat<'a> {
|
||||
pub(crate) fn new<F>(bot: &'a Bot, chat_id: F) -> Self
|
||||
where
|
||||
F: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = chat_id.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, ChatMember},
|
||||
};
|
||||
|
||||
/// Use this method to get a list of administrators in a chat. On success,
|
||||
/// returns an Array of ChatMember objects that contains information about all
|
||||
/// chat administrators except other bots. If the chat is a group or a
|
||||
/// supergroup and no administrators were appointed, only the creator will be
|
||||
/// returned
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetChatAdministrators<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target
|
||||
/// supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetChatAdministrators<'_> {
|
||||
type Output = Vec<ChatMember>;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChatAdministrators<'_> {
|
||||
async fn send(&self) -> ResponseResult<Vec<ChatMember>> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getChatAdministrators",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetChatAdministrators<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, ChatMember},
|
||||
};
|
||||
|
||||
/// Use this method to get information about a member of a chat. Returns a
|
||||
/// ChatMember object on success.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetChatMember<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target
|
||||
/// supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
|
||||
/// Unique identifier of the target user
|
||||
user_id: i32,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetChatMember<'_> {
|
||||
type Output = ChatMember;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChatMember<'_> {
|
||||
async fn send(&self) -> ResponseResult<ChatMember> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getChatMember",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetChatMember<'a> {
|
||||
pub(crate) fn new<C, I>(bot: &'a Bot, chat_id: C, user_id: I) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
I: Into<i32>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
user_id: user_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id<I>(mut self, value: I) -> Self
|
||||
where
|
||||
I: Into<i32>,
|
||||
{
|
||||
self.user_id = value.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{Chat, ChatId},
|
||||
};
|
||||
|
||||
/// Use this method to get the number of members in a chat. Returns Int on
|
||||
/// success.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetChatMembersCount<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username
|
||||
/// of the target supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetChatMembersCount<'_> {
|
||||
type Output = Chat;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChatMembersCount<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Chat> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getChatMembersCount",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetChatMembersCount<'a> {
|
||||
pub fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::File,
|
||||
};
|
||||
|
||||
/// 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.
|
||||
/// On success, a File object is returned.
|
||||
/// The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>,
|
||||
/// where <file_path> is taken from the response.
|
||||
/// It is guaranteed that the link will be valid for at least 1 hour.
|
||||
/// When the link expires, a new one can be requested by calling getFile again.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetFile<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
/// File identifier to get info about
|
||||
pub file_id: String,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetFile<'_> {
|
||||
type Output = File;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetFile<'_> {
|
||||
pub async fn send(self) -> ResponseResult<File> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getFile",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetFile<'a> {
|
||||
pub(crate) fn new<F>(bot: &'a Bot, value: F) -> Self
|
||||
where
|
||||
F: Into<String>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
file_id: value.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn file_id<F>(mut self, value: F) -> Self
|
||||
where
|
||||
F: Into<String>,
|
||||
{
|
||||
self.file_id = value.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::User,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
/// A filter 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> {
|
||||
bot: &'a Bot,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetMe<'_> {
|
||||
type Output = User;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetMe<'_> {
|
||||
pub async fn send(self) -> ResponseResult<User> {
|
||||
network::request_simple(self.bot.client(), self.bot.token(), "getMe")
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetMe<'a> {
|
||||
pub(crate) fn new(bot: &'a Bot) -> Self {
|
||||
GetMe { bot }
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::Update,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetUpdates<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
pub offset: Option<i32>,
|
||||
pub limit: Option<u8>,
|
||||
pub timeout: Option<u32>,
|
||||
pub allowed_updates: Option<Vec<AllowedUpdate>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Eq, Hash, PartialEq, Clone, Copy)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum AllowedUpdate {
|
||||
Message,
|
||||
EditedMessage,
|
||||
ChannelPost,
|
||||
EditedChannelPost,
|
||||
InlineQuery,
|
||||
ChosenInlineResult,
|
||||
CallbackQuery,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetUpdates<'_> {
|
||||
type Output = Vec<Update>;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetUpdates<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Vec<Update>> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getUpdates",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetUpdates<'a> {
|
||||
pub(crate) fn new(bot: &'a Bot) -> Self {
|
||||
Self {
|
||||
bot,
|
||||
offset: None,
|
||||
limit: None,
|
||||
timeout: None,
|
||||
allowed_updates: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn offset<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.offset = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn limit<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<u8>,
|
||||
{
|
||||
self.limit = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn timeout<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<u32>,
|
||||
{
|
||||
self.timeout = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn allowed_updates<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<Vec<AllowedUpdate>>,
|
||||
{
|
||||
self.allowed_updates = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::UserProfilePhotos,
|
||||
};
|
||||
|
||||
///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)]
|
||||
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
|
||||
/// photos are returned.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub offset: Option<i64>,
|
||||
///Limits the number of photos to be retrieved. Values between 1—100 are
|
||||
/// accepted. Defaults to 100.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub limit: Option<i64>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetUserProfilePhotos<'_> {
|
||||
type Output = UserProfilePhotos;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetUserProfilePhotos<'_> {
|
||||
async fn send(self) -> ResponseResult<UserProfilePhotos> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getUserProfilePhotos",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetUserProfilePhotos<'a> {
|
||||
pub fn new<U>(bot: &'a Bot, user_id: U) -> Self
|
||||
where
|
||||
U: Into<i32>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
user_id: user_id.into(),
|
||||
offset: None,
|
||||
limit: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn user_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.user_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn offset<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i64>,
|
||||
{
|
||||
self.offset = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn limit<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i64>,
|
||||
{
|
||||
self.limit = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
42
src/requests/json.rs
Normal file
42
src/requests/json.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
use super::{Method, ResponseResult};
|
||||
use crate::{network, Bot};
|
||||
|
||||
pub trait Payload: Serialize + Method {}
|
||||
|
||||
/// Ready-to-send telegram request.
|
||||
///
|
||||
/// Note: params will be sent to telegram using [`application/json`]
|
||||
///
|
||||
/// See [GetUpdates] and [SendMessage] for reference implementations.
|
||||
///
|
||||
/// [`application/json`]: https://core.telegram.org/bots/api#making-requests
|
||||
/// [GetUpdates]: crate::requests::payloads::GetUpdates
|
||||
/// [SendMessage]: crate::requests::payloads::SendMessage
|
||||
#[must_use = "requests do nothing until sent"]
|
||||
pub struct Request<'b, P> {
|
||||
bot: &'b Bot,
|
||||
pub(crate) payload: P,
|
||||
}
|
||||
|
||||
impl<'b, P> Request<'b, P>
|
||||
where
|
||||
P: Payload,
|
||||
P::Output: DeserializeOwned,
|
||||
{
|
||||
pub fn new(bot: &'b Bot, payload: P) -> Self {
|
||||
Self { bot, payload }
|
||||
}
|
||||
|
||||
/// Send request to telegram
|
||||
pub async fn send(&self) -> ResponseResult<P::Output> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
P::NAME,
|
||||
&self.payload,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
/// 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
|
||||
/// the group on their own using invite links, etc., unless unbanned first. The
|
||||
/// bot must be an administrator in the chat for this to work and must have the
|
||||
/// appropriate admin rights. Returns True on success.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct KickChatMember<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
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,
|
||||
/// Unique identifier of the target user
|
||||
pub user_id: i32,
|
||||
///Date when the user will be unbanned, unix time. If user is banned for
|
||||
/// more than 366 days or less than 30 seconds from the current time they
|
||||
/// are considered to be banned forever
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub until_date: Option<u64>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for KickChatMember<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl KickChatMember<'_> {
|
||||
async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"kickChatMember",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> KickChatMember<'a> {
|
||||
pub(crate) fn new<C, U>(bot: &'a Bot, chat_id: C, user_id: U) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
U: Into<i32>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
user_id: user_id.into(),
|
||||
until_date: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id<U>(mut self, value: U) -> Self
|
||||
where
|
||||
U: Into<i32>,
|
||||
{
|
||||
self.user_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn until_date<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<u64>,
|
||||
{
|
||||
self.until_date = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::ChatId,
|
||||
};
|
||||
|
||||
/// Use this method for your bot to leave a group, supergroup or channel.
|
||||
/// Returns True on success.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct LeaveChat<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
/// Unique identifier for the target chat or username
|
||||
/// of the target supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for LeaveChat<'_> {
|
||||
type Output = bool;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl LeaveChat<'_> {
|
||||
pub async fn send(self) -> ResponseResult<bool> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"leaveChat",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> LeaveChat<'a> {
|
||||
pub(crate) fn new<F>(bot: &'a Bot, chat_id: F) -> Self
|
||||
where
|
||||
F: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
}
|
||||
}
|
||||
pub fn chat_id<C>(mut self, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = chat_id.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,108 +1,193 @@
|
|||
//! API requests.
|
||||
|
||||
pub use answer_callback_query::*;
|
||||
pub use answer_pre_checkout_query::*;
|
||||
pub use answer_shipping_query::*;
|
||||
pub use delete_chat_photo::*;
|
||||
pub use delete_chat_sticker_set::*;
|
||||
pub use edit_message_live_location::*;
|
||||
pub use export_chat_invite_link::*;
|
||||
pub use forward_message::*;
|
||||
pub use get_chat::*;
|
||||
pub use get_chat_administrators::*;
|
||||
pub use get_chat_member::*;
|
||||
pub use get_chat_members_count::*;
|
||||
pub use get_file::*;
|
||||
pub use get_me::*;
|
||||
pub use get_updates::*;
|
||||
pub use get_user_profile_photos::*;
|
||||
pub use kick_chat_member::*;
|
||||
pub use leave_chat::*;
|
||||
pub use pin_chat_message::*;
|
||||
pub use promote_chat_member::*;
|
||||
pub use restrict_chat_member::*;
|
||||
pub use send_animation::*;
|
||||
pub use send_audio::*;
|
||||
pub use send_chat_action::*;
|
||||
pub use send_contact::*;
|
||||
pub use send_document::*;
|
||||
pub use send_location::*;
|
||||
pub use send_media_group::*;
|
||||
pub use send_message::*;
|
||||
pub use send_photo::*;
|
||||
pub use send_poll::*;
|
||||
pub use send_venue::*;
|
||||
pub use send_video::*;
|
||||
pub use send_video_note::*;
|
||||
pub use send_voice::*;
|
||||
pub use set_chat_description::*;
|
||||
pub use set_chat_permissions::*;
|
||||
pub use set_chat_photo::*;
|
||||
pub use set_chat_sticker_set::*;
|
||||
pub use set_chat_title::*;
|
||||
pub use stop_message_live_location::*;
|
||||
pub use unban_chat_member::*;
|
||||
pub use unpin_chat_message::*;
|
||||
|
||||
mod form_builder;
|
||||
mod utils;
|
||||
|
||||
mod answer_callback_query;
|
||||
mod answer_pre_checkout_query;
|
||||
mod answer_shipping_query;
|
||||
mod delete_chat_photo;
|
||||
mod delete_chat_sticker_set;
|
||||
mod edit_message_live_location;
|
||||
mod export_chat_invite_link;
|
||||
mod forward_message;
|
||||
mod get_chat;
|
||||
mod get_chat_administrators;
|
||||
mod get_chat_member;
|
||||
mod get_chat_members_count;
|
||||
mod get_file;
|
||||
mod get_me;
|
||||
mod get_updates;
|
||||
mod get_user_profile_photos;
|
||||
mod kick_chat_member;
|
||||
mod leave_chat;
|
||||
mod pin_chat_message;
|
||||
mod promote_chat_member;
|
||||
mod restrict_chat_member;
|
||||
mod send_animation;
|
||||
mod send_audio;
|
||||
mod send_chat_action;
|
||||
mod send_contact;
|
||||
mod send_document;
|
||||
mod send_location;
|
||||
mod send_media_group;
|
||||
mod send_message;
|
||||
mod send_photo;
|
||||
mod send_poll;
|
||||
mod send_venue;
|
||||
mod send_video;
|
||||
mod send_video_note;
|
||||
mod send_voice;
|
||||
mod set_chat_description;
|
||||
mod set_chat_permissions;
|
||||
mod set_chat_photo;
|
||||
mod set_chat_sticker_set;
|
||||
mod set_chat_title;
|
||||
mod stop_message_live_location;
|
||||
mod unban_chat_member;
|
||||
mod unpin_chat_message;
|
||||
pub mod dynamic;
|
||||
pub mod json;
|
||||
pub mod multipart;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
/// A type that is returned from `Request::send_boxed`.
|
||||
/// A type that is returned when making requests to telegram
|
||||
pub type ResponseResult<T> = Result<T, crate::RequestError>;
|
||||
|
||||
/// A request that can be sent to Telegram.
|
||||
#[async_trait]
|
||||
pub trait Request {
|
||||
/// A type of response.
|
||||
type Output: DeserializeOwned;
|
||||
/// Signature of telegram method.
|
||||
pub trait Method {
|
||||
/// Return-type of the method.
|
||||
type Output;
|
||||
|
||||
/// Send this request.
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output>;
|
||||
/// Name of the method.
|
||||
const NAME: &'static str;
|
||||
}
|
||||
|
||||
/// Signature of telegram method.
|
||||
///
|
||||
/// Note: this trait is very similar to [`Method`] trait, however it can be used
|
||||
/// as trait object.
|
||||
pub trait DynMethod {
|
||||
type Output;
|
||||
|
||||
/// Return name of the method.
|
||||
fn name(&self) -> &str;
|
||||
}
|
||||
|
||||
impl<T> DynMethod for T
|
||||
where
|
||||
T: Method,
|
||||
{
|
||||
type Output = T::Output;
|
||||
|
||||
fn name(&self) -> &str {
|
||||
T::NAME
|
||||
}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub mod payloads {
|
||||
mod get_updates;
|
||||
mod set_webhook;
|
||||
mod delete_webhook;
|
||||
mod get_webhook_info;
|
||||
mod get_me;
|
||||
mod send_message;
|
||||
mod forward_message;
|
||||
mod send_photo;
|
||||
mod send_audio;
|
||||
mod send_document;
|
||||
mod send_video;
|
||||
mod send_animation;
|
||||
mod send_voice;
|
||||
mod send_video_note;
|
||||
mod send_media_group;
|
||||
mod send_location;
|
||||
mod edit_message_live_location_inline;
|
||||
mod edit_message_live_location;
|
||||
mod stop_message_live_location_inline;
|
||||
mod stop_message_live_location;
|
||||
mod send_venue;
|
||||
mod send_contact;
|
||||
mod send_poll;
|
||||
mod send_chat_action;
|
||||
mod get_user_profile_photos;
|
||||
mod get_file;
|
||||
mod kick_chat_member;
|
||||
mod unban_chat_member;
|
||||
mod restrict_chat_member;
|
||||
mod promote_chat_member;
|
||||
mod set_chat_permissions;
|
||||
mod export_chat_invite_link;
|
||||
mod set_chat_photo;
|
||||
mod delete_chat_photo;
|
||||
mod set_chat_title;
|
||||
mod set_chat_description;
|
||||
mod pin_chat_message;
|
||||
mod unpin_chat_message;
|
||||
mod leave_chat;
|
||||
mod get_chat;
|
||||
mod get_chat_administrators;
|
||||
mod get_chat_members_count;
|
||||
mod get_chat_member;
|
||||
mod set_chat_sticker_set;
|
||||
mod delete_chat_sticker_set;
|
||||
mod answer_callback_query;
|
||||
mod edit_message_text_inline;
|
||||
mod edit_message_text;
|
||||
mod edit_message_caption_inline;
|
||||
mod edit_message_caption;
|
||||
mod edit_message_media_inline;
|
||||
mod edit_message_media;
|
||||
mod edit_message_reply_markup_inline;
|
||||
mod edit_message_reply_markup;
|
||||
mod stop_poll;
|
||||
mod delete_message;
|
||||
mod send_sticker;
|
||||
mod get_sticker_set;
|
||||
mod upload_sticker_file;
|
||||
mod create_new_sticker_set;
|
||||
mod add_sticker_to_set;
|
||||
mod set_sticker_position_in_set;
|
||||
mod delete_sticker_from_set;
|
||||
mod answer_inline_query;
|
||||
mod send_invoice;
|
||||
mod answer_shipping_query;
|
||||
mod answer_pre_checkout_query;
|
||||
mod send_game;
|
||||
mod set_game_score_inline;
|
||||
mod set_game_score;
|
||||
mod get_game_high_scores;
|
||||
mod get_game_high_scores_inline;
|
||||
|
||||
pub use {
|
||||
get_updates::{GetUpdates, AllowedUpdate},
|
||||
set_webhook::SetWebhook,
|
||||
delete_webhook::DeleteWebhook,
|
||||
get_webhook_info::GetWebhookInfo,
|
||||
get_me::GetMe,
|
||||
send_message::SendMessage,
|
||||
forward_message::ForwardMessage,
|
||||
send_photo::SendPhoto,
|
||||
send_audio::SendAudio,
|
||||
send_document::SendDocument,
|
||||
send_video::SendVideo,
|
||||
send_animation::SendAnimation,
|
||||
send_voice::SendVoice,
|
||||
send_video_note::SendVideoNote,
|
||||
send_media_group::SendMediaGroup,
|
||||
send_location::SendLocation,
|
||||
edit_message_live_location_inline::EditMessageLiveLocationInline,
|
||||
edit_message_live_location::EditMessageLiveLocation,
|
||||
stop_message_live_location_inline::StopMessageLiveLocationInline,
|
||||
stop_message_live_location::StopMessageLiveLocation,
|
||||
send_venue::SendVenue,
|
||||
send_contact::SendContact,
|
||||
send_poll::SendPoll,
|
||||
send_chat_action::SendChatAction,
|
||||
get_user_profile_photos::GetUserProfilePhoto,
|
||||
get_file::GetFile,
|
||||
kick_chat_member::KickChatMember,
|
||||
unban_chat_member::UnbanChatMember,
|
||||
restrict_chat_member::RestrictChatMember,
|
||||
promote_chat_member::PromoteChatMember,
|
||||
set_chat_permissions::SetChatPermission,
|
||||
export_chat_invite_link::ExportChatInviteLink,
|
||||
set_chat_photo::SetChatPhoto,
|
||||
delete_chat_photo::DeleteChatPhoto,
|
||||
set_chat_title::SetChatTitle,
|
||||
set_chat_description::SetChatDescription,
|
||||
pin_chat_message::PinChatMessage,
|
||||
unpin_chat_message::UnpinChatMessage,
|
||||
leave_chat::LeaveChat,
|
||||
get_chat::GetChat,
|
||||
get_chat_administrators::GetChatAdministrator,
|
||||
get_chat_members_count::GetChatMembersCount,
|
||||
get_chat_member::GetChatMember,
|
||||
set_chat_sticker_set::SetChatStickerSet,
|
||||
delete_chat_sticker_set::DeleteChatStickerSet,
|
||||
answer_callback_query::AnswerCallbackQuery,
|
||||
edit_message_text_inline::EditMessageTextInline,
|
||||
edit_message_text::EditMessageText,
|
||||
edit_message_caption_inline::EditMessageCaptionInline,
|
||||
edit_message_caption::EditMessageCaption,
|
||||
edit_message_media_inline::EditMessageMediaInline,
|
||||
edit_message_media::EditMessageMedia,
|
||||
edit_message_reply_markup_inline::EditMessageReplyMarkupInline,
|
||||
edit_message_reply_markup::EditMessageReplyMarkup,
|
||||
stop_poll::StopPoll,
|
||||
delete_message::DeleteMessage,
|
||||
send_sticker::SendSticker,
|
||||
get_sticker_set::GetStickerSet,
|
||||
upload_sticker_file::UploadStickerFile,
|
||||
create_new_sticker_set::CreateNewStickerSet,
|
||||
add_sticker_to_set::AddStickerToSet,
|
||||
set_sticker_position_in_set::SetStickerPositionInSet,
|
||||
delete_sticker_from_set::DeleteStickerFromSet,
|
||||
answer_inline_query::AnswerInlineQuery,
|
||||
send_invoice::SendInvoice,
|
||||
answer_shipping_query::AnswerShippingQuery,
|
||||
answer_pre_checkout_query::AnswerPreCheckoutQuery,
|
||||
send_game::SendGame,
|
||||
set_game_score_inline::SetGameScoreInline,
|
||||
set_game_score::SetGameScore,
|
||||
get_game_high_scores_inline::GetGameHighScoreInline,
|
||||
get_game_high_scores::GetGameHighScore,
|
||||
};
|
||||
}
|
||||
|
|
44
src/requests/multipart.rs
Normal file
44
src/requests/multipart.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
use reqwest::multipart;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
use super::{Method, ResponseResult};
|
||||
use crate::{network, Bot};
|
||||
|
||||
pub trait Payload: Method {
|
||||
fn payload(&self) -> multipart::Form;
|
||||
}
|
||||
|
||||
/// Ready-to-send telegram request.
|
||||
///
|
||||
/// Note: params will be sent to telegram using [`multipart/form-data`]
|
||||
///
|
||||
/// See [SendAnimation] for reference implementation.
|
||||
///
|
||||
/// [`multipart/form-data`]: https://core.telegram.org/bots/api#making-requests
|
||||
/// [SendAnimation]: crate::requests::payloads::SendAnimation
|
||||
#[must_use = "requests do nothing until sent"]
|
||||
pub struct Request<'b, P> {
|
||||
bot: &'b Bot,
|
||||
pub(crate) payload: P,
|
||||
}
|
||||
|
||||
impl<'b, P> Request<'b, P>
|
||||
where
|
||||
P: Payload,
|
||||
P::Output: DeserializeOwned,
|
||||
{
|
||||
pub fn new(bot: &'b Bot, payload: P) -> Self {
|
||||
Self { bot, payload }
|
||||
}
|
||||
|
||||
/// Send request to telegram
|
||||
pub async fn send(&self) -> ResponseResult<P::Output> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
P::NAME,
|
||||
self.payload.payload(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
102
src/requests/payloads/add_sticker_to_set.rs
Normal file
102
src/requests/payloads/add_sticker_to_set.rs
Normal file
|
@ -0,0 +1,102 @@
|
|||
use reqwest::multipart::Form;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, multipart, Method, form_builder::FormBuilder},
|
||||
types::{MaskPosition, InputFile, True},
|
||||
};
|
||||
|
||||
/// Use this method to add a new sticker to a set created by the bot. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
pub struct AddStickerToSet {
|
||||
/// User identifier of sticker set owner
|
||||
user_id: i32,
|
||||
/// Sticker set name
|
||||
name: String,
|
||||
/// Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More info on Sending Files »
|
||||
png_sticker: InputFile,
|
||||
/// One or more emoji corresponding to the sticker
|
||||
emojis: String,
|
||||
/// A JSON-serialized object for position where the mask should be placed on faces
|
||||
mask_position: Option<MaskPosition>,
|
||||
}
|
||||
|
||||
impl Method for AddStickerToSet {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "addStickerToSet";
|
||||
}
|
||||
|
||||
impl multipart::Payload for AddStickerToSet {
|
||||
fn payload(&self) -> Form {
|
||||
FormBuilder::new()
|
||||
.add("user_id", &self.user_id)
|
||||
.add("name", &self.name)
|
||||
.add("png_sticker", &self.png_sticker)
|
||||
.add("emojis", &self.emojis)
|
||||
.add("mask_position", &self.mask_position)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
impl dynamic::Payload for AddStickerToSet {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Multipart(multipart::Payload::payload(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl AddStickerToSet {
|
||||
pub fn new<N, P, E>(user_id: i32, name: N, png_sticker: P, emojis: E) -> Self
|
||||
where
|
||||
N: Into<String>,
|
||||
P: Into<InputFile>,
|
||||
E: Into<String>
|
||||
{
|
||||
let name = name.into();
|
||||
let png_sticker = png_sticker.into();
|
||||
let emojis = emojis.into();
|
||||
Self {
|
||||
user_id,
|
||||
name,
|
||||
png_sticker,
|
||||
emojis,
|
||||
mask_position: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl multipart::Request<'_, AddStickerToSet> {
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.payload.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.name = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn png_sticker<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>
|
||||
{
|
||||
self.payload.png_sticker = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn emojis<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.emojis = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn mask_position(mut self, val: MaskPosition) -> Self {
|
||||
self.payload.mask_position = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
87
src/requests/payloads/answer_callback_query.rs
Normal file
87
src/requests/payloads/answer_callback_query.rs
Normal file
|
@ -0,0 +1,87 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::True,
|
||||
};
|
||||
|
||||
/// Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned.Alternatively, the user can be redirected to the specified Game URL. For this option to work, you must first create a game for your bot via @Botfather and accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct AnswerCallbackQuery {
|
||||
/// Unique identifier for the query to be answered
|
||||
callback_query_id: String,
|
||||
/// Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
|
||||
text: Option<String>,
|
||||
/// If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.
|
||||
show_alert: Option<bool>,
|
||||
/// URL that will be opened by the user's client. If you have created a Game and accepted the conditions via @Botfather, specify the URL that opens your game – note that this will only work if the query comes from a callback_game button.Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
|
||||
url: Option<String>,
|
||||
/// The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.
|
||||
cache_time: Option<i32>,
|
||||
}
|
||||
|
||||
impl Method for AnswerCallbackQuery {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "answerCallbackQuery";
|
||||
}
|
||||
|
||||
impl json::Payload for AnswerCallbackQuery {}
|
||||
|
||||
impl dynamic::Payload for AnswerCallbackQuery {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl AnswerCallbackQuery {
|
||||
pub fn new<C>(callback_query_id: C) -> Self
|
||||
where
|
||||
C: Into<String>
|
||||
{
|
||||
let callback_query_id = callback_query_id.into();
|
||||
Self {
|
||||
callback_query_id,
|
||||
text: None,
|
||||
show_alert: None,
|
||||
url: None,
|
||||
cache_time: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, AnswerCallbackQuery> {
|
||||
pub fn callback_query_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.callback_query_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn text<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.text = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn show_alert(mut self, val: bool) -> Self {
|
||||
self.payload.show_alert = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn url<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.url = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn cache_time(mut self, val: i32) -> Self {
|
||||
self.payload.cache_time = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
113
src/requests/payloads/answer_inline_query.rs
Normal file
113
src/requests/payloads/answer_inline_query.rs
Normal file
|
@ -0,0 +1,113 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::InlineQueryResult,
|
||||
types::True,
|
||||
};
|
||||
|
||||
/// Use this method to send answers to an inline query. On success, True is returned.No more than 50 results per query are allowed.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
pub struct AnswerInlineQuery {
|
||||
/// Unique identifier for the answered query
|
||||
inline_query_id: String,
|
||||
/// A JSON-serialized array of results for the inline query
|
||||
results: Vec<InlineQueryResult>,
|
||||
/// The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.
|
||||
cache_time: Option<i32>,
|
||||
/// Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query
|
||||
is_personal: Option<bool>,
|
||||
/// Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t exceed 64 bytes.
|
||||
next_offset: Option<String>,
|
||||
/// If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switch_pm_parameter
|
||||
switch_pm_text: Option<String>,
|
||||
/// Deep-linking parameter for the /start message sent to the bot when user presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed.Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account to adapt search results accordingly. To do this, it displays a ‘Connect your YouTube account’ button above the results, or even before showing any. The user presses the button, switches to a private chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth link. Once done, the bot can offer a switch_inline button so that the user can easily return to the chat where they wanted to use the bot's inline capabilities.
|
||||
switch_pm_parameter: Option<String>,
|
||||
}
|
||||
|
||||
impl Method for AnswerInlineQuery {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "answerInlineQuery";
|
||||
}
|
||||
|
||||
impl json::Payload for AnswerInlineQuery {}
|
||||
|
||||
impl dynamic::Payload for AnswerInlineQuery {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl AnswerInlineQuery {
|
||||
pub fn new<I, R>(inline_query_id: I, results: R) -> Self
|
||||
where
|
||||
I: Into<String>,
|
||||
R: Into<Vec<InlineQueryResult>>
|
||||
{
|
||||
let inline_query_id = inline_query_id.into();
|
||||
let results = results.into();
|
||||
Self {
|
||||
inline_query_id,
|
||||
results,
|
||||
cache_time: None,
|
||||
is_personal: None,
|
||||
next_offset: None,
|
||||
switch_pm_text: None,
|
||||
switch_pm_parameter: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, AnswerInlineQuery> {
|
||||
pub fn inline_query_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.inline_query_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn results<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<Vec<InlineQueryResult>>
|
||||
{
|
||||
self.payload.results = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn cache_time(mut self, val: i32) -> Self {
|
||||
self.payload.cache_time = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
pub fn is_personal(mut self, val: bool) -> Self {
|
||||
self.payload.is_personal = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn next_offset<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.next_offset = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn switch_pm_text<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.switch_pm_text = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn switch_pm_parameter<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.switch_pm_parameter = Some(val.into());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
68
src/requests/payloads/answer_pre_checkout_query.rs
Normal file
68
src/requests/payloads/answer_pre_checkout_query.rs
Normal file
|
@ -0,0 +1,68 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::True,
|
||||
};
|
||||
|
||||
/// Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, True is returned. Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct AnswerPreCheckoutQuery {
|
||||
/// Unique identifier for the query to be answered
|
||||
pre_checkout_query_id: String,
|
||||
/// Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.
|
||||
ok: bool,
|
||||
/// Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user.
|
||||
error_message: Option<String>,
|
||||
}
|
||||
|
||||
impl Method for AnswerPreCheckoutQuery {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "answerPreCheckoutQuery";
|
||||
}
|
||||
|
||||
impl json::Payload for AnswerPreCheckoutQuery {}
|
||||
|
||||
impl dynamic::Payload for AnswerPreCheckoutQuery {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl AnswerPreCheckoutQuery {
|
||||
pub fn new<P>(pre_checkout_query_id: P, ok: bool) -> Self
|
||||
where
|
||||
P: Into<String>
|
||||
{
|
||||
let pre_checkout_query_id = pre_checkout_query_id.into();
|
||||
Self {
|
||||
pre_checkout_query_id,
|
||||
ok,
|
||||
error_message: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, AnswerPreCheckoutQuery> {
|
||||
pub fn pre_checkout_query_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.pre_checkout_query_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ok(mut self, val: bool) -> Self {
|
||||
self.payload.ok = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn error_message<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.error_message = Some(val.into());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
79
src/requests/payloads/answer_shipping_query.rs
Normal file
79
src/requests/payloads/answer_shipping_query.rs
Normal file
|
@ -0,0 +1,79 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ShippingOption, True},
|
||||
};
|
||||
|
||||
/// If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct AnswerShippingQuery {
|
||||
/// Unique identifier for the query to be answered
|
||||
shipping_query_id: String,
|
||||
/// Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible)
|
||||
ok: bool,
|
||||
/// Required if ok is True. A JSON-serialized array of available shipping options.
|
||||
shipping_options: Option<Vec<ShippingOption>>,
|
||||
/// Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user.
|
||||
error_message: Option<String>,
|
||||
}
|
||||
|
||||
impl Method for AnswerShippingQuery {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "answerShippingQuery";
|
||||
}
|
||||
|
||||
impl json::Payload for AnswerShippingQuery {}
|
||||
|
||||
impl dynamic::Payload for AnswerShippingQuery {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl AnswerShippingQuery {
|
||||
pub fn new<S>(shipping_query_id: S, ok: bool) -> Self
|
||||
where
|
||||
S: Into<String>
|
||||
{
|
||||
let shipping_query_id = shipping_query_id.into();
|
||||
Self {
|
||||
shipping_query_id,
|
||||
ok,
|
||||
shipping_options: None,
|
||||
error_message: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, AnswerShippingQuery> {
|
||||
pub fn shipping_query_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.shipping_query_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ok(mut self, val: bool) -> Self {
|
||||
self.payload.ok = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn shipping_options<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<Vec<ShippingOption>>
|
||||
{
|
||||
self.payload.shipping_options = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn error_message<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.error_message = Some(val.into());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
125
src/requests/payloads/create_new_sticker_set.rs
Normal file
125
src/requests/payloads/create_new_sticker_set.rs
Normal file
|
@ -0,0 +1,125 @@
|
|||
use reqwest::multipart::Form;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, multipart, Method, form_builder::FormBuilder},
|
||||
types::{InputFile, MaskPosition, True},
|
||||
};
|
||||
|
||||
/// Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
pub struct CreateNewStickerSet {
|
||||
/// User identifier of created sticker set owner
|
||||
user_id: i32,
|
||||
/// Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can contain only english letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in “_by_<bot username>”. <bot_username> is case insensitive. 1-64 characters.
|
||||
name: String,
|
||||
/// Sticker set title, 1-64 characters
|
||||
title: String,
|
||||
/// Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More info on Sending Files »
|
||||
png_sticker: InputFile,
|
||||
/// One or more emoji corresponding to the sticker
|
||||
emojis: String,
|
||||
/// Pass True, if a set of mask stickers should be created
|
||||
contains_masks: Option<bool>,
|
||||
/// A JSON-serialized object for position where the mask should be placed on faces
|
||||
mask_position: Option<MaskPosition>,
|
||||
}
|
||||
|
||||
impl Method for CreateNewStickerSet {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "createNewStickerSet";
|
||||
}
|
||||
|
||||
impl multipart::Payload for CreateNewStickerSet {
|
||||
fn payload(&self) -> Form {
|
||||
FormBuilder::new()
|
||||
.add("user_id", &self.user_id)
|
||||
.add("name", &self.name)
|
||||
.add("title", &self.title)
|
||||
.add("png_sticker", &self.png_sticker)
|
||||
.add("emojis", &self.emojis)
|
||||
.add("contains_masks", &self.contains_masks)
|
||||
.add("mask_position", &self.mask_position)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
impl dynamic::Payload for CreateNewStickerSet {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Multipart(multipart::Payload::payload(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl CreateNewStickerSet {
|
||||
pub fn new<N, T, P, E>(user_id: i32, name: N, title: T, png_sticker: P, emojis: E) -> Self
|
||||
where
|
||||
N: Into<String>,
|
||||
T: Into<String>,
|
||||
P: Into<InputFile>,
|
||||
E: Into<String>
|
||||
{
|
||||
let name = name.into();
|
||||
let title = title.into();
|
||||
let png_sticker = png_sticker.into();
|
||||
let emojis = emojis.into();
|
||||
Self {
|
||||
user_id,
|
||||
name,
|
||||
title,
|
||||
png_sticker,
|
||||
emojis,
|
||||
contains_masks: None,
|
||||
mask_position: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl multipart::Request<'_, CreateNewStickerSet> {
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.payload.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.name = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.title = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn png_sticker<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>
|
||||
{
|
||||
self.payload.png_sticker = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn emojis<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.emojis = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn contains_masks(mut self, val: bool) -> Self {
|
||||
self.payload.contains_masks = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn mask_position(mut self, val: MaskPosition) -> Self {
|
||||
self.payload.mask_position = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
49
src/requests/payloads/delete_chat_photo.rs
Normal file
49
src/requests/payloads/delete_chat_photo.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
};
|
||||
use crate::types::{ChatId, True};
|
||||
|
||||
/// Use this method to delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct DeleteChatPhoto {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
impl Method for DeleteChatPhoto {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "deleteChatPhoto";
|
||||
}
|
||||
|
||||
impl json::Payload for DeleteChatPhoto {}
|
||||
|
||||
impl dynamic::Payload for DeleteChatPhoto {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl DeleteChatPhoto {
|
||||
pub fn new<C>(chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, DeleteChatPhoto> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
49
src/requests/payloads/delete_chat_sticker_set.rs
Normal file
49
src/requests/payloads/delete_chat_sticker_set.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
/// Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct DeleteChatStickerSet {
|
||||
/// Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
impl Method for DeleteChatStickerSet {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "deleteChatStickerSet";
|
||||
}
|
||||
|
||||
impl json::Payload for DeleteChatStickerSet {}
|
||||
|
||||
impl dynamic::Payload for DeleteChatStickerSet {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl DeleteChatStickerSet {
|
||||
pub fn new<C>(chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, DeleteChatStickerSet> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
57
src/requests/payloads/delete_message.rs
Normal file
57
src/requests/payloads/delete_message.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
/// Use this method to delete a message, including service messages, with the following limitations:- A message can only be deleted if it was sent less than 48 hours ago.- Bots can delete outgoing messages in private chats, groups, and supergroups.- Bots can delete incoming messages in private chats.- Bots granted can_post_messages permissions can delete outgoing messages in channels.- If the bot is an administrator of a group, it can delete any message there.- If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct DeleteMessage {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Identifier of the message to delete
|
||||
message_id: i32,
|
||||
}
|
||||
|
||||
impl Method for DeleteMessage {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "deleteMessage";
|
||||
}
|
||||
|
||||
impl json::Payload for DeleteMessage {}
|
||||
|
||||
impl dynamic::Payload for DeleteMessage {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl DeleteMessage {
|
||||
pub fn new<C>(chat_id: C, message_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
message_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, DeleteMessage> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.payload.message_id = val;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
49
src/requests/payloads/delete_sticker_from_set.rs
Normal file
49
src/requests/payloads/delete_sticker_from_set.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::True,
|
||||
};
|
||||
|
||||
/// Use this method to delete a sticker from a set created by the bot. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct DeleteStickerFromSet {
|
||||
/// File identifier of the sticker
|
||||
sticker: String,
|
||||
}
|
||||
|
||||
impl Method for DeleteStickerFromSet {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "deleteStickerFromSet";
|
||||
}
|
||||
|
||||
impl json::Payload for DeleteStickerFromSet {}
|
||||
|
||||
impl dynamic::Payload for DeleteStickerFromSet {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl DeleteStickerFromSet {
|
||||
pub fn new<S>(sticker: S) -> Self
|
||||
where
|
||||
S: Into<String>
|
||||
{
|
||||
let sticker = sticker.into();
|
||||
Self {
|
||||
sticker,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, DeleteStickerFromSet> {
|
||||
pub fn sticker<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.sticker = val.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
30
src/requests/payloads/delete_webhook.rs
Normal file
30
src/requests/payloads/delete_webhook.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::True,
|
||||
};
|
||||
|
||||
/// Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success. Requires no parameters.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize, Default)]
|
||||
pub struct DeleteWebhook {}
|
||||
|
||||
impl Method for DeleteWebhook {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "deleteWebhook";
|
||||
}
|
||||
|
||||
impl json::Payload for DeleteWebhook {}
|
||||
|
||||
impl dynamic::Payload for DeleteWebhook {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl DeleteWebhook {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
83
src/requests/payloads/edit_message_caption.rs
Normal file
83
src/requests/payloads/edit_message_caption.rs
Normal file
|
@ -0,0 +1,83 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, ParseMode, InlineKeyboardMarkup, Message},
|
||||
};
|
||||
|
||||
/// Use this method to edit captions of messages. On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct EditMessageCaption {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Identifier of the message to edit
|
||||
message_id: i32,
|
||||
/// New caption of the message
|
||||
caption: Option<String>,
|
||||
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
|
||||
parse_mode: Option<ParseMode>,
|
||||
/// A JSON-serialized object for an inline keyboard.
|
||||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
impl Method for EditMessageCaption {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "editMessageCaptionInline";
|
||||
}
|
||||
|
||||
impl json::Payload for EditMessageCaption {}
|
||||
|
||||
impl dynamic::Payload for EditMessageCaption {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageCaption {
|
||||
pub fn new<C>(chat_id: C, message_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
message_id,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, EditMessageCaption> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.payload.message_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.caption = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.payload.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
78
src/requests/payloads/edit_message_caption_inline.rs
Normal file
78
src/requests/payloads/edit_message_caption_inline.rs
Normal file
|
@ -0,0 +1,78 @@
|
|||
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ParseMode, InlineKeyboardMarkup},
|
||||
};
|
||||
use crate::types::Message;
|
||||
|
||||
/// Use this method to edit captions of messages. On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct EditMessageCaptionInline {
|
||||
/// Identifier of the inline message
|
||||
inline_message_id: String,
|
||||
/// New caption of the message
|
||||
caption: Option<String>,
|
||||
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
|
||||
parse_mode: Option<ParseMode>,
|
||||
/// A JSON-serialized object for an inline keyboard.
|
||||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
impl Method for EditMessageCaptionInline {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "editMessageCaption";
|
||||
}
|
||||
|
||||
impl json::Payload for EditMessageCaptionInline {}
|
||||
|
||||
impl dynamic::Payload for EditMessageCaptionInline {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageCaptionInline {
|
||||
pub fn new<I>(inline_message_id: I) -> Self
|
||||
where
|
||||
I: Into<String>,
|
||||
{
|
||||
let inline_message_id = inline_message_id.into();
|
||||
Self {
|
||||
inline_message_id,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, EditMessageCaptionInline> {
|
||||
pub fn inline_message_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.inline_message_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.caption = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.payload.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
80
src/requests/payloads/edit_message_live_location.rs
Normal file
80
src/requests/payloads/edit_message_live_location.rs
Normal file
|
@ -0,0 +1,80 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, InlineKeyboardMarkup, Message},
|
||||
};
|
||||
|
||||
/// Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
pub struct EditMessageLiveLocation {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Identifier of the message to edit
|
||||
message_id: i32,
|
||||
/// Latitude of new location
|
||||
latitude: f32,
|
||||
/// Longitude of new location
|
||||
longitude: f32,
|
||||
/// A JSON-serialized object for a new inline keyboard.
|
||||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
impl Method for EditMessageLiveLocation {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "editMessageLiveLocationInline";
|
||||
}
|
||||
|
||||
impl json::Payload for EditMessageLiveLocation {}
|
||||
|
||||
impl dynamic::Payload for EditMessageLiveLocation {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageLiveLocation {
|
||||
pub fn new<C>(chat_id: C, message_id: i32, latitude: f32, longitude: f32) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
message_id,
|
||||
latitude,
|
||||
longitude,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, EditMessageLiveLocation> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.payload.message_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn latitude(mut self, val: f32) -> Self {
|
||||
self.payload.latitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn longitude(mut self, val: f32) -> Self {
|
||||
self.payload.longitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
73
src/requests/payloads/edit_message_live_location_inline.rs
Normal file
73
src/requests/payloads/edit_message_live_location_inline.rs
Normal file
|
@ -0,0 +1,73 @@
|
|||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{InlineKeyboardMarkup, Message},
|
||||
};
|
||||
|
||||
/// Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
pub struct EditMessageLiveLocationInline {
|
||||
/// Identifier of the inline message
|
||||
inline_message_id: String,
|
||||
/// Latitude of new location
|
||||
latitude: f32,
|
||||
/// Longitude of new location
|
||||
longitude: f32,
|
||||
/// A JSON-serialized object for a new inline keyboard.
|
||||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
impl Method for EditMessageLiveLocationInline {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "editMessageLiveLocation";
|
||||
}
|
||||
|
||||
impl json::Payload for EditMessageLiveLocationInline {}
|
||||
|
||||
impl dynamic::Payload for EditMessageLiveLocationInline {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageLiveLocationInline {
|
||||
pub fn new<I>(inline_message_id: I, latitude: f32, longitude: f32) -> Self
|
||||
where
|
||||
I: Into<String>,
|
||||
{
|
||||
let inline_message_id = inline_message_id.into();
|
||||
Self {
|
||||
inline_message_id,
|
||||
latitude,
|
||||
longitude,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, EditMessageLiveLocationInline> {
|
||||
pub fn inline_message_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.inline_message_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn latitude(mut self, val: f32) -> Self {
|
||||
self.payload.latitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn longitude(mut self, val: f32) -> Self {
|
||||
self.payload.longitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
83
src/requests/payloads/edit_message_media.rs
Normal file
83
src/requests/payloads/edit_message_media.rs
Normal file
|
@ -0,0 +1,83 @@
|
|||
use reqwest::multipart::Form;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, multipart, Method, form_builder::FormBuilder},
|
||||
types::{ChatId, InputMedia, InlineKeyboardMarkup, Message},
|
||||
};
|
||||
|
||||
/// Use this method to edit animation, audio, document, photo, or video messages. If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded. Use previously uploaded file via its file_id or specify a URL. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
pub struct EditMessageMedia {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Identifier of the message to edit
|
||||
message_id: i32,
|
||||
/// A JSON-serialized object for a new media content of the message
|
||||
media: InputMedia,
|
||||
/// A JSON-serialized object for a new inline keyboard.
|
||||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
impl Method for EditMessageMedia {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "editMessageMediaInline";
|
||||
}
|
||||
|
||||
impl multipart::Payload for EditMessageMedia {
|
||||
fn payload(&self) -> Form {
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.add("message_id", &self.message_id)
|
||||
.add("media", &self.media)
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
impl dynamic::Payload for EditMessageMedia {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Multipart(multipart::Payload::payload(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageMedia {
|
||||
pub fn new<C>(chat_id: C, message_id: i32, media: InputMedia) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
message_id,
|
||||
media,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl multipart::Request<'_, EditMessageMedia> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.payload.message_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn media(mut self, val: InputMedia) -> Self {
|
||||
self.payload.media = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
74
src/requests/payloads/edit_message_media_inline.rs
Normal file
74
src/requests/payloads/edit_message_media_inline.rs
Normal file
|
@ -0,0 +1,74 @@
|
|||
use reqwest::multipart::Form;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, multipart, Method, form_builder::FormBuilder},
|
||||
types::{InputMedia, InlineKeyboardMarkup, Message},
|
||||
};
|
||||
|
||||
/// Use this method to edit animation, audio, document, photo, or video messages. If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded. Use previously uploaded file via its file_id or specify a URL. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
pub struct EditMessageMediaInline {
|
||||
/// Identifier of the inline message
|
||||
inline_message_id: String,
|
||||
/// A JSON-serialized object for a new media content of the message
|
||||
media: InputMedia,
|
||||
/// A JSON-serialized object for a new inline keyboard.
|
||||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
impl Method for EditMessageMediaInline {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "editMessageMedia";
|
||||
}
|
||||
|
||||
impl multipart::Payload for EditMessageMediaInline {
|
||||
fn payload(&self) -> Form {
|
||||
FormBuilder::new()
|
||||
.add("inline_message_id", &self.inline_message_id)
|
||||
.add("media", &self.media)
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
impl dynamic::Payload for EditMessageMediaInline {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Multipart(multipart::Payload::payload(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageMediaInline {
|
||||
pub fn new<I>(inline_message_id: I, media: InputMedia) -> Self
|
||||
where
|
||||
I: Into<String>,
|
||||
{
|
||||
let inline_message_id = inline_message_id.into();
|
||||
Self {
|
||||
inline_message_id,
|
||||
media,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl multipart::Request<'_, EditMessageMediaInline> {
|
||||
pub fn inline_message_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.inline_message_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn media(mut self, val: InputMedia) -> Self {
|
||||
self.payload.media = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
64
src/requests/payloads/edit_message_reply_markup.rs
Normal file
64
src/requests/payloads/edit_message_reply_markup.rs
Normal file
|
@ -0,0 +1,64 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, InlineKeyboardMarkup, Message},
|
||||
};
|
||||
|
||||
/// Use this method to edit only the reply markup of messages. On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct EditMessageReplyMarkup {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Identifier of the message to edit
|
||||
message_id: i32,
|
||||
/// A JSON-serialized object for an inline keyboard.
|
||||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
impl Method for EditMessageReplyMarkup {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "editMessageReplyMarkupInline";
|
||||
}
|
||||
|
||||
impl json::Payload for EditMessageReplyMarkup {}
|
||||
|
||||
impl dynamic::Payload for EditMessageReplyMarkup {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageReplyMarkup {
|
||||
pub fn new<C>(chat_id: C, message_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
message_id,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, EditMessageReplyMarkup> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.payload.message_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
57
src/requests/payloads/edit_message_reply_markup_inline.rs
Normal file
57
src/requests/payloads/edit_message_reply_markup_inline.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{InlineKeyboardMarkup, Message},
|
||||
};
|
||||
|
||||
/// Use this method to edit only the reply markup of messages. On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct EditMessageReplyMarkupInline {
|
||||
/// Identifier of the inline message
|
||||
inline_message_id: String,
|
||||
/// A JSON-serialized object for an inline keyboard.
|
||||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
impl Method for EditMessageReplyMarkupInline {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "editMessageReplyMarkup";
|
||||
}
|
||||
|
||||
impl json::Payload for EditMessageReplyMarkupInline {}
|
||||
|
||||
impl dynamic::Payload for EditMessageReplyMarkupInline {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageReplyMarkupInline {
|
||||
pub fn new<I>(inline_message_id: I) -> Self
|
||||
where
|
||||
I: Into<String>,
|
||||
{
|
||||
let inline_message_id = inline_message_id.into();
|
||||
Self {
|
||||
inline_message_id,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, EditMessageReplyMarkupInline> {
|
||||
pub fn inline_message_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.inline_message_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
93
src/requests/payloads/edit_message_text.rs
Normal file
93
src/requests/payloads/edit_message_text.rs
Normal file
|
@ -0,0 +1,93 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, ParseMode, InlineKeyboardMarkup, Message},
|
||||
};
|
||||
|
||||
/// Use this method to edit text and game messages. On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct EditMessageText {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Identifier of the message to edit
|
||||
message_id: i32,
|
||||
/// New text of the message
|
||||
text: String,
|
||||
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
|
||||
parse_mode: Option<ParseMode>,
|
||||
/// Disables link previews for links in this message
|
||||
disable_web_page_preview: Option<bool>,
|
||||
/// A JSON-serialized object for an inline keyboard.
|
||||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
impl Method for EditMessageText {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "editMessageTextInline";
|
||||
}
|
||||
|
||||
impl json::Payload for EditMessageText {}
|
||||
|
||||
impl dynamic::Payload for EditMessageText {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageText {
|
||||
pub fn new<C, T>(chat_id: C, message_id: i32, text: T) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
T: Into<String>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let text = text.into();
|
||||
Self {
|
||||
chat_id,
|
||||
message_id,
|
||||
text,
|
||||
parse_mode: None,
|
||||
disable_web_page_preview: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, EditMessageText> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.payload.message_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn text<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.text = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.payload.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_web_page_preview(mut self, val: bool) -> Self {
|
||||
self.payload.disable_web_page_preview = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
85
src/requests/payloads/edit_message_text_inline.rs
Normal file
85
src/requests/payloads/edit_message_text_inline.rs
Normal file
|
@ -0,0 +1,85 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ParseMode, InlineKeyboardMarkup, Message},
|
||||
};
|
||||
|
||||
/// Use this method to edit text and game messages. On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct EditMessageTextInline {
|
||||
/// Identifier of the inline message
|
||||
inline_message_id: String,
|
||||
/// New text of the message
|
||||
text: String,
|
||||
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
|
||||
parse_mode: Option<ParseMode>,
|
||||
/// Disables link previews for links in this message
|
||||
disable_web_page_preview: Option<bool>,
|
||||
/// A JSON-serialized object for an inline keyboard.
|
||||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
impl Method for EditMessageTextInline {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "editMessageText";
|
||||
}
|
||||
|
||||
impl json::Payload for EditMessageTextInline {}
|
||||
|
||||
impl dynamic::Payload for EditMessageTextInline {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageTextInline {
|
||||
pub fn new<I, T>(inline_message_id: I, text: T) -> Self
|
||||
where
|
||||
I: Into<String>,
|
||||
T: Into<String>,
|
||||
{
|
||||
let inline_message_id = inline_message_id.into();
|
||||
let text = text.into();
|
||||
Self {
|
||||
inline_message_id,
|
||||
text,
|
||||
parse_mode: None,
|
||||
disable_web_page_preview: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, EditMessageTextInline> {
|
||||
pub fn inline_message_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.inline_message_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn text<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.text = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.payload.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_web_page_preview(mut self, val: bool) -> Self {
|
||||
self.payload.disable_web_page_preview = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
49
src/requests/payloads/export_chat_invite_link.rs
Normal file
49
src/requests/payloads/export_chat_invite_link.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::ChatId,
|
||||
};
|
||||
|
||||
/// Use this method to generate a new invite link for a chat; any previously generated link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns the new invite link as String on success.Note: Each administrator in a chat generates their own invite links. Bots can't use invite links generated by other administrators. If you want your bot to work with invite links, it will need to generate its own link using exportChatInviteLink – after this the link will become available to the bot via the getChat method. If your bot needs to generate a new invite link replacing its previous one, use exportChatInviteLink again.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct ExportChatInviteLink {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
impl Method for ExportChatInviteLink {
|
||||
type Output = String;
|
||||
|
||||
const NAME: &'static str = "exportChatInviteLink";
|
||||
}
|
||||
|
||||
impl json::Payload for ExportChatInviteLink {}
|
||||
|
||||
impl dynamic::Payload for ExportChatInviteLink {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl ExportChatInviteLink {
|
||||
pub fn new<C>(chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, ExportChatInviteLink> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
79
src/requests/payloads/forward_message.rs
Normal file
79
src/requests/payloads/forward_message.rs
Normal file
|
@ -0,0 +1,79 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, Message},
|
||||
};
|
||||
|
||||
/// Use this method to forward messages of any kind. On success, the sent Message is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct ForwardMessage {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
|
||||
from_chat_id: ChatId,
|
||||
/// Sends the message silently. Users will receive a notification with no sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// Message identifier in the chat specified in from_chat_id
|
||||
message_id: i32,
|
||||
}
|
||||
|
||||
impl Method for ForwardMessage {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "forwardMessage";
|
||||
}
|
||||
|
||||
impl json::Payload for ForwardMessage {}
|
||||
|
||||
impl dynamic::Payload for ForwardMessage {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl ForwardMessage {
|
||||
pub fn new<C, F>(chat_id: C, from_chat_id: F, message_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
F: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let from_chat_id = from_chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
from_chat_id,
|
||||
message_id,
|
||||
disable_notification: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, ForwardMessage> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
pub fn from_chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.from_chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.payload.message_id = val;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
49
src/requests/payloads/get_chat.rs
Normal file
49
src/requests/payloads/get_chat.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, Chat},
|
||||
};
|
||||
|
||||
/// Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct GetChat {
|
||||
/// Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
impl Method for GetChat {
|
||||
type Output = Chat;
|
||||
|
||||
const NAME: &'static str = "getChat";
|
||||
}
|
||||
|
||||
impl json::Payload for GetChat {}
|
||||
|
||||
impl dynamic::Payload for GetChat {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChat {
|
||||
pub fn new<C>(chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, GetChat> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
49
src/requests/payloads/get_chat_administrators.rs
Normal file
49
src/requests/payloads/get_chat_administrators.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, ChatMember},
|
||||
};
|
||||
|
||||
/// Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct GetChatAdministrator {
|
||||
/// Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
impl Method for GetChatAdministrator {
|
||||
type Output = Vec<ChatMember>;
|
||||
|
||||
const NAME: &'static str = "getChatAdministrators";
|
||||
}
|
||||
|
||||
impl json::Payload for GetChatAdministrator {}
|
||||
|
||||
impl dynamic::Payload for GetChatAdministrator {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChatAdministrator {
|
||||
pub fn new<C>(chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, GetChatAdministrator> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
57
src/requests/payloads/get_chat_member.rs
Normal file
57
src/requests/payloads/get_chat_member.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, ChatMember},
|
||||
};
|
||||
|
||||
/// Use this method to get information about a member of a chat. Returns a ChatMember object on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct GetChatMember {
|
||||
/// Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Unique identifier of the target user
|
||||
user_id: i32,
|
||||
}
|
||||
|
||||
impl Method for GetChatMember {
|
||||
type Output = ChatMember;
|
||||
|
||||
const NAME: &'static str = "getChatMember";
|
||||
}
|
||||
|
||||
impl json::Payload for GetChatMember {}
|
||||
|
||||
impl dynamic::Payload for GetChatMember {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChatMember {
|
||||
pub fn new<C>(chat_id: C, user_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
user_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, GetChatMember> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.payload.user_id = val;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
49
src/requests/payloads/get_chat_members_count.rs
Normal file
49
src/requests/payloads/get_chat_members_count.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::ChatId,
|
||||
};
|
||||
|
||||
/// Use this method to get the number of members in a chat. Returns Int on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct GetChatMembersCount {
|
||||
/// Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
impl Method for GetChatMembersCount {
|
||||
type Output = i32;
|
||||
|
||||
const NAME: &'static str = "getChatMembersCount";
|
||||
}
|
||||
|
||||
impl json::Payload for GetChatMembersCount {}
|
||||
|
||||
impl dynamic::Payload for GetChatMembersCount {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChatMembersCount {
|
||||
pub fn new<C>(chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, GetChatMembersCount> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
65
src/requests/payloads/get_file.rs
Normal file
65
src/requests/payloads/get_file.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::File,
|
||||
};
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// On success, a [`File`] object is returned.
|
||||
///
|
||||
/// The file can then be downloaded via the link
|
||||
/// `https://api.telegram.org/file/bot<token>/<file_path>`, where `<file_path>`
|
||||
/// is taken from the response. It is guaranteed that the link will be valid
|
||||
/// for at least `1` hour. When the link expires, a new one can be requested by
|
||||
/// calling [`GetFile`] again.
|
||||
///
|
||||
/// **Note**: This function may not preserve the original file name and MIME
|
||||
/// type. You should save the file's MIME type and name (if available) when the
|
||||
/// [`File`] object is received.
|
||||
///
|
||||
/// [`File`]: crate::types::file
|
||||
/// [`GetFile`]: self::GetFile
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct GetFile {
|
||||
/// File identifier to get info about
|
||||
pub file_id: String,
|
||||
}
|
||||
|
||||
impl Method for GetFile {
|
||||
type Output = File;
|
||||
|
||||
const NAME: &'static str = "getFile";
|
||||
}
|
||||
|
||||
impl json::Payload for GetFile {}
|
||||
|
||||
impl dynamic::Payload for GetFile {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl GetFile {
|
||||
pub fn new<F>(file_id: F) -> Self
|
||||
where
|
||||
F: Into<String>,
|
||||
{
|
||||
Self {
|
||||
file_id: file_id.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, GetFile> {
|
||||
pub fn file_id<F>(mut self, value: F) -> Self
|
||||
where
|
||||
F: Into<String>,
|
||||
{
|
||||
self.payload.file_id = value.into();
|
||||
self
|
||||
}
|
||||
}
|
66
src/requests/payloads/get_game_high_scores.rs
Normal file
66
src/requests/payloads/get_game_high_scores.rs
Normal file
|
@ -0,0 +1,66 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::GameHighScore,
|
||||
};
|
||||
use crate::types::ChatId;
|
||||
|
||||
/// Use this method to get data for high score tables. Will return the score of the specified user and several of his neighbors in a game. On success, returns an Array of GameHighScore objects.This method will currently return scores for the target user, plus two of his closest neighbors on each side. Will also return the top three users if the user and his neighbors are not among them. Please note that this behavior is subject to change.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct GetGameHighScore {
|
||||
/// Target user id
|
||||
user_id: i32,
|
||||
/// Unique identifier for the target chat
|
||||
chat_id: ChatId,
|
||||
/// Identifier of the sent message
|
||||
message_id: i32,
|
||||
}
|
||||
|
||||
impl Method for GetGameHighScore {
|
||||
type Output = Vec<GameHighScore>;
|
||||
|
||||
const NAME: &'static str = "getGameHighScores";
|
||||
}
|
||||
|
||||
impl json::Payload for GetGameHighScore {}
|
||||
|
||||
impl dynamic::Payload for GetGameHighScore {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl GetGameHighScore {
|
||||
pub fn new<C>(chat_id: C, message_id: i32, user_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
message_id,
|
||||
user_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, GetGameHighScore> {
|
||||
pub fn chat_id<C>(mut self, val: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.payload.message_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.payload.user_id = val;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
56
src/requests/payloads/get_game_high_scores_inline.rs
Normal file
56
src/requests/payloads/get_game_high_scores_inline.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::GameHighScore,
|
||||
};
|
||||
|
||||
/// Use this method to get data for high score tables. Will return the score of the specified user and several of his neighbors in a game. On success, returns an Array of GameHighScore objects.This method will currently return scores for the target user, plus two of his closest neighbors on each side. Will also return the top three users if the user and his neighbors are not among them. Please note that this behavior is subject to change.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct GetGameHighScoreInline {
|
||||
/// Identifier of the inline message
|
||||
inline_message_id: String,
|
||||
/// Target user id
|
||||
user_id: i32,
|
||||
}
|
||||
|
||||
impl Method for GetGameHighScoreInline {
|
||||
type Output = Vec<GameHighScore>;
|
||||
|
||||
const NAME: &'static str = "getGameHighScores";
|
||||
}
|
||||
|
||||
impl json::Payload for GetGameHighScoreInline {}
|
||||
|
||||
impl dynamic::Payload for GetGameHighScoreInline {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl GetGameHighScoreInline {
|
||||
pub fn new<I>(inline_message_id: I, user_id: i32) -> Self
|
||||
where
|
||||
I: Into<String>,
|
||||
{
|
||||
let inline_message_id = inline_message_id.into();
|
||||
Self {
|
||||
inline_message_id,
|
||||
user_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, GetGameHighScoreInline> {
|
||||
pub fn inline_message_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.inline_message_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.payload.user_id = val;
|
||||
self
|
||||
}
|
||||
}
|
33
src/requests/payloads/get_me.rs
Normal file
33
src/requests/payloads/get_me.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::User,
|
||||
};
|
||||
|
||||
#[derive(
|
||||
Debug, PartialEq, Eq, Hash, Clone, Copy, Default, Deserialize, Serialize,
|
||||
)]
|
||||
/// A filter method for testing your bot's auth token. Requires no parameters.
|
||||
/// Returns basic information about the bot in form of a [`User`] object.
|
||||
///
|
||||
/// [`User`]: crate::types::User
|
||||
pub struct GetMe {}
|
||||
|
||||
impl Method for GetMe {
|
||||
type Output = User;
|
||||
|
||||
const NAME: &'static str = "getMe";
|
||||
}
|
||||
|
||||
impl json::Payload for GetMe {}
|
||||
|
||||
impl dynamic::Payload for GetMe {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl GetMe {
|
||||
pub fn new() -> Self {
|
||||
GetMe {}
|
||||
}
|
||||
}
|
49
src/requests/payloads/get_sticker_set.rs
Normal file
49
src/requests/payloads/get_sticker_set.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::StickerSet,
|
||||
};
|
||||
|
||||
/// Use this method to get a sticker set. On success, a StickerSet object is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct GetStickerSet {
|
||||
/// Name of the sticker set
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl Method for GetStickerSet {
|
||||
type Output = StickerSet;
|
||||
|
||||
const NAME: &'static str = "getStickerSet";
|
||||
}
|
||||
|
||||
impl json::Payload for GetStickerSet {}
|
||||
|
||||
impl dynamic::Payload for GetStickerSet {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl GetStickerSet {
|
||||
pub fn new<N>(name: N) -> Self
|
||||
where
|
||||
N: Into<String>
|
||||
{
|
||||
let name = name.into();
|
||||
Self {
|
||||
name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, GetStickerSet> {
|
||||
pub fn name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.name = val.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
121
src/requests/payloads/get_updates.rs
Normal file
121
src/requests/payloads/get_updates.rs
Normal file
|
@ -0,0 +1,121 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::Update,
|
||||
};
|
||||
|
||||
/// Use this method to receive incoming updates using long polling ([wiki]).
|
||||
/// An array ([`Vec`]) of [`Update`]s is returned.
|
||||
///
|
||||
/// **Notes:**
|
||||
/// 1. This method will not work if an outgoing webhook is set up.
|
||||
/// 2. In order to avoid getting duplicate updates,
|
||||
/// recalculate offset after each server response.
|
||||
///
|
||||
/// [wiki]: https://en.wikipedia.org/wiki/Push_technology#Long_polling
|
||||
/// [Update]: crate::types::Update
|
||||
/// [Vec]: std::alloc::Vec
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize, Default)]
|
||||
pub struct GetUpdates {
|
||||
/// Identifier of the first update to be returned. Must be greater by one
|
||||
/// than the highest among the identifiers of previously received updates.
|
||||
/// By default, updates starting with the earliest unconfirmed update are
|
||||
/// returned. An update is considered confirmed as soon as [`GetUpdates`]
|
||||
/// is called with an [`offset`] higher than its [`id`]. The negative
|
||||
/// offset can be specified to retrieve updates starting from `-offset`
|
||||
/// update from the end of the updates queue. All previous updates will
|
||||
/// forgotten.
|
||||
///
|
||||
/// [`GetUpdates`]: self::GetUpdates
|
||||
/// [`offset`]: self::GetUpdates::offset
|
||||
/// [`id`]: crate::types::Update::id
|
||||
pub offset: Option<i32>,
|
||||
/// Limits the number of updates to be retrieved.
|
||||
/// Values between `1`—`100` are accepted. Defaults to `100`.
|
||||
pub limit: Option<u8>,
|
||||
/// Timeout in seconds for long polling. Defaults to `0`,
|
||||
/// i.e. usual short polling. Should be positive, short polling should be
|
||||
/// used for testing purposes only.
|
||||
pub timeout: Option<u32>,
|
||||
/// List the types of updates you want your bot to receive.
|
||||
/// For example, specify [[`Message`], [`EditedChannelPost`],
|
||||
/// [`CallbackQuery`]] to only receive updates of these types.
|
||||
/// See [`AllowedUpdate`] for a complete list of available update types.
|
||||
///
|
||||
/// Specify an empty list to receive all updates regardless of type
|
||||
/// (default). If not specified, the previous setting will be used.
|
||||
///
|
||||
/// **Note:**
|
||||
/// This parameter doesn't affect updates created before the call to the
|
||||
/// [`GetUpdates`], so unwanted updates may be received for a short period
|
||||
/// of time.
|
||||
///
|
||||
/// [`Message`]: self::AllowedUpdate::Message
|
||||
/// [`EditedChannelPost`]: self::AllowedUpdate::EditedChannelPost
|
||||
/// [`CallbackQuery`]: self::AllowedUpdate::CallbackQuery
|
||||
/// [`AllowedUpdate`]: self::AllowedUpdate
|
||||
/// [`GetUpdates`]: self::GetUpdates
|
||||
pub allowed_updates: Option<Vec<AllowedUpdate>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum AllowedUpdate {
|
||||
Message,
|
||||
EditedMessage,
|
||||
ChannelPost,
|
||||
EditedChannelPost,
|
||||
InlineQuery,
|
||||
ChosenInlineResult,
|
||||
CallbackQuery,
|
||||
}
|
||||
|
||||
impl Method for GetUpdates {
|
||||
type Output = Vec<Update>;
|
||||
|
||||
const NAME: &'static str = "getUpdates";
|
||||
}
|
||||
|
||||
impl json::Payload for GetUpdates {}
|
||||
|
||||
impl dynamic::Payload for GetUpdates {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl GetUpdates {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
offset: None,
|
||||
limit: None,
|
||||
timeout: None,
|
||||
allowed_updates: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, GetUpdates> {
|
||||
pub fn offset(mut self, value: i32) -> Self {
|
||||
self.payload.offset = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn limit(mut self, value: u8) -> Self {
|
||||
self.payload.limit = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn timeout(mut self, value: u32) -> Self {
|
||||
self.payload.timeout = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn allowed_updates<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<Vec<AllowedUpdate>>, // TODO: into or other trait?
|
||||
{
|
||||
self.payload.allowed_updates = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
59
src/requests/payloads/get_user_profile_photos.rs
Normal file
59
src/requests/payloads/get_user_profile_photos.rs
Normal file
|
@ -0,0 +1,59 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::UserProfilePhotos,
|
||||
};
|
||||
|
||||
/// Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct GetUserProfilePhoto {
|
||||
/// Unique identifier of the target user
|
||||
user_id: i32,
|
||||
/// Sequential number of the first photo to be returned. By default, all photos are returned.
|
||||
offset: Option<i32>,
|
||||
/// Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100.
|
||||
limit: Option<i32>,
|
||||
}
|
||||
|
||||
impl Method for GetUserProfilePhoto {
|
||||
type Output = UserProfilePhotos;
|
||||
|
||||
const NAME: &'static str = "getUserProfilePhotos";
|
||||
}
|
||||
|
||||
impl json::Payload for GetUserProfilePhoto {}
|
||||
|
||||
impl dynamic::Payload for GetUserProfilePhoto {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl GetUserProfilePhoto {
|
||||
pub fn new(user_id: i32) -> Self {
|
||||
|
||||
Self {
|
||||
user_id,
|
||||
offset: None,
|
||||
limit: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, GetUserProfilePhoto> {
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.payload.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn offset(mut self, val: i32) -> Self {
|
||||
self.payload.offset = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn limit(mut self, val: i32) -> Self {
|
||||
self.payload.limit = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
28
src/requests/payloads/get_webhook_info.rs
Normal file
28
src/requests/payloads/get_webhook_info.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
};
|
||||
use crate::types::WebhookInfo;
|
||||
|
||||
/// Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty.
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize, Default)]
|
||||
pub struct GetWebhookInfo {}
|
||||
|
||||
impl Method for GetWebhookInfo {
|
||||
type Output = WebhookInfo;
|
||||
|
||||
const NAME: &'static str = "getWebhookInfo";
|
||||
}
|
||||
|
||||
impl json::Payload for GetWebhookInfo {}
|
||||
|
||||
impl dynamic::Payload for GetWebhookInfo {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl GetWebhookInfo {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
65
src/requests/payloads/kick_chat_member.rs
Normal file
65
src/requests/payloads/kick_chat_member.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
/// 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 the group on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct KickChatMember {
|
||||
/// Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Unique identifier of the target user
|
||||
user_id: i32,
|
||||
/// Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever
|
||||
until_date: Option<i32>,
|
||||
}
|
||||
|
||||
impl Method for KickChatMember {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "kickChatMember";
|
||||
}
|
||||
|
||||
impl json::Payload for KickChatMember {}
|
||||
|
||||
impl dynamic::Payload for KickChatMember {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl KickChatMember {
|
||||
pub fn new<C>(chat_id: C, user_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
user_id,
|
||||
until_date: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, KickChatMember> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.payload.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn until_date(mut self, val: i32) -> Self {
|
||||
self.payload.until_date = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
50
src/requests/payloads/leave_chat.rs
Normal file
50
src/requests/payloads/leave_chat.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
|
||||
/// Use this method for your bot to leave a group, supergroup or channel. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct LeaveChat {
|
||||
/// Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
impl Method for LeaveChat {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "leaveChat";
|
||||
}
|
||||
|
||||
impl json::Payload for LeaveChat {}
|
||||
|
||||
impl dynamic::Payload for LeaveChat {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl LeaveChat {
|
||||
pub fn new<C>(chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, LeaveChat> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
65
src/requests/payloads/pin_chat_message.rs
Normal file
65
src/requests/payloads/pin_chat_message.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
};
|
||||
use crate::types::{ChatId, True};
|
||||
|
||||
/// Use this method to pin a message in a group, a supergroup, or a channel. The bot must be an administrator in the chat for this to work and must have the ‘can_pin_messages’ admin right in the supergroup or ‘can_edit_messages’ admin right in the channel. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct PinChatMessage {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Identifier of a message to pin
|
||||
message_id: i32,
|
||||
/// Pass True, if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels.
|
||||
disable_notification: Option<bool>,
|
||||
}
|
||||
|
||||
impl Method for PinChatMessage {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "pinChatMessage";
|
||||
}
|
||||
|
||||
impl json::Payload for PinChatMessage {}
|
||||
|
||||
impl dynamic::Payload for PinChatMessage {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl PinChatMessage {
|
||||
pub fn new<C>(chat_id: C, message_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
message_id,
|
||||
disable_notification: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, PinChatMessage> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.payload.message_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
121
src/requests/payloads/promote_chat_member.rs
Normal file
121
src/requests/payloads/promote_chat_member.rs
Normal file
|
@ -0,0 +1,121 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
};
|
||||
use crate::types::{ChatId, True};
|
||||
|
||||
/// 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 the appropriate admin rights. Pass False for all boolean parameters to demote a user. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct PromoteChatMember {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Unique identifier of the target user
|
||||
user_id: i32,
|
||||
/// Pass True, if the administrator can change chat title, photo and other settings
|
||||
can_change_info: Option<bool>,
|
||||
/// Pass True, if the administrator can create channel posts, channels only
|
||||
can_post_messages: Option<bool>,
|
||||
/// Pass True, if the administrator can edit messages of other users and can pin messages, channels only
|
||||
can_edit_messages: Option<bool>,
|
||||
/// Pass True, if the administrator can delete messages of other users
|
||||
can_delete_messages: Option<bool>,
|
||||
/// Pass True, if the administrator can invite new users to the chat
|
||||
can_invite_users: Option<bool>,
|
||||
/// Pass True, if the administrator can restrict, ban or unban chat members
|
||||
can_restrict_members: Option<bool>,
|
||||
/// Pass True, if the administrator can pin messages, supergroups only
|
||||
can_pin_messages: Option<bool>,
|
||||
/// Pass True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by him)
|
||||
can_promote_members: Option<bool>,
|
||||
}
|
||||
|
||||
impl Method for PromoteChatMember {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "promoteChatMember";
|
||||
}
|
||||
|
||||
impl json::Payload for PromoteChatMember {}
|
||||
|
||||
impl dynamic::Payload for PromoteChatMember {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl PromoteChatMember {
|
||||
pub fn new<C>(chat_id: C, user_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
user_id,
|
||||
can_change_info: None,
|
||||
can_post_messages: None,
|
||||
can_edit_messages: None,
|
||||
can_delete_messages: None,
|
||||
can_invite_users: None,
|
||||
can_restrict_members: None,
|
||||
can_pin_messages: None,
|
||||
can_promote_members: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, PromoteChatMember> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.payload.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_change_info(mut self, val: bool) -> Self {
|
||||
self.payload.can_change_info = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_post_messages(mut self, val: bool) -> Self {
|
||||
self.payload.can_post_messages = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_edit_messages(mut self, val: bool) -> Self {
|
||||
self.payload.can_edit_messages = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_delete_messages(mut self, val: bool) -> Self {
|
||||
self.payload.can_delete_messages = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_invite_users(mut self, val: bool) -> Self {
|
||||
self.payload.can_invite_users = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_restrict_members(mut self, val: bool) -> Self {
|
||||
self.payload.can_restrict_members = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_pin_messages(mut self, val: bool) -> Self {
|
||||
self.payload.can_pin_messages = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_promote_members(mut self, val: bool) -> Self {
|
||||
self.payload.can_promote_members = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
73
src/requests/payloads/restrict_chat_member.rs
Normal file
73
src/requests/payloads/restrict_chat_member.rs
Normal file
|
@ -0,0 +1,73 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, ChatPermissions, True},
|
||||
};
|
||||
|
||||
/// 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 appropriate admin rights. Pass True for all permissions to lift restrictions from a user. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct RestrictChatMember {
|
||||
/// Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
||||
chat_id: ChatId,
|
||||
/// Unique identifier of the target user
|
||||
user_id: i32,
|
||||
/// New user permissions
|
||||
permissions: ChatPermissions,
|
||||
/// Date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever
|
||||
until_date: Option<i32>,
|
||||
}
|
||||
|
||||
impl Method for RestrictChatMember {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "restrictChatMember";
|
||||
}
|
||||
|
||||
impl json::Payload for RestrictChatMember {}
|
||||
|
||||
impl dynamic::Payload for RestrictChatMember {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl RestrictChatMember {
|
||||
pub fn new<C>(chat_id: C, user_id: i32, permissions: ChatPermissions) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
user_id,
|
||||
permissions,
|
||||
until_date: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, RestrictChatMember> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.payload.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn permissions(mut self, val: ChatPermissions) -> Self {
|
||||
self.payload.permissions = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn until_date(mut self, val: i32) -> Self {
|
||||
self.payload.until_date = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
163
src/requests/payloads/send_animation.rs
Normal file
163
src/requests/payloads/send_animation.rs
Normal file
|
@ -0,0 +1,163 @@
|
|||
use reqwest::multipart::Form;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, form_builder::FormBuilder, multipart, Method},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
};
|
||||
|
||||
/// 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 the future.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SendAnimation {
|
||||
/// Unique identifier for the target chat or username of the target channel
|
||||
/// (in the format `@channelusername`)
|
||||
pub chat_id: ChatId,
|
||||
/// Animation to send.
|
||||
pub animation: InputFile,
|
||||
/// Duration of sent animation in seconds
|
||||
pub duration: Option<u32>,
|
||||
/// Animation width
|
||||
pub width: Option<u32>,
|
||||
/// Animation height
|
||||
pub height: Option<u32>,
|
||||
/// Thumbnail of the file sent; can be ignored if thumbnail generation for
|
||||
/// the file is supported server-side. The thumbnail should be in JPEG
|
||||
/// format and less than 200 kB in size. A thumbnail‘s width and height
|
||||
/// should not exceed 320. Ignored if the file is not uploaded using
|
||||
/// [`InputFile::File`]. Thumbnails can’t be reused and can be only
|
||||
/// uploaded as a new file, with [`InputFile::File`]
|
||||
///
|
||||
/// [`InputFile::File`]: crate::types::InputFile::File
|
||||
pub thumb: Option<InputFile>,
|
||||
/// Animation caption, `0`-`1024` characters
|
||||
pub caption: Option<String>,
|
||||
/// Send [Markdown] or [HTML], if you want Telegram apps to show
|
||||
/// [bold, italic, fixed-width text or inline URLs] in the media caption.
|
||||
///
|
||||
/// [Markdown]: crate::types::ParseMode::Markdown
|
||||
/// [HTML]: crate::types::ParseMode::HTML
|
||||
/// [bold, italic, fixed-width text or inline URLs]:
|
||||
/// crate::types::ParseMode
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
/// Sends the message silently. Users will receive a notification with no
|
||||
/// sound.
|
||||
pub disable_notification: Option<bool>,
|
||||
/// If the message is a reply, [id] of the original message
|
||||
///
|
||||
/// [id]: crate::types::Message::id
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
/// Additional interface options
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendAnimation {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "sendAnimation";
|
||||
}
|
||||
|
||||
impl multipart::Payload for SendAnimation {
|
||||
fn payload(&self) -> Form {
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.add("animation", &self.animation)
|
||||
.add("duration", &self.duration)
|
||||
.add("width", &self.width)
|
||||
.add("height", &self.height)
|
||||
.add("thumb", &self.thumb)
|
||||
.add("caption", &self.caption)
|
||||
.add("parse_mode", &self.parse_mode)
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
impl dynamic::Payload for SendAnimation {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Multipart(multipart::Payload::payload(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl SendAnimation {
|
||||
pub fn new<C>(chat_id: C, animation: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
chat_id: chat_id.into(),
|
||||
animation,
|
||||
duration: None,
|
||||
width: None,
|
||||
height: None,
|
||||
thumb: None,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl multipart::Request<'_, SendAnimation> {
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.payload.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn duration(mut self, value: u32) -> Self {
|
||||
self.payload.duration = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn width(mut self, value: u32) -> Self {
|
||||
self.payload.width = Some(value);
|
||||
self
|
||||
}
|
||||
pub fn height(mut self, value: u32) -> Self {
|
||||
self.payload.height = Some(value);
|
||||
self
|
||||
}
|
||||
pub fn thumb(mut self, value: InputFile) -> Self {
|
||||
self.payload.thumb = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.caption = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn parse_mode(mut self, value: ParseMode) -> Self {
|
||||
self.payload.parse_mode = Some(value);
|
||||
self
|
||||
}
|
||||
pub fn disable_notification(mut self, value: bool) -> Self {
|
||||
self.payload.disable_notification = Some(value);
|
||||
self
|
||||
}
|
||||
pub fn reply_to_message_id(mut self, value: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(value);
|
||||
self
|
||||
}
|
||||
pub fn reply_markup<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ReplyMarkup>,
|
||||
{
|
||||
self.payload.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
163
src/requests/payloads/send_audio.rs
Normal file
163
src/requests/payloads/send_audio.rs
Normal file
|
@ -0,0 +1,163 @@
|
|||
use reqwest::multipart::Form;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, multipart, Method, form_builder::FormBuilder},
|
||||
types::{ReplyMarkup, InputFile, ParseMode, ChatId, Message},
|
||||
};
|
||||
|
||||
/// 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 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.For sending voice messages, use the sendVoice method instead.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SendAudio {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Audio file to send. Pass a file_id as String to send an audio file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an audio file from the Internet, or upload a new one using multipart/form-data. More info on Sending Files »
|
||||
audio: InputFile,
|
||||
/// Audio caption, 0-1024 characters
|
||||
caption: Option<String>,
|
||||
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
|
||||
parse_mode: Option<ParseMode>,
|
||||
/// Duration of the audio in seconds
|
||||
duration: Option<i32>,
|
||||
/// Performer
|
||||
performer: Option<String>,
|
||||
/// Track name
|
||||
title: Option<String>,
|
||||
/// Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More info on Sending Files »
|
||||
thumb: Option<InputFile>,
|
||||
/// Sends the message silently. Users will receive a notification with no sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
/// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||
reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendAudio {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "sendAudio";
|
||||
}
|
||||
|
||||
impl multipart::Payload for SendAudio {
|
||||
fn payload(&self) -> Form {
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.add("audio", &self.audio)
|
||||
.add("caption", &self.caption)
|
||||
.add("parse_mode", &self.parse_mode)
|
||||
.add("duration", &self.duration)
|
||||
.add("performer", &self.performer)
|
||||
.add("title", &self.title)
|
||||
.add("thumb", &self.thumb)
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
impl dynamic::Payload for SendAudio {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Multipart(multipart::Payload::payload(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl SendAudio {
|
||||
pub fn new<C, A>(chat_id: C, audio: A) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
A: Into<InputFile>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let audio = audio.into();
|
||||
Self {
|
||||
chat_id,
|
||||
audio,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
duration: None,
|
||||
performer: None,
|
||||
title: None,
|
||||
thumb: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl multipart::Request<'_, SendAudio> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn audio<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>
|
||||
{
|
||||
self.payload.audio = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.caption = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.payload.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn duration(mut self, val: i32) -> Self {
|
||||
self.payload.duration = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn performer<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.performer = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.title = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn thumb<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>
|
||||
{
|
||||
self.payload.thumb = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
62
src/requests/payloads/send_chat_action.rs
Normal file
62
src/requests/payloads/send_chat_action.rs
Normal file
|
@ -0,0 +1,62 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
/// 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 arrives from your bot, Telegram clients clear its typing status). Returns True on success.Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of “Retrieving image, please wait…”, the bot may use sendChatAction with action = upload_photo. The user will see a “sending photo” status for the bot.We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SendChatAction {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location data, record_video_note or upload_video_note for video notes.
|
||||
action: String,
|
||||
}
|
||||
|
||||
impl Method for SendChatAction {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "sendChatAction";
|
||||
}
|
||||
|
||||
impl json::Payload for SendChatAction {}
|
||||
|
||||
impl dynamic::Payload for SendChatAction {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SendChatAction {
|
||||
pub fn new<C, A>(chat_id: C, action: A) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
A: Into<String>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let action = action.into();
|
||||
Self {
|
||||
chat_id,
|
||||
action,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SendChatAction> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn action<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.action = val.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
121
src/requests/payloads/send_contact.rs
Normal file
121
src/requests/payloads/send_contact.rs
Normal file
|
@ -0,0 +1,121 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, ReplyMarkup, Message},
|
||||
};
|
||||
|
||||
/// Use this method to send phone contacts. On success, the sent Message is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SendContact {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Contact's phone number
|
||||
phone_number: String,
|
||||
/// Contact's first name
|
||||
first_name: String,
|
||||
/// Contact's last name
|
||||
last_name: Option<String>,
|
||||
/// Additional data about the contact in the form of a vCard, 0-2048 bytes
|
||||
vcard: Option<String>,
|
||||
/// Sends the message silently. Users will receive a notification with no sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
/// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove keyboard or to force a reply from the user.
|
||||
reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendContact {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "sendContact";
|
||||
}
|
||||
|
||||
impl json::Payload for SendContact {}
|
||||
|
||||
impl dynamic::Payload for SendContact {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SendContact {
|
||||
pub fn new<C, P, F>(chat_id: C, phone_number: P, first_name: F) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
P: Into<String>,
|
||||
F: Into<String>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let phone_number = phone_number.into();
|
||||
let first_name = first_name.into();
|
||||
Self {
|
||||
chat_id,
|
||||
phone_number,
|
||||
first_name,
|
||||
last_name: None,
|
||||
vcard: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SendContact> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn phone_number<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.phone_number = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn first_name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.first_name = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn last_name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.last_name = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn vcard<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.vcard = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
130
src/requests/payloads/send_document.rs
Normal file
130
src/requests/payloads/send_document.rs
Normal file
|
@ -0,0 +1,130 @@
|
|||
use reqwest::multipart::Form;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, multipart, Method, form_builder::FormBuilder},
|
||||
types::{ReplyMarkup, InputFile, Message, ParseMode, ChatId},
|
||||
};
|
||||
|
||||
/// 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.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SendDocument {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// File to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More info on Sending Files »
|
||||
document: InputFile,
|
||||
/// Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More info on Sending Files »
|
||||
thumb: Option<InputFile>,
|
||||
/// Document caption (may also be used when resending documents by file_id), 0-1024 characters
|
||||
caption: Option<String>,
|
||||
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
|
||||
parse_mode: Option<ParseMode>,
|
||||
/// Sends the message silently. Users will receive a notification with no sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
/// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||
reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendDocument {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "sendDocument";
|
||||
}
|
||||
|
||||
impl multipart::Payload for SendDocument {
|
||||
fn payload(&self) -> Form {
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.add("document", &self.document)
|
||||
.add("thumb", &self.thumb)
|
||||
.add("caption", &self.caption)
|
||||
.add("parse_mode", &self.parse_mode)
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
impl dynamic::Payload for SendDocument {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Multipart(multipart::Payload::payload(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl SendDocument {
|
||||
pub fn new<C, D>(chat_id: C, document: D) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
D: Into<InputFile>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let document = document.into();
|
||||
Self {
|
||||
chat_id,
|
||||
document,
|
||||
thumb: None,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl multipart::Request<'_, SendDocument> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn document<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>
|
||||
{
|
||||
self.payload.document = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn thumb<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>
|
||||
{
|
||||
self.payload.thumb = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.caption = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.payload.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
81
src/requests/payloads/send_game.rs
Normal file
81
src/requests/payloads/send_game.rs
Normal file
|
@ -0,0 +1,81 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{InlineKeyboardMarkup, Message},
|
||||
};
|
||||
|
||||
/// Use this method to send a game. On success, the sent Message is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SendGame {
|
||||
/// Unique identifier for the target chat
|
||||
chat_id: i32,
|
||||
/// Short name of the game, serves as the unique identifier for the game. Set up your games via Botfather.
|
||||
game_short_name: String,
|
||||
/// Sends the message silently. Users will receive a notification with no sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
/// A JSON-serialized object for an inline keyboard. If empty, one ‘Play game_title’ button will be shown. If not empty, the first button must launch the game.
|
||||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendGame {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "sendGame";
|
||||
}
|
||||
|
||||
impl json::Payload for SendGame {}
|
||||
|
||||
impl dynamic::Payload for SendGame {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SendGame {
|
||||
pub fn new<G>(chat_id: i32, game_short_name: G) -> Self
|
||||
where
|
||||
G: Into<String>
|
||||
{
|
||||
let game_short_name = game_short_name.into();
|
||||
Self {
|
||||
chat_id,
|
||||
game_short_name,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SendGame> {
|
||||
pub fn chat_id(mut self, val: i32) -> Self {
|
||||
self.payload.chat_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn game_short_name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.game_short_name = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
272
src/requests/payloads/send_invoice.rs
Normal file
272
src/requests/payloads/send_invoice.rs
Normal file
|
@ -0,0 +1,272 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
};
|
||||
use crate::types::{LabeledPrice, InlineKeyboardMarkup, Message};
|
||||
|
||||
/// Use this method to send invoices. On success, the sent Message is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SendInvoice {
|
||||
/// Unique identifier for the target private chat
|
||||
chat_id: i32,
|
||||
/// Product name, 1-32 characters
|
||||
title: String,
|
||||
/// Product description, 1-255 characters
|
||||
description: String,
|
||||
/// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
|
||||
payload: String,
|
||||
/// Payments provider token, obtained via Botfather
|
||||
provider_token: String,
|
||||
/// Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter
|
||||
start_parameter: String,
|
||||
/// Three-letter ISO 4217 currency code, see more on currencies
|
||||
currency: String,
|
||||
/// Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
|
||||
prices: Vec<LabeledPrice>,
|
||||
/// JSON-encoded data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.
|
||||
provider_data: Option<String>,
|
||||
/// URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for.
|
||||
photo_url: Option<String>,
|
||||
/// Photo size
|
||||
photo_size: Option<i32>,
|
||||
/// Photo width
|
||||
photo_width: Option<i32>,
|
||||
/// Photo height
|
||||
photo_height: Option<i32>,
|
||||
/// Pass True, if you require the user's full name to complete the order
|
||||
need_name: Option<bool>,
|
||||
/// Pass True, if you require the user's phone number to complete the order
|
||||
need_phone_number: Option<bool>,
|
||||
/// Pass True, if you require the user's email address to complete the order
|
||||
need_email: Option<bool>,
|
||||
/// Pass True, if you require the user's shipping address to complete the order
|
||||
need_shipping_address: Option<bool>,
|
||||
/// Pass True, if user's phone number should be sent to provider
|
||||
send_phone_number_to_provider: Option<bool>,
|
||||
/// Pass True, if user's email address should be sent to provider
|
||||
send_email_to_provider: Option<bool>,
|
||||
/// Pass True, if the final price depends on the shipping method
|
||||
is_flexible: Option<bool>,
|
||||
/// Sends the message silently. Users will receive a notification with no sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
/// A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button.
|
||||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendInvoice {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "sendInvoice";
|
||||
}
|
||||
|
||||
impl json::Payload for SendInvoice {}
|
||||
|
||||
impl dynamic::Payload for SendInvoice {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SendInvoice {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new<T, D, Pl, Pt, S, C, Pr>(
|
||||
chat_id: i32,
|
||||
title: T,
|
||||
description: D,
|
||||
payload: Pl,
|
||||
provider_token: Pt,
|
||||
start_parameter: S,
|
||||
currency: C,
|
||||
prices: Pr
|
||||
) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
D: Into<String>,
|
||||
Pl: Into<String>,
|
||||
Pt: Into<String>,
|
||||
S: Into<String>,
|
||||
C: Into<String>,
|
||||
Pr: Into<Vec<LabeledPrice>>
|
||||
{
|
||||
let title = title.into();
|
||||
let description = description.into();
|
||||
let payload = payload.into();
|
||||
let provider_token = provider_token.into();
|
||||
let start_parameter = start_parameter.into();
|
||||
let currency = currency.into();
|
||||
let prices = prices.into();
|
||||
Self {
|
||||
chat_id,
|
||||
title,
|
||||
description,
|
||||
payload,
|
||||
provider_token,
|
||||
start_parameter,
|
||||
currency,
|
||||
prices,
|
||||
provider_data: None,
|
||||
photo_url: None,
|
||||
photo_size: None,
|
||||
photo_width: None,
|
||||
photo_height: None,
|
||||
need_name: None,
|
||||
need_phone_number: None,
|
||||
need_email: None,
|
||||
need_shipping_address: None,
|
||||
send_phone_number_to_provider: None,
|
||||
send_email_to_provider: None,
|
||||
is_flexible: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SendInvoice> {
|
||||
pub fn chat_id(mut self, val: i32) -> Self {
|
||||
self.payload.chat_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.title = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn description<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.description = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn payload<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.payload = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn provider_token<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.provider_token = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn start_parameter<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.start_parameter = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn currency<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.currency = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn prices<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<Vec<LabeledPrice>>
|
||||
{
|
||||
self.payload.prices = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn provider_data<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.provider_data = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo_url<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.photo_url = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo_size(mut self, val: i32) -> Self {
|
||||
self.payload.photo_size = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo_width(mut self, val: i32) -> Self {
|
||||
self.payload.photo_width = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo_height(mut self, val: i32) -> Self {
|
||||
self.payload.photo_height = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn need_name(mut self, val: bool) -> Self {
|
||||
self.payload.need_name = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn need_phone_number(mut self, val: bool) -> Self {
|
||||
self.payload.need_phone_number = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn need_email(mut self, val: bool) -> Self {
|
||||
self.payload.need_email = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn need_shipping_address(mut self, val: bool) -> Self {
|
||||
self.payload.need_shipping_address = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn send_phone_number_to_provider(mut self, val: bool) -> Self {
|
||||
self.payload.send_phone_number_to_provider = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn send_email_to_provider(mut self, val: bool) -> Self {
|
||||
self.payload.send_email_to_provider = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
pub fn is_flexible(mut self, val: bool) -> Self {
|
||||
self.payload.is_flexible = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
97
src/requests/payloads/send_location.rs
Normal file
97
src/requests/payloads/send_location.rs
Normal file
|
@ -0,0 +1,97 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, ReplyMarkup, Message},
|
||||
};
|
||||
|
||||
/// Use this method to send point on the map. On success, the sent Message is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
pub struct SendLocation {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Latitude of the location
|
||||
latitude: f32,
|
||||
/// Longitude of the location
|
||||
longitude: f32,
|
||||
/// Period in seconds for which the location will be updated (see Live Locations, should be between 60 and 86400.
|
||||
live_period: Option<i64>,
|
||||
/// Sends the message silently. Users will receive a notification with no sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
/// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||
reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendLocation {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "sendLocation";
|
||||
}
|
||||
|
||||
impl json::Payload for SendLocation {}
|
||||
|
||||
impl dynamic::Payload for SendLocation {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SendLocation {
|
||||
pub fn new<C>(chat_id: C, latitude: f32, longitude: f32) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
latitude,
|
||||
longitude,
|
||||
live_period: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SendLocation> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn latitude(mut self, val: f32) -> Self {
|
||||
self.payload.latitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn longitude(mut self, val: f32) -> Self {
|
||||
self.payload.longitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn live_period(mut self, val: i64) -> Self {
|
||||
self.payload.live_period = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
89
src/requests/payloads/send_media_group.rs
Normal file
89
src/requests/payloads/send_media_group.rs
Normal file
|
@ -0,0 +1,89 @@
|
|||
use reqwest::multipart::Form;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, Method, multipart, form_builder::FormBuilder},
|
||||
types::{ChatId, InputMedia, Message},
|
||||
};
|
||||
|
||||
/// Use this method to send a group of photos or videos as an album. On success, an array of the sent Messages is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
pub struct SendMediaGroup {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// A JSON-serialized array describing photos and videos to be sent, must include 2–10 items
|
||||
media: Vec<InputMedia>, // TODO: InputMediaPhoto and InputMediaVideo
|
||||
/// Sends the messages silently. Users will receive a notification with no sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// If the messages are a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
}
|
||||
|
||||
impl Method for SendMediaGroup {
|
||||
type Output = Vec<Message>;
|
||||
|
||||
const NAME: &'static str = "sendMediaGroup";
|
||||
}
|
||||
|
||||
impl multipart::Payload for SendMediaGroup {
|
||||
fn payload(&self) -> Form {
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.add("media", &self.media)
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
impl dynamic::Payload for SendMediaGroup {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SendMediaGroup {
|
||||
pub fn new<C, M>(chat_id: C, media: M) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
M: Into<Vec<InputMedia>>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let media = media.into();
|
||||
Self {
|
||||
chat_id,
|
||||
media,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl multipart::Request<'_, SendMediaGroup> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn media<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<Vec<InputMedia>>
|
||||
{
|
||||
self.payload.media = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
116
src/requests/payloads/send_message.rs
Normal file
116
src/requests/payloads/send_message.rs
Normal file
|
@ -0,0 +1,116 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, Message, ParseMode, ReplyMarkup},
|
||||
};
|
||||
|
||||
/// Use this method to send text messages.
|
||||
///
|
||||
/// On success, the sent [`Message`] is returned.
|
||||
///
|
||||
/// [`Message`]: crate::types::Message
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SendMessage {
|
||||
/// Unique identifier for the target chat or username of the target channel
|
||||
/// (in the format `@channelusername`)
|
||||
pub chat_id: ChatId,
|
||||
/// Text of the message to be sent
|
||||
pub text: String,
|
||||
/// Send [Markdown] or [HTML], if you want Telegram apps to show
|
||||
/// [bold, italic, fixed-width text or inline URLs] in your bot's message.
|
||||
///
|
||||
/// [Markdown]: crate::types::ParseMode::Markdown
|
||||
/// [HTML]: crate::types::ParseMode::HTML
|
||||
/// [bold, italic, fixed-width text or inline URLs]:
|
||||
/// crate::types::ParseMode
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
/// Disables link previews for links in this message
|
||||
pub disable_web_page_preview: Option<bool>,
|
||||
/// Sends the message silently.
|
||||
/// Users will receive a notification with no sound.
|
||||
pub disable_notification: Option<bool>,
|
||||
/// If the message is a reply, [id] of the original message
|
||||
///
|
||||
/// [id]: crate::types::Message::id
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
/// Additional interface options.
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendMessage {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "sendMessage";
|
||||
}
|
||||
|
||||
impl json::Payload for SendMessage {}
|
||||
|
||||
impl dynamic::Payload for SendMessage {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SendMessage {
|
||||
pub fn new<C, T>(chat_id: C, text: T) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
T: Into<String>, // TODO: into?
|
||||
{
|
||||
SendMessage {
|
||||
chat_id: chat_id.into(),
|
||||
text: text.into(),
|
||||
parse_mode: None,
|
||||
disable_web_page_preview: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SendMessage> {
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.payload.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn text<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>, // TODO: into?
|
||||
{
|
||||
self.payload.text = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, value: ParseMode) -> Self {
|
||||
self.payload.parse_mode = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_web_page_preview(mut self, value: bool) -> Self {
|
||||
self.payload.disable_web_page_preview = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, value: bool) -> Self {
|
||||
self.payload.disable_notification = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, value: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ReplyMarkup>,
|
||||
{
|
||||
self.payload.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
118
src/requests/payloads/send_photo.rs
Normal file
118
src/requests/payloads/send_photo.rs
Normal file
|
@ -0,0 +1,118 @@
|
|||
use reqwest::multipart::Form;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, multipart, Method, form_builder::FormBuilder},
|
||||
types::{ReplyMarkup, ParseMode, InputFile, Message, ChatId},
|
||||
};
|
||||
|
||||
/// Use this method to send photos. On success, the sent Message is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SendPhoto {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. More info on Sending Files »
|
||||
photo: InputFile,
|
||||
/// Photo caption (may also be used when resending photos by file_id), 0-1024 characters
|
||||
caption: Option<String>,
|
||||
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
|
||||
parse_mode: Option<ParseMode>,
|
||||
/// Sends the message silently. Users will receive a notification with no sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
/// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||
reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendPhoto {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "sendPhoto";
|
||||
}
|
||||
|
||||
impl multipart::Payload for SendPhoto {
|
||||
fn payload(&self) -> Form {
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.add("photo", &self.photo)
|
||||
.add("caption", &self.caption)
|
||||
.add("parse_mode", &self.parse_mode)
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
impl dynamic::Payload for SendPhoto {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Multipart(multipart::Payload::payload(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl SendPhoto {
|
||||
pub fn new<C, P>(chat_id: C, photo: P) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
P: Into<InputFile>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let photo = photo.into();
|
||||
Self {
|
||||
chat_id,
|
||||
photo,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl multipart::Request<'_, SendPhoto> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>
|
||||
{
|
||||
self.payload.photo = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.caption = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.payload.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
99
src/requests/payloads/send_poll.rs
Normal file
99
src/requests/payloads/send_poll.rs
Normal file
|
@ -0,0 +1,99 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
};
|
||||
use crate::types::{ChatId, ReplyMarkup, Message};
|
||||
|
||||
/// 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.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SendPoll {
|
||||
/// Unique 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.
|
||||
chat_id: ChatId,
|
||||
/// Poll question, 1-255 characters
|
||||
question: String,
|
||||
/// List of answer options, 2-10 strings 1-100 characters each
|
||||
options: Vec<String>,
|
||||
/// Sends the message silently. Users will receive a notification with no sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
/// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||
reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendPoll {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "sendPoll";
|
||||
}
|
||||
|
||||
impl json::Payload for SendPoll {}
|
||||
|
||||
impl dynamic::Payload for SendPoll {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SendPoll {
|
||||
pub fn new<C, Q, O>(chat_id: C, question: Q, options: O) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
Q: Into<String>,
|
||||
O: Into<Vec<String>>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let question = question.into();
|
||||
let options = options.into();
|
||||
Self {
|
||||
chat_id,
|
||||
question,
|
||||
options,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SendPoll> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn question<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.question = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn options<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<Vec<String>>
|
||||
{
|
||||
self.payload.options = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
97
src/requests/payloads/send_sticker.rs
Normal file
97
src/requests/payloads/send_sticker.rs
Normal file
|
@ -0,0 +1,97 @@
|
|||
use reqwest::multipart::Form;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, multipart, Method, form_builder::FormBuilder},
|
||||
types::{ReplyMarkup, InputFile, ChatId, Message},
|
||||
};
|
||||
|
||||
/// Use this method to send static .WEBP or animated .TGS stickers. On success, the sent Message is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SendSticker {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Sticker to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a .webp file from the Internet, or upload a new one using multipart/form-data. More info on Sending Files »
|
||||
sticker: InputFile,
|
||||
/// Sends the message silently. Users will receive a notification with no sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
/// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||
reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendSticker {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "sendSticker";
|
||||
}
|
||||
|
||||
impl multipart::Payload for SendSticker {
|
||||
fn payload(&self) -> Form {
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.add("sticker", &self.sticker)
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
impl dynamic::Payload for SendSticker {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Multipart(multipart::Payload::payload(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl SendSticker {
|
||||
pub fn new<C, S>(chat_id: C, sticker: S) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
S: Into<InputFile>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let sticker = sticker.into();
|
||||
Self {
|
||||
chat_id,
|
||||
sticker,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl multipart::Request<'_, SendSticker> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn sticker<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>
|
||||
{
|
||||
self.payload.sticker = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
137
src/requests/payloads/send_venue.rs
Normal file
137
src/requests/payloads/send_venue.rs
Normal file
|
@ -0,0 +1,137 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, ReplyMarkup, Message},
|
||||
};
|
||||
|
||||
/// Use this method to send information about a venue. On success, the sent Message is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
pub struct SendVenue {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Latitude of the venue
|
||||
latitude: f32,
|
||||
/// Longitude of the venue
|
||||
longitude: f32,
|
||||
/// Name of the venue
|
||||
title: String,
|
||||
/// Address of the venue
|
||||
address: String,
|
||||
/// Foursquare identifier of the venue
|
||||
foursquare_id: Option<String>,
|
||||
/// Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)
|
||||
foursquare_type: Option<String>,
|
||||
/// Sends the message silently. Users will receive a notification with no sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
/// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||
reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendVenue {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "sendVenue";
|
||||
}
|
||||
|
||||
impl json::Payload for SendVenue {}
|
||||
|
||||
impl dynamic::Payload for SendVenue {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SendVenue {
|
||||
pub fn new<C, T, A>(chat_id: C, latitude: f32, longitude: f32, title: T, address: A) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
T: Into<String>,
|
||||
A: Into<String>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let title = title.into();
|
||||
let address = address.into();
|
||||
Self {
|
||||
chat_id,
|
||||
latitude,
|
||||
longitude,
|
||||
title,
|
||||
address,
|
||||
foursquare_id: None,
|
||||
foursquare_type: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SendVenue> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn latitude(mut self, val: f32) -> Self {
|
||||
self.payload.latitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn longitude(mut self, val: f32) -> Self {
|
||||
self.payload.longitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.title = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn address<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.address = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn foursquare_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.foursquare_id = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn foursquare_type<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.foursquare_type = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
166
src/requests/payloads/send_video.rs
Normal file
166
src/requests/payloads/send_video.rs
Normal file
|
@ -0,0 +1,166 @@
|
|||
use reqwest::multipart::Form;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, multipart, Method, form_builder::FormBuilder},
|
||||
types::{ReplyMarkup, InputFile, Message, ParseMode, ChatId},
|
||||
};
|
||||
|
||||
/// 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 limit may be changed in the future.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SendVideo {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Video to send. Pass a file_id as String to send a video that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a video from the Internet, or upload a new video using multipart/form-data. More info on Sending Files »
|
||||
video: InputFile,
|
||||
/// Duration of sent video in seconds
|
||||
duration: Option<i32>,
|
||||
/// Video width
|
||||
width: Option<i32>,
|
||||
/// Video height
|
||||
height: Option<i32>,
|
||||
/// Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More info on Sending Files »
|
||||
thumb: Option<InputFile>,
|
||||
/// Video caption (may also be used when resending videos by file_id), 0-1024 characters
|
||||
caption: Option<String>,
|
||||
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
|
||||
parse_mode: Option<ParseMode>,
|
||||
/// Pass True, if the uploaded video is suitable for streaming
|
||||
supports_streaming: Option<bool>,
|
||||
/// Sends the message silently. Users will receive a notification with no sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
/// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||
reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendVideo {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "sendVideo";
|
||||
}
|
||||
|
||||
impl multipart::Payload for SendVideo {
|
||||
fn payload(&self) -> Form {
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.add("video", &self.video)
|
||||
.add("duration", &self.duration)
|
||||
.add("width", &self.width)
|
||||
.add("height", &self.height)
|
||||
.add("thumb", &self.thumb)
|
||||
.add("caption", &self.caption)
|
||||
.add("parse_mode", &self.parse_mode)
|
||||
.add("supports_streaming", &self.supports_streaming)
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
impl dynamic::Payload for SendVideo {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Multipart(multipart::Payload::payload(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl SendVideo {
|
||||
pub fn new<C, V>(chat_id: C, video: V) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
V: Into<InputFile>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let video = video.into();
|
||||
Self {
|
||||
chat_id,
|
||||
video,
|
||||
duration: None,
|
||||
width: None,
|
||||
height: None,
|
||||
thumb: None,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
supports_streaming: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl multipart::Request<'_, SendVideo> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn video<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>
|
||||
{
|
||||
self.payload.video = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn duration(mut self, val: i32) -> Self {
|
||||
self.payload.duration = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn width(mut self, val: i32) -> Self {
|
||||
self.payload.width = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn height(mut self, val: i32) -> Self {
|
||||
self.payload.height = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn thumb<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>
|
||||
{
|
||||
self.payload.thumb = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.caption = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.payload.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn supports_streaming(mut self, val: bool) -> Self {
|
||||
self.payload.supports_streaming = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
127
src/requests/payloads/send_video_note.rs
Normal file
127
src/requests/payloads/send_video_note.rs
Normal file
|
@ -0,0 +1,127 @@
|
|||
use reqwest::multipart::Form;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, multipart, Method, form_builder::FormBuilder},
|
||||
types::{ReplyMarkup, InputFile, ChatId, Message},
|
||||
};
|
||||
|
||||
/// 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 Message is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SendVideoNote {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Video note to send. Pass a file_id as String to send a video note that exists on the Telegram servers (recommended) or upload a new video using multipart/form-data. More info on Sending Files ». Sending video notes by a URL is currently unsupported
|
||||
video_note: InputFile,
|
||||
/// Duration of sent video in seconds
|
||||
duration: Option<i32>,
|
||||
/// Video width and height, i.e. diameter of the video message
|
||||
length: Option<i32>,
|
||||
/// Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. More info on Sending Files »
|
||||
thumb: Option<InputFile>,
|
||||
/// Sends the message silently. Users will receive a notification with no sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
/// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||
reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendVideoNote {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "sendVideoNote";
|
||||
}
|
||||
|
||||
impl multipart::Payload for SendVideoNote {
|
||||
fn payload(&self) -> Form {
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.add("video_note", &self.video_note)
|
||||
.add("duration", &self.duration)
|
||||
.add("length", &self.length)
|
||||
.add("thumb", &self.thumb)
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
impl dynamic::Payload for SendVideoNote {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Multipart(multipart::Payload::payload(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl SendVideoNote {
|
||||
pub fn new<C, V>(chat_id: C, video_note: V) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
V: Into<InputFile>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let video_note = video_note.into();
|
||||
Self {
|
||||
chat_id,
|
||||
video_note,
|
||||
duration: None,
|
||||
length: None,
|
||||
thumb: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl multipart::Request<'_, SendVideoNote> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn video_note<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>
|
||||
{
|
||||
self.payload.video_note = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn duration(mut self, val: i32) -> Self {
|
||||
self.payload.duration = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn length(mut self, val: i32) -> Self {
|
||||
self.payload.length = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn thumb<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>
|
||||
{
|
||||
self.payload.thumb = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
127
src/requests/payloads/send_voice.rs
Normal file
127
src/requests/payloads/send_voice.rs
Normal file
|
@ -0,0 +1,127 @@
|
|||
use reqwest::multipart::Form;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, multipart, Method, form_builder::FormBuilder},
|
||||
types::{ReplyMarkup, InputFile, Message, ParseMode, ChatId},
|
||||
};
|
||||
|
||||
/// 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 in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SendVoice {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Audio file to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More info on Sending Files »
|
||||
voice: InputFile,
|
||||
/// Voice message caption, 0-1024 characters
|
||||
caption: Option<String>,
|
||||
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
|
||||
parse_mode: Option<ParseMode>,
|
||||
/// Duration of the voice message in seconds
|
||||
duration: Option<i32>,
|
||||
/// Sends the message silently. Users will receive a notification with no sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
/// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||
reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendVoice {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "sendVoice";
|
||||
}
|
||||
|
||||
impl multipart::Payload for SendVoice {
|
||||
fn payload(&self) -> Form {
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.add("voice", &self.voice)
|
||||
.add("caption", &self.caption)
|
||||
.add("parse_mode", &self.parse_mode)
|
||||
.add("duration", &self.duration)
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
impl dynamic::Payload for SendVoice {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Multipart(multipart::Payload::payload(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl SendVoice {
|
||||
pub fn new<C, V>(chat_id: C, voice: V) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
V: Into<InputFile>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let voice = voice.into();
|
||||
Self {
|
||||
chat_id,
|
||||
voice,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
duration: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl multipart::Request<'_, SendVoice> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn voice<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>
|
||||
{
|
||||
self.payload.voice = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.caption = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.payload.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn duration(mut self, val: i32) -> Self {
|
||||
self.payload.duration = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.payload.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
60
src/requests/payloads/set_chat_description.rs
Normal file
60
src/requests/payloads/set_chat_description.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
/// Use this method to change the description of a group, a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SetChatDescription {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// New chat description, 0-255 characters
|
||||
description: Option<String>,
|
||||
}
|
||||
|
||||
impl Method for SetChatDescription {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "setChatDescription";
|
||||
}
|
||||
|
||||
impl json::Payload for SetChatDescription {}
|
||||
|
||||
impl dynamic::Payload for SetChatDescription {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatDescription {
|
||||
pub fn new<C>(chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
description: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SetChatDescription> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn description<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.description = Some(val.into());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
57
src/requests/payloads/set_chat_permissions.rs
Normal file
57
src/requests/payloads/set_chat_permissions.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, ChatPermissions, True},
|
||||
};
|
||||
|
||||
/// Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members admin rights. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SetChatPermission {
|
||||
/// Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
||||
chat_id: ChatId,
|
||||
/// New default chat permissions
|
||||
permissions: ChatPermissions,
|
||||
}
|
||||
|
||||
impl Method for SetChatPermission {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "setChatPermissions";
|
||||
}
|
||||
|
||||
impl json::Payload for SetChatPermission {}
|
||||
|
||||
impl dynamic::Payload for SetChatPermission {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatPermission {
|
||||
pub fn new<C>(chat_id: C, permissions: ChatPermissions) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
permissions,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SetChatPermission> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn permissions(mut self, val: ChatPermissions) -> Self {
|
||||
self.payload.permissions = val;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
57
src/requests/payloads/set_chat_photo.rs
Normal file
57
src/requests/payloads/set_chat_photo.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, InputFile, True},
|
||||
};
|
||||
|
||||
/// Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SetChatPhoto {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// New chat photo, uploaded using multipart/form-data
|
||||
photo: InputFile,
|
||||
}
|
||||
|
||||
impl Method for SetChatPhoto {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "setChatPhoto";
|
||||
}
|
||||
|
||||
impl json::Payload for SetChatPhoto {}
|
||||
|
||||
impl dynamic::Payload for SetChatPhoto {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatPhoto {
|
||||
pub fn new<C>(chat_id: C, photo: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
photo,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SetChatPhoto> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo(mut self, val: InputFile) -> Self {
|
||||
self.payload.photo = val;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
62
src/requests/payloads/set_chat_sticker_set.rs
Normal file
62
src/requests/payloads/set_chat_sticker_set.rs
Normal file
|
@ -0,0 +1,62 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
/// Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SetChatStickerSet {
|
||||
/// Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
||||
chat_id: ChatId,
|
||||
/// Name of the sticker set to be set as the group sticker set
|
||||
sticker_set_name: String,
|
||||
}
|
||||
|
||||
impl Method for SetChatStickerSet {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "setChatStickerSet";
|
||||
}
|
||||
|
||||
impl json::Payload for SetChatStickerSet {}
|
||||
|
||||
impl dynamic::Payload for SetChatStickerSet {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatStickerSet {
|
||||
pub fn new<C, S>(chat_id: C, sticker_set_name: S) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
S: Into<String>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let sticker_set_name = sticker_set_name.into();
|
||||
Self {
|
||||
chat_id,
|
||||
sticker_set_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SetChatStickerSet> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn sticker_set_name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.sticker_set_name = val.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
62
src/requests/payloads/set_chat_title.rs
Normal file
62
src/requests/payloads/set_chat_title.rs
Normal file
|
@ -0,0 +1,62 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
/// Use this method to change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SetChatTitle {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// New chat title, 1-255 characters
|
||||
title: String,
|
||||
}
|
||||
|
||||
impl Method for SetChatTitle {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "setChatTitle";
|
||||
}
|
||||
|
||||
impl json::Payload for SetChatTitle {}
|
||||
|
||||
impl dynamic::Payload for SetChatTitle {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatTitle {
|
||||
pub fn new<C, T>(chat_id: C, title: T) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
T: Into<String>
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let title = title.into();
|
||||
Self {
|
||||
chat_id,
|
||||
title,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SetChatTitle> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.title = val.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
88
src/requests/payloads/set_game_score.rs
Normal file
88
src/requests/payloads/set_game_score.rs
Normal file
|
@ -0,0 +1,88 @@
|
|||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{Message, ChatId},
|
||||
};
|
||||
|
||||
/// Use this method to set the score of the specified user in a game. On success, if the message was sent by the bot, returns the edited Message, otherwise returns True. Returns an error, if the new score is not greater than the user's current score in the chat and force is False.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SetGameScore {
|
||||
/// Unique identifier for the target chat
|
||||
chat_id: ChatId,
|
||||
/// Identifier of the sent message
|
||||
message_id: i32,
|
||||
/// User identifier
|
||||
user_id: i32,
|
||||
/// New score, must be non-negative
|
||||
score: i32,
|
||||
/// Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters
|
||||
force: Option<bool>,
|
||||
/// Pass True, if the game message should not be automatically edited to include the current scoreboard
|
||||
disable_edit_message: Option<bool>,
|
||||
}
|
||||
|
||||
impl Method for SetGameScore {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "setGameScoreInline";
|
||||
}
|
||||
|
||||
impl json::Payload for SetGameScore {}
|
||||
|
||||
impl dynamic::Payload for SetGameScore {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SetGameScore {
|
||||
pub fn new<C>(chat_id: C, message_id: i32, user_id: i32, score: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
chat_id,
|
||||
message_id,
|
||||
user_id,
|
||||
score,
|
||||
force: None,
|
||||
disable_edit_message: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SetGameScore> {
|
||||
pub fn chat_id<C>(mut self, val: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.payload.message_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.payload.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn score(mut self, val: i32) -> Self {
|
||||
self.payload.score = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn force(mut self, val: bool) -> Self {
|
||||
self.payload.force = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_edit_message(mut self, val: bool) -> Self {
|
||||
self.payload.disable_edit_message = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
81
src/requests/payloads/set_game_score_inline.rs
Normal file
81
src/requests/payloads/set_game_score_inline.rs
Normal file
|
@ -0,0 +1,81 @@
|
|||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::Message,
|
||||
};
|
||||
|
||||
/// Use this method to set the score of the specified user in a game. On success, if the message was sent by the bot, returns the edited Message, otherwise returns True. Returns an error, if the new score is not greater than the user's current score in the chat and force is False.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SetGameScoreInline {
|
||||
/// Identifier of the inline message
|
||||
inline_message_id: String,
|
||||
/// User identifier
|
||||
user_id: i32,
|
||||
/// New score, must be non-negative
|
||||
score: i32,
|
||||
/// Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters
|
||||
force: Option<bool>,
|
||||
/// Pass True, if the game message should not be automatically edited to include the current scoreboard
|
||||
disable_edit_message: Option<bool>,
|
||||
}
|
||||
|
||||
impl Method for SetGameScoreInline {
|
||||
type Output = Message;
|
||||
|
||||
const NAME: &'static str = "setGameScore";
|
||||
}
|
||||
|
||||
impl json::Payload for SetGameScoreInline {}
|
||||
|
||||
impl dynamic::Payload for SetGameScoreInline {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl SetGameScoreInline {
|
||||
pub fn new<I>(inline_message_id: I, user_id: i32, score: i32) -> Self
|
||||
where
|
||||
I: Into<String>,
|
||||
{
|
||||
let inline_message_id = inline_message_id.into();
|
||||
Self {
|
||||
inline_message_id,
|
||||
user_id,
|
||||
score,
|
||||
force: None,
|
||||
disable_edit_message: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SetGameScoreInline> {
|
||||
pub fn inline_message_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
{
|
||||
self.payload.inline_message_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.payload.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn score(mut self, val: i32) -> Self {
|
||||
self.payload.score = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn force(mut self, val: bool) -> Self {
|
||||
self.payload.force = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_edit_message(mut self, val: bool) -> Self {
|
||||
self.payload.disable_edit_message = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue