mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
Merge pull request #116 from teloxide/redesign_requests
Redesign requests
This commit is contained in:
commit
e9c356c4df
140 changed files with 5245 additions and 6078 deletions
909
src/bot/api.rs
909
src/bot/api.rs
File diff suppressed because it is too large
Load diff
|
@ -19,7 +19,7 @@ impl Bot {
|
|||
/// use teloxide::types::File as TgFile;
|
||||
/// use tokio::fs::File;
|
||||
/// # use teloxide::RequestError;
|
||||
/// use teloxide::Bot;
|
||||
/// use teloxide::{requests::Request, Bot};
|
||||
///
|
||||
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let bot = Bot::new("TOKEN");
|
||||
|
@ -30,8 +30,8 @@ impl Bot {
|
|||
/// # Ok(()) }
|
||||
/// ```
|
||||
///
|
||||
/// [`get_file`]: crate::bot::Bot::get_file
|
||||
/// [`download_file_stream`]: crate::bot::Bot::download_file_stream
|
||||
/// [`get_file`]: crate::Bot::get_file
|
||||
/// [`download_file_stream`]: crate::Bot::download_file_stream
|
||||
pub async fn download_file<D>(
|
||||
&self,
|
||||
path: &str,
|
||||
|
@ -53,7 +53,7 @@ impl Bot {
|
|||
/// [`get_file`]: crate::bot::Bot::get_file
|
||||
/// [`AsyncWrite`]: tokio::io::AsyncWrite
|
||||
/// [`tokio::fs::File`]: tokio::fs::File
|
||||
/// [`download_file`]: crate::bot::Bot::download_file
|
||||
/// [`download_file`]: crate::Bot::download_file
|
||||
#[cfg(feature = "unstable-stream")]
|
||||
pub async fn download_file_stream(
|
||||
&self,
|
||||
|
|
|
@ -1,102 +0,0 @@
|
|||
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 teloxide::{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 teloxide::{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 teloxide::{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,9 +2,8 @@ use reqwest::Client;
|
|||
|
||||
mod api;
|
||||
mod download;
|
||||
mod execute;
|
||||
|
||||
/// A Telegram bot used to build requests.
|
||||
/// A Telegram bot used to send requests.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Bot {
|
||||
token: String,
|
||||
|
@ -34,12 +33,12 @@ impl Bot {
|
|||
}
|
||||
|
||||
impl Bot {
|
||||
#[inline]
|
||||
// TODO: const fn
|
||||
pub fn token(&self) -> &str {
|
||||
&self.token
|
||||
}
|
||||
|
||||
#[inline]
|
||||
// TODO: const fn
|
||||
pub fn client(&self) -> &Client {
|
||||
&self.client
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ use futures::{stream, Stream, StreamExt};
|
|||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
requests::Request,
|
||||
types::{AllowedUpdate, Update},
|
||||
RequestError,
|
||||
};
|
||||
|
@ -133,7 +134,7 @@ pub fn polling_default(bot: &Bot) -> impl Updater<RequestError> + '_ {
|
|||
///
|
||||
/// See also: [`polling_default`](polling_default).
|
||||
///
|
||||
/// [`GetUpdates`]: crate::requests::payloads::GetUpdates
|
||||
/// [`GetUpdates`]: crate::requests::GetUpdates
|
||||
pub fn polling(
|
||||
bot: &Bot,
|
||||
timeout: Option<Duration>,
|
||||
|
@ -147,9 +148,9 @@ pub fn polling(
|
|||
(allowed_updates, bot, 0),
|
||||
move |(mut allowed_updates, bot, mut offset)| async move {
|
||||
let mut req = bot.get_updates().offset(offset);
|
||||
req.payload.timeout = timeout;
|
||||
req.payload.limit = limit;
|
||||
req.payload.allowed_updates = allowed_updates.take();
|
||||
req.timeout = timeout;
|
||||
req.limit = limit;
|
||||
req.allowed_updates = allowed_updates.take();
|
||||
|
||||
let updates = match req.send().await {
|
||||
Err(err) => vec![Err(err)],
|
||||
|
|
|
@ -3,7 +3,7 @@ pub use download::download_file_stream;
|
|||
|
||||
pub use self::{
|
||||
download::download_file,
|
||||
request::{request_dynamic, request_json, request_multipart},
|
||||
request::{request_json, request_multipart},
|
||||
telegram_response::TelegramResponse,
|
||||
};
|
||||
|
||||
|
|
|
@ -44,44 +44,6 @@ where
|
|||
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>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
|
|
111
src/requests/all/add_sticker_to_set.rs
Normal file
111
src/requests/all/add_sticker_to_set.rs
Normal file
|
@ -0,0 +1,111 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::form_builder::FormBuilder,
|
||||
types::{InputFile, MaskPosition, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
use crate::requests::{Request, ResponseResult};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct AddStickerToSet<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for AddStickerToSet<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"addStickerToSet",
|
||||
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(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AddStickerToSet<'a> {
|
||||
pub(crate) fn new<N, E>(
|
||||
bot: &'a Bot,
|
||||
user_id: i32,
|
||||
name: N,
|
||||
png_sticker: InputFile,
|
||||
emojis: E,
|
||||
) -> Self
|
||||
where
|
||||
N: Into<String>,
|
||||
E: Into<String>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
user_id,
|
||||
name: name.into(),
|
||||
png_sticker,
|
||||
emojis: emojis.into(),
|
||||
mask_position: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.name = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn png_sticker(mut self, val: InputFile) -> Self {
|
||||
self.png_sticker = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn emojis<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.emojis = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn mask_position(mut self, val: MaskPosition) -> Self {
|
||||
self.mask_position = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
107
src/requests/all/answer_callback_query.rs
Normal file
107
src/requests/all/answer_callback_query.rs
Normal file
|
@ -0,0 +1,107 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::True,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, 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
|
||||
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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for AnswerCallbackQuery<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"answerCallbackQuery",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AnswerCallbackQuery<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, callback_query_id: C) -> Self
|
||||
where
|
||||
C: Into<String>,
|
||||
{
|
||||
let callback_query_id = callback_query_id.into();
|
||||
Self {
|
||||
bot,
|
||||
callback_query_id,
|
||||
text: None,
|
||||
show_alert: None,
|
||||
url: None,
|
||||
cache_time: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn callback_query_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.callback_query_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn text<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.text = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn show_alert(mut self, val: bool) -> Self {
|
||||
self.show_alert = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn url<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.url = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn cache_time(mut self, val: i32) -> Self {
|
||||
self.cache_time = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
141
src/requests/all/answer_inline_query.rs
Normal file
141
src/requests/all/answer_inline_query.rs
Normal file
|
@ -0,0 +1,141 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{InlineQueryResult, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct AnswerInlineQuery<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for AnswerInlineQuery<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"answerInlineQuery",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AnswerInlineQuery<'a> {
|
||||
pub(crate) fn new<I, R>(
|
||||
bot: &'a Bot,
|
||||
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 {
|
||||
bot,
|
||||
inline_query_id,
|
||||
results,
|
||||
cache_time: None,
|
||||
is_personal: None,
|
||||
next_offset: None,
|
||||
switch_pm_text: None,
|
||||
switch_pm_parameter: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inline_query_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.inline_query_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn results<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<Vec<InlineQueryResult>>,
|
||||
{
|
||||
self.results = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn cache_time(mut self, val: i32) -> Self {
|
||||
self.cache_time = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
pub fn is_personal(mut self, val: bool) -> Self {
|
||||
self.is_personal = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn next_offset<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.next_offset = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn switch_pm_text<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.switch_pm_text = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn switch_pm_parameter<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.switch_pm_parameter = Some(val.into());
|
||||
self
|
||||
}
|
||||
}
|
89
src/requests/all/answer_pre_checkout_query.rs
Normal file
89
src/requests/all/answer_pre_checkout_query.rs
Normal file
|
@ -0,0 +1,89 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::True,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct AnswerPreCheckoutQuery<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for AnswerPreCheckoutQuery<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"answerPreCheckoutQuery",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AnswerPreCheckoutQuery<'a> {
|
||||
pub(crate) fn new<P>(
|
||||
bot: &'a Bot,
|
||||
pre_checkout_query_id: P,
|
||||
ok: bool,
|
||||
) -> Self
|
||||
where
|
||||
P: Into<String>,
|
||||
{
|
||||
let pre_checkout_query_id = pre_checkout_query_id.into();
|
||||
Self {
|
||||
bot,
|
||||
pre_checkout_query_id,
|
||||
ok,
|
||||
error_message: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pre_checkout_query_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.pre_checkout_query_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ok(mut self, val: bool) -> Self {
|
||||
self.ok = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn error_message<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.error_message = Some(val.into());
|
||||
self
|
||||
}
|
||||
}
|
94
src/requests/all/answer_shipping_query.rs
Normal file
94
src/requests/all/answer_shipping_query.rs
Normal file
|
@ -0,0 +1,94 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ShippingOption, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct AnswerShippingQuery<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for AnswerShippingQuery<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"answerShippingQuery",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AnswerShippingQuery<'a> {
|
||||
pub(crate) fn new<S>(bot: &'a Bot, shipping_query_id: S, ok: bool) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
let shipping_query_id = shipping_query_id.into();
|
||||
Self {
|
||||
bot,
|
||||
shipping_query_id,
|
||||
ok,
|
||||
shipping_options: None,
|
||||
error_message: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shipping_query_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.shipping_query_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ok(mut self, val: bool) -> Self {
|
||||
self.ok = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn shipping_options<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<Vec<ShippingOption>>,
|
||||
{
|
||||
self.shipping_options = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn error_message<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.error_message = Some(val.into());
|
||||
self
|
||||
}
|
||||
}
|
136
src/requests/all/create_new_sticker_set.rs
Normal file
136
src/requests/all/create_new_sticker_set.rs
Normal file
|
@ -0,0 +1,136 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{form_builder::FormBuilder, Request, ResponseResult},
|
||||
types::{InputFile, MaskPosition, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct CreateNewStickerSet<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for CreateNewStickerSet<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"createNewStickerSet",
|
||||
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(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> CreateNewStickerSet<'a> {
|
||||
pub(crate) fn new<N, T, E>(
|
||||
bot: &'a Bot,
|
||||
user_id: i32,
|
||||
name: N,
|
||||
title: T,
|
||||
png_sticker: InputFile,
|
||||
emojis: E,
|
||||
) -> Self
|
||||
where
|
||||
N: Into<String>,
|
||||
T: Into<String>,
|
||||
E: Into<String>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
user_id,
|
||||
name: name.into(),
|
||||
title: title.into(),
|
||||
png_sticker,
|
||||
emojis: emojis.into(),
|
||||
contains_masks: None,
|
||||
mask_position: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.name = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.title = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn png_sticker(mut self, val: InputFile) -> Self {
|
||||
self.png_sticker = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn emojis<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.emojis = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn contains_masks(mut self, val: bool) -> Self {
|
||||
self.contains_masks = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn mask_position(mut self, val: MaskPosition) -> Self {
|
||||
self.mask_position = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
55
src/requests/all/delete_chat_photo.rs
Normal file
55
src/requests/all/delete_chat_photo.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct DeleteChatPhoto<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target channel
|
||||
/// (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for DeleteChatPhoto<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"deleteChatPhoto",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DeleteChatPhoto<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id }
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
57
src/requests/all/delete_chat_sticker_set.rs
Normal file
57
src/requests/all/delete_chat_sticker_set.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, 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::async_trait]
|
||||
impl Request for DeleteChatStickerSet<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"deleteChatStickerSet",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DeleteChatStickerSet<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id }
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
72
src/requests/all/delete_message.rs
Normal file
72
src/requests/all/delete_message.rs
Normal file
|
@ -0,0 +1,72 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct DeleteMessage<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for DeleteMessage<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"deleteMessage",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DeleteMessage<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, message_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
message_id,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.message_id = val;
|
||||
self
|
||||
}
|
||||
}
|
53
src/requests/all/delete_sticker_from_set.rs
Normal file
53
src/requests/all/delete_sticker_from_set.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::True,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct DeleteStickerFromSet<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// File identifier of the sticker
|
||||
sticker: String,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for DeleteStickerFromSet<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"deleteStickerFromSet",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DeleteStickerFromSet<'a> {
|
||||
pub(crate) fn new<S>(bot: &'a Bot, sticker: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
let sticker = sticker.into();
|
||||
Self { bot, sticker }
|
||||
}
|
||||
|
||||
pub fn sticker<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.sticker = val.into();
|
||||
self
|
||||
}
|
||||
}
|
38
src/requests/all/delete_webhook.rs
Normal file
38
src/requests/all/delete_webhook.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::True,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct DeleteWebhook<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for DeleteWebhook<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"deleteWebhook",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DeleteWebhook<'a> {
|
||||
pub(crate) fn new(bot: &'a Bot) -> Self {
|
||||
Self { bot }
|
||||
}
|
||||
}
|
82
src/requests/all/edit_message_caption.rs
Normal file
82
src/requests/all/edit_message_caption.rs
Normal file
|
@ -0,0 +1,82 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message, ParseMode},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct EditMessageCaption<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
#[serde(flatten)]
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for EditMessageCaption<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"editMessageCaption",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> EditMessageCaption<'a> {
|
||||
pub(crate) fn new(
|
||||
bot: &'a Bot,
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
) -> Self {
|
||||
Self {
|
||||
bot,
|
||||
chat_or_inline_message,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
|
||||
self.chat_or_inline_message = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
81
src/requests/all/edit_message_live_location.rs
Normal file
81
src/requests/all/edit_message_live_location.rs
Normal file
|
@ -0,0 +1,81 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct EditMessageLiveLocation<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
#[serde(flatten)]
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for EditMessageLiveLocation<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"editMessageLiveLocation",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> EditMessageLiveLocation<'a> {
|
||||
pub(crate) fn new(
|
||||
bot: &'a Bot,
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
latitude: f32,
|
||||
longitude: f32,
|
||||
) -> Self {
|
||||
Self {
|
||||
bot,
|
||||
chat_or_inline_message,
|
||||
latitude,
|
||||
longitude,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
|
||||
self.chat_or_inline_message = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn latitude(mut self, val: f32) -> Self {
|
||||
self.latitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn longitude(mut self, val: f32) -> Self {
|
||||
self.longitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
94
src/requests/all/edit_message_media.rs
Normal file
94
src/requests/all/edit_message_media.rs
Normal file
|
@ -0,0 +1,94 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{form_builder::FormBuilder, Request, ResponseResult},
|
||||
types::{ChatOrInlineMessage, InlineKeyboardMarkup, InputMedia, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct EditMessageMedia<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
#[serde(flatten)]
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for EditMessageMedia<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
let mut params = FormBuilder::new();
|
||||
|
||||
match &self.chat_or_inline_message {
|
||||
ChatOrInlineMessage::Chat {
|
||||
chat_id,
|
||||
message_id,
|
||||
} => {
|
||||
params = params
|
||||
.add("chat_id", chat_id)
|
||||
.add("message_id", message_id);
|
||||
}
|
||||
ChatOrInlineMessage::Inline { inline_message_id } => {
|
||||
params = params.add("inline_message_id", inline_message_id);
|
||||
}
|
||||
}
|
||||
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"editMessageMedia",
|
||||
params
|
||||
.add("media", &self.media)
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> EditMessageMedia<'a> {
|
||||
pub(crate) fn new(
|
||||
bot: &'a Bot,
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
media: InputMedia,
|
||||
) -> Self {
|
||||
Self {
|
||||
bot,
|
||||
chat_or_inline_message,
|
||||
media,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
|
||||
self.chat_or_inline_message = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn media(mut self, val: InputMedia) -> Self {
|
||||
self.media = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
62
src/requests/all/edit_message_reply_markup.rs
Normal file
62
src/requests/all/edit_message_reply_markup.rs
Normal file
|
@ -0,0 +1,62 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct EditMessageReplyMarkup<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
#[serde(flatten)]
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
|
||||
/// A JSON-serialized object for an inline keyboard.
|
||||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for EditMessageReplyMarkup<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"editMessageReplyMarkup",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> EditMessageReplyMarkup<'a> {
|
||||
pub(crate) fn new(
|
||||
bot: &'a Bot,
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
) -> Self {
|
||||
Self {
|
||||
bot,
|
||||
chat_or_inline_message,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
|
||||
self.chat_or_inline_message = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
94
src/requests/all/edit_message_text.rs
Normal file
94
src/requests/all/edit_message_text.rs
Normal file
|
@ -0,0 +1,94 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message, ParseMode},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct EditMessageText<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
#[serde(flatten)]
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for EditMessageText<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"editMessageText",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> EditMessageText<'a> {
|
||||
pub(crate) fn new<T>(
|
||||
bot: &'a Bot,
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
text: T,
|
||||
) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_or_inline_message,
|
||||
text: text.into(),
|
||||
parse_mode: None,
|
||||
disable_web_page_preview: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
|
||||
self.chat_or_inline_message = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn text<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.text = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_web_page_preview(mut self, val: bool) -> Self {
|
||||
self.disable_web_page_preview = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
62
src/requests/all/export_chat_invite_link.rs
Normal file
62
src/requests/all/export_chat_invite_link.rs
Normal file
|
@ -0,0 +1,62 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::ChatId,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct ExportChatInviteLink<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target channel
|
||||
/// (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for ExportChatInviteLink<'_> {
|
||||
type Output = String;
|
||||
|
||||
async fn send(&self) -> ResponseResult<String> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"exportChatInviteLink",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExportChatInviteLink<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id }
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,81 +1,94 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to forward messages of any kind. On success, the sent Message is returned.
|
||||
/// 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)
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
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)
|
||||
chat_id: ChatId,
|
||||
/// Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
|
||||
/// 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.
|
||||
/// 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 {
|
||||
#[async_trait::async_trait]
|
||||
impl Request 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())
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"forwardMessage",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl ForwardMessage {
|
||||
pub fn new<C, F>(chat_id: C, from_chat_id: F, message_id: i32) -> Self
|
||||
impl<'a> ForwardMessage<'a> {
|
||||
pub(crate) fn new<C, F>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
from_chat_id: F,
|
||||
message_id: i32,
|
||||
) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
F: Into<ChatId>
|
||||
F: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let from_chat_id = from_chat_id.into();
|
||||
Self {
|
||||
bot,
|
||||
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>
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self.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>
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.payload.from_chat_id = val.into();
|
||||
self.from_chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.payload.message_id = val;
|
||||
self.message_id = val;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
55
src/requests/all/get_chat.rs
Normal file
55
src/requests/all/get_chat.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{Chat, ChatId},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, 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::async_trait]
|
||||
impl Request for GetChat<'_> {
|
||||
type Output = Chat;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Chat> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getChat",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetChat<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id }
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
57
src/requests/all/get_chat_administrators.rs
Normal file
57
src/requests/all/get_chat_administrators.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, ChatMember},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, 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::async_trait]
|
||||
impl Request for GetChatAdministrators<'_> {
|
||||
type Output = Vec<ChatMember>;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Vec<ChatMember>> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getChatAdministrators",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetChatAdministrators<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id }
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
65
src/requests/all/get_chat_member.rs
Normal file
65
src/requests/all/get_chat_member.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, ChatMember},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, 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::async_trait]
|
||||
impl Request for GetChatMember<'_> {
|
||||
type Output = ChatMember;
|
||||
|
||||
async fn send(&self) -> ResponseResult<ChatMember> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getChatMember",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetChatMember<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, user_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
user_id,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
}
|
54
src/requests/all/get_chat_members_count.rs
Normal file
54
src/requests/all/get_chat_members_count.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::ChatId,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to get the number of members in a chat. Returns Int on
|
||||
/// success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[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::async_trait]
|
||||
impl Request for GetChatMembersCount<'_> {
|
||||
type Output = i32;
|
||||
|
||||
async fn send(&self) -> ResponseResult<i32> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getChatMembersCount",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetChatMembersCount<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id }
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::File,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to get basic info about a file and prepare it for
|
||||
|
@ -25,43 +27,46 @@ use crate::{
|
|||
/// [`File`]: crate::types::file
|
||||
/// [`GetFile`]: self::GetFile
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct GetFile {
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetFile<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// File identifier to get info about
|
||||
pub file_id: String,
|
||||
}
|
||||
|
||||
impl Method for GetFile {
|
||||
#[async_trait::async_trait]
|
||||
impl Request 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())
|
||||
async fn send(&self) -> ResponseResult<File> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getFile",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetFile {
|
||||
pub fn new<F>(file_id: F) -> Self
|
||||
impl<'a> GetFile<'a> {
|
||||
pub(crate) fn new<F>(bot: &'a Bot, file_id: F) -> Self
|
||||
where
|
||||
F: Into<String>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
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.file_id = value.into();
|
||||
self
|
||||
}
|
||||
}
|
66
src/requests/all/get_game_high_scores.rs
Normal file
66
src/requests/all/get_game_high_scores.rs
Normal file
|
@ -0,0 +1,66 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatOrInlineMessage, GameHighScore},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct GetGameHighScores<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
#[serde(flatten)]
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
|
||||
/// Target user id
|
||||
user_id: i32,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for GetGameHighScores<'_> {
|
||||
type Output = Vec<GameHighScore>;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Vec<GameHighScore>> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getGameHighScores",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetGameHighScores<'a> {
|
||||
pub(crate) fn new(
|
||||
bot: &'a Bot,
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
user_id: i32,
|
||||
) -> Self {
|
||||
Self {
|
||||
bot,
|
||||
chat_or_inline_message,
|
||||
user_id,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
|
||||
self.chat_or_inline_message = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
}
|
39
src/requests/all/get_me.rs
Normal file
39
src/requests/all/get_me.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::User,
|
||||
Bot,
|
||||
};
|
||||
use serde::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
|
||||
#[derive(Debug, Clone, Copy, Serialize)]
|
||||
pub struct GetMe<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for GetMe<'_> {
|
||||
type Output = User;
|
||||
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
async fn send(&self) -> ResponseResult<User> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getMe",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetMe<'a> {
|
||||
pub(crate) fn new(bot: &'a Bot) -> Self {
|
||||
Self { bot }
|
||||
}
|
||||
}
|
53
src/requests/all/get_sticker_set.rs
Normal file
53
src/requests/all/get_sticker_set.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::StickerSet,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to get a sticker set. On success, a StickerSet object is
|
||||
/// returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetStickerSet<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Name of the sticker set
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for GetStickerSet<'_> {
|
||||
type Output = StickerSet;
|
||||
|
||||
async fn send(&self) -> ResponseResult<StickerSet> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getStickerSet",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetStickerSet<'a> {
|
||||
pub(crate) fn new<N>(bot: &'a Bot, name: N) -> Self
|
||||
where
|
||||
N: Into<String>,
|
||||
{
|
||||
let name = name.into();
|
||||
Self { bot, name }
|
||||
}
|
||||
|
||||
pub fn name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.name = val.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::Update,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{AllowedUpdate, Update},
|
||||
Bot,
|
||||
};
|
||||
use crate::types::AllowedUpdate;
|
||||
|
||||
/// Use this method to receive incoming updates using long polling ([wiki]).
|
||||
/// An array ([`Vec`]) of [`Update`]s is returned.
|
||||
|
@ -18,8 +19,11 @@ use crate::types::AllowedUpdate;
|
|||
/// [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 {
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetUpdates<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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
|
||||
|
@ -61,44 +65,44 @@ pub struct GetUpdates {
|
|||
pub allowed_updates: Option<Vec<AllowedUpdate>>,
|
||||
}
|
||||
|
||||
impl Method for GetUpdates {
|
||||
#[async_trait::async_trait]
|
||||
impl Request 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())
|
||||
async fn send(&self) -> ResponseResult<Vec<Update>> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getUpdates",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetUpdates {
|
||||
pub fn new() -> Self {
|
||||
impl<'a> GetUpdates<'a> {
|
||||
pub(crate) fn new(bot: &'a Bot) -> Self {
|
||||
Self {
|
||||
bot,
|
||||
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.offset = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn limit(mut self, value: u8) -> Self {
|
||||
self.payload.limit = Some(value);
|
||||
self.limit = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn timeout(mut self, value: u32) -> Self {
|
||||
self.payload.timeout = Some(value);
|
||||
self.timeout = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -106,7 +110,7 @@ impl json::Request<'_, GetUpdates> {
|
|||
where
|
||||
T: Into<Vec<AllowedUpdate>>, // TODO: into or other trait?
|
||||
{
|
||||
self.payload.allowed_updates = Some(value.into());
|
||||
self.allowed_updates = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
67
src/requests/all/get_user_profile_photos.rs
Normal file
67
src/requests/all/get_user_profile_photos.rs
Normal file
|
@ -0,0 +1,67 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::UserProfilePhotos,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct GetUserProfilePhotos<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for GetUserProfilePhotos<'_> {
|
||||
type Output = UserProfilePhotos;
|
||||
|
||||
async fn send(&self) -> ResponseResult<UserProfilePhotos> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getUserProfilePhotos",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetUserProfilePhotos<'a> {
|
||||
pub(crate) fn new(bot: &'a Bot, user_id: i32) -> Self {
|
||||
Self {
|
||||
bot,
|
||||
user_id,
|
||||
offset: None,
|
||||
limit: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn offset(mut self, val: i32) -> Self {
|
||||
self.offset = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn limit(mut self, val: i32) -> Self {
|
||||
self.limit = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
38
src/requests/all/get_webhook_info.rs
Normal file
38
src/requests/all/get_webhook_info.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::WebhookInfo,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct GetWebhookInfo<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for GetWebhookInfo<'_> {
|
||||
type Output = WebhookInfo;
|
||||
|
||||
async fn send(&self) -> ResponseResult<WebhookInfo> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getWebhookInfo",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetWebhookInfo<'a> {
|
||||
pub(crate) fn new(bot: &'a Bot) -> Self {
|
||||
Self { bot }
|
||||
}
|
||||
}
|
78
src/requests/all/kick_chat_member.rs
Normal file
78
src/requests/all/kick_chat_member.rs
Normal file
|
@ -0,0 +1,78 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to kick a user from a group, a supergroup or a channel. In
|
||||
/// the case of supergroups and channels, the user will not be able to return to
|
||||
/// 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, 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)
|
||||
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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for KickChatMember<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"kickChatMember",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> KickChatMember<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, user_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
user_id,
|
||||
until_date: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn until_date(mut self, val: i32) -> Self {
|
||||
self.until_date = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
54
src/requests/all/leave_chat.rs
Normal file
54
src/requests/all/leave_chat.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, 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::async_trait]
|
||||
impl Request for LeaveChat<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"leaveChat",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> LeaveChat<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id }
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
132
src/requests/all/mod.rs
Normal file
132
src/requests/all/mod.rs
Normal file
|
@ -0,0 +1,132 @@
|
|||
mod add_sticker_to_set;
|
||||
mod answer_callback_query;
|
||||
mod answer_inline_query;
|
||||
mod answer_pre_checkout_query;
|
||||
mod answer_shipping_query;
|
||||
mod create_new_sticker_set;
|
||||
mod delete_chat_photo;
|
||||
mod delete_chat_sticker_set;
|
||||
mod delete_message;
|
||||
mod delete_sticker_from_set;
|
||||
mod delete_webhook;
|
||||
mod edit_message_caption;
|
||||
mod edit_message_live_location;
|
||||
mod edit_message_media;
|
||||
mod edit_message_reply_markup;
|
||||
mod edit_message_text;
|
||||
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_game_high_scores;
|
||||
mod get_me;
|
||||
mod get_sticker_set;
|
||||
mod get_updates;
|
||||
mod get_user_profile_photos;
|
||||
mod get_webhook_info;
|
||||
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_game;
|
||||
mod send_invoice;
|
||||
mod send_location;
|
||||
mod send_media_group;
|
||||
mod send_message;
|
||||
mod send_photo;
|
||||
mod send_poll;
|
||||
mod send_sticker;
|
||||
mod send_venue;
|
||||
mod send_video;
|
||||
mod send_video_note;
|
||||
mod send_voice;
|
||||
mod set_chat_administrator_custom_title;
|
||||
mod set_chat_description;
|
||||
mod set_chat_permissions;
|
||||
mod set_chat_photo;
|
||||
mod set_chat_sticker_set;
|
||||
mod set_chat_title;
|
||||
mod set_game_score;
|
||||
mod set_sticker_position_in_set;
|
||||
mod set_webhook;
|
||||
mod stop_message_live_location;
|
||||
mod stop_poll;
|
||||
mod unban_chat_member;
|
||||
mod unpin_chat_message;
|
||||
mod upload_sticker_file;
|
||||
|
||||
pub use add_sticker_to_set::*;
|
||||
pub use answer_callback_query::*;
|
||||
pub use answer_inline_query::*;
|
||||
pub use answer_pre_checkout_query::*;
|
||||
pub use answer_shipping_query::*;
|
||||
pub use create_new_sticker_set::*;
|
||||
pub use delete_chat_photo::*;
|
||||
pub use delete_chat_sticker_set::*;
|
||||
pub use delete_message::*;
|
||||
pub use delete_sticker_from_set::*;
|
||||
pub use delete_webhook::*;
|
||||
pub use edit_message_caption::*;
|
||||
pub use edit_message_live_location::*;
|
||||
pub use edit_message_media::*;
|
||||
pub use edit_message_reply_markup::*;
|
||||
pub use edit_message_text::*;
|
||||
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_game_high_scores::*;
|
||||
pub use get_me::*;
|
||||
pub use get_sticker_set::*;
|
||||
pub use get_updates::*;
|
||||
pub use get_user_profile_photos::*;
|
||||
pub use get_webhook_info::*;
|
||||
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_game::*;
|
||||
pub use send_invoice::*;
|
||||
pub use send_location::*;
|
||||
pub use send_media_group::*;
|
||||
pub use send_message::*;
|
||||
pub use send_photo::*;
|
||||
pub use send_poll::*;
|
||||
pub use send_sticker::*;
|
||||
pub use send_venue::*;
|
||||
pub use send_video::*;
|
||||
pub use send_video_note::*;
|
||||
pub use send_voice::*;
|
||||
pub use set_chat_administrator_custom_title::*;
|
||||
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 set_game_score::*;
|
||||
pub use set_sticker_position_in_set::*;
|
||||
pub use set_webhook::*;
|
||||
pub use std::pin::Pin;
|
||||
pub use stop_message_live_location::*;
|
||||
pub use stop_poll::*;
|
||||
pub use unban_chat_member::*;
|
||||
pub use unpin_chat_message::*;
|
||||
pub use upload_sticker_file::*;
|
77
src/requests/all/pin_chat_message.rs
Normal file
77
src/requests/all/pin_chat_message.rs
Normal file
|
@ -0,0 +1,77 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct PinChatMessage<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for PinChatMessage<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"pinChatMessage",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PinChatMessage<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, message_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
message_id,
|
||||
disable_notification: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.message_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,23 +1,34 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user. Returns True on success.
|
||||
/// 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)
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct PromoteChatMember<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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
|
||||
/// 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
|
||||
/// 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>,
|
||||
|
@ -27,31 +38,36 @@ pub struct PromoteChatMember {
|
|||
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)
|
||||
/// 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 {
|
||||
#[async_trait::async_trait]
|
||||
impl Request 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())
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"promoteChatMember",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl PromoteChatMember {
|
||||
pub fn new<C>(chat_id: C, user_id: i32) -> Self
|
||||
impl<'a> PromoteChatMember<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, user_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
user_id,
|
||||
can_change_info: None,
|
||||
|
@ -64,60 +80,57 @@ impl PromoteChatMember {
|
|||
can_promote_members: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, PromoteChatMember> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.payload.user_id = val;
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_change_info(mut self, val: bool) -> Self {
|
||||
self.payload.can_change_info = Some(val);
|
||||
self.can_change_info = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_post_messages(mut self, val: bool) -> Self {
|
||||
self.payload.can_post_messages = Some(val);
|
||||
self.can_post_messages = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_edit_messages(mut self, val: bool) -> Self {
|
||||
self.payload.can_edit_messages = Some(val);
|
||||
self.can_edit_messages = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_delete_messages(mut self, val: bool) -> Self {
|
||||
self.payload.can_delete_messages = Some(val);
|
||||
self.can_delete_messages = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_invite_users(mut self, val: bool) -> Self {
|
||||
self.payload.can_invite_users = Some(val);
|
||||
self.can_invite_users = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_restrict_members(mut self, val: bool) -> Self {
|
||||
self.payload.can_restrict_members = Some(val);
|
||||
self.can_restrict_members = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_pin_messages(mut self, val: bool) -> Self {
|
||||
self.payload.can_pin_messages = Some(val);
|
||||
self.can_pin_messages = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_promote_members(mut self, val: bool) -> Self {
|
||||
self.payload.can_promote_members = Some(val);
|
||||
self.can_promote_members = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
90
src/requests/all/restrict_chat_member.rs
Normal file
90
src/requests/all/restrict_chat_member.rs
Normal file
|
@ -0,0 +1,90 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, ChatPermissions, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to restrict a user in a supergroup. The bot must be an
|
||||
/// administrator in the supergroup for this to work and must have the
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct RestrictChatMember<'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,
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for RestrictChatMember<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"restrictChatMember",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RestrictChatMember<'a> {
|
||||
pub(crate) fn new<C>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
user_id: i32,
|
||||
permissions: ChatPermissions,
|
||||
) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
user_id,
|
||||
permissions,
|
||||
until_date: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn permissions(mut self, val: ChatPermissions) -> Self {
|
||||
self.permissions = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn until_date(mut self, val: i32) -> Self {
|
||||
self.until_date = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use reqwest::multipart::Form;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, form_builder::FormBuilder, multipart, Method},
|
||||
network,
|
||||
requests::{form_builder::FormBuilder, Request, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send animation files (GIF or H.264/MPEG-4 AVC video
|
||||
|
@ -14,8 +15,11 @@ use crate::{
|
|||
/// 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 {
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendAnimation<'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,
|
||||
|
@ -57,42 +61,40 @@ pub struct SendAnimation {
|
|||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendAnimation {
|
||||
#[async_trait::async_trait]
|
||||
impl Request 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()
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendAnimation",
|
||||
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(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
impl<'a> SendAnimation<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, animation: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
animation,
|
||||
duration: None,
|
||||
|
@ -106,32 +108,30 @@ impl SendAnimation {
|
|||
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.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn duration(mut self, value: u32) -> Self {
|
||||
self.payload.duration = Some(value);
|
||||
self.duration = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn width(mut self, value: u32) -> Self {
|
||||
self.payload.width = Some(value);
|
||||
self.width = Some(value);
|
||||
self
|
||||
}
|
||||
pub fn height(mut self, value: u32) -> Self {
|
||||
self.payload.height = Some(value);
|
||||
self.height = Some(value);
|
||||
self
|
||||
}
|
||||
pub fn thumb(mut self, value: InputFile) -> Self {
|
||||
self.payload.thumb = Some(value);
|
||||
self.thumb = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -139,26 +139,26 @@ impl multipart::Request<'_, SendAnimation> {
|
|||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.caption = Some(value.into());
|
||||
self.caption = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn parse_mode(mut self, value: ParseMode) -> Self {
|
||||
self.payload.parse_mode = Some(value);
|
||||
self.parse_mode = Some(value);
|
||||
self
|
||||
}
|
||||
pub fn disable_notification(mut self, value: bool) -> Self {
|
||||
self.payload.disable_notification = Some(value);
|
||||
self.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.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.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
174
src/requests/all/send_audio.rs
Normal file
174
src/requests/all/send_audio.rs
Normal file
|
@ -0,0 +1,174 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{form_builder::FormBuilder, Request, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send audio files, if you want Telegram clients to display
|
||||
/// them in the music player. Your audio must be in the .MP3 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, Clone, Serialize)]
|
||||
pub struct SendAudio<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SendAudio<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendAudio",
|
||||
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(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendAudio<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, audio: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn audio(mut self, val: InputFile) -> Self {
|
||||
self.audio = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn duration(mut self, val: i32) -> Self {
|
||||
self.duration = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn performer<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.performer = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.title = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn thumb(mut self, val: InputFile) -> Self {
|
||||
self.thumb = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
113
src/requests/all/send_chat_action.rs
Normal file
113
src/requests/all/send_chat_action.rs
Normal file
|
@ -0,0 +1,113 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method when you need to tell the user that something is happening
|
||||
/// on the bot's side. The status is set for 5 seconds or less (when a message
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct SendChatAction<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target channel
|
||||
/// (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
|
||||
/// Type of action to broadcast.
|
||||
action: SendChatActionKind,
|
||||
}
|
||||
|
||||
/// A type of action used in [`SendChatAction`].
|
||||
///
|
||||
/// [`SendChatAction`]: crate::requests::SendChatAction
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum SendChatActionKind {
|
||||
/// For [text messages](crate::Bot::send_message).
|
||||
Typing,
|
||||
|
||||
/// For [photos](crate::Bot::send_photo).
|
||||
UploadPhoto,
|
||||
|
||||
/// For [videos](crate::Bot::send_video).
|
||||
RecordVideo,
|
||||
|
||||
/// For [videos](crate::Bot::send_video).
|
||||
UploadVideo,
|
||||
|
||||
/// For [audio files](crate::Bot::send_audio).
|
||||
RecordAudio,
|
||||
|
||||
/// For [audio files](crate::Bot::send_audio).
|
||||
UploadAudio,
|
||||
|
||||
/// For [general files](crate::Bot::send_document).
|
||||
UploadDocument,
|
||||
|
||||
/// For [location data](crate::Bot::send_location).
|
||||
FindLocation,
|
||||
|
||||
/// For [video notes](crate::Bot::send_video_note).
|
||||
RecordVideoNote,
|
||||
|
||||
/// For [video notes](crate::Bot::send_video_note).
|
||||
UploadVideoNote,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SendChatAction<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendChatAction",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendChatAction<'a> {
|
||||
pub(crate) fn new<C>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
action: SendChatActionKind,
|
||||
) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
action,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn action(mut self, val: SendChatActionKind) -> Self {
|
||||
self.action = val;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,15 +1,22 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, ReplyMarkup, Message},
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send phone contacts. On success, the sent Message is returned.
|
||||
/// 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)
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendContact<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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,
|
||||
|
@ -19,39 +26,49 @@ pub struct SendContact {
|
|||
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.
|
||||
/// 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.
|
||||
/// 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 {
|
||||
#[async_trait::async_trait]
|
||||
impl Request 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())
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendContact",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendContact {
|
||||
pub fn new<C, P, F>(chat_id: C, phone_number: P, first_name: F) -> Self
|
||||
impl<'a> SendContact<'a> {
|
||||
pub(crate) fn new<C, P, F>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
phone_number: P,
|
||||
first_name: F,
|
||||
) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
P: Into<String>,
|
||||
F: Into<String>
|
||||
F: Into<String>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let phone_number = phone_number.into();
|
||||
let first_name = first_name.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
phone_number,
|
||||
first_name,
|
||||
|
@ -62,62 +79,59 @@ impl SendContact {
|
|||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SendContact> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn phone_number<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.phone_number = val.into();
|
||||
self.phone_number = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn first_name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.first_name = val.into();
|
||||
self.first_name = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn last_name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.last_name = Some(val.into());
|
||||
self.last_name = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn vcard<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.vcard = Some(val.into());
|
||||
self.vcard = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self.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.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
140
src/requests/all/send_document.rs
Normal file
140
src/requests/all/send_document.rs
Normal file
|
@ -0,0 +1,140 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{form_builder::FormBuilder, Request, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct SendDocument<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SendDocument<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendDocument",
|
||||
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(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendDocument<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, document: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
document,
|
||||
thumb: None,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn document(mut self, val: InputFile) -> Self {
|
||||
self.document = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn thumb(mut self, val: InputFile) -> Self {
|
||||
self.thumb = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,47 +1,58 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{InlineKeyboardMarkup, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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 {
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendGame<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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.
|
||||
/// 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.
|
||||
/// 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.
|
||||
/// 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 {
|
||||
#[async_trait::async_trait]
|
||||
impl Request 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())
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendGame",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendGame {
|
||||
pub fn new<G>(chat_id: i32, game_short_name: G) -> Self
|
||||
impl<'a> SendGame<'a> {
|
||||
pub(crate) fn new<G>(bot: &'a Bot, chat_id: i32, game_short_name: G) -> Self
|
||||
where
|
||||
G: Into<String>
|
||||
G: Into<String>,
|
||||
{
|
||||
let game_short_name = game_short_name.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
game_short_name,
|
||||
disable_notification: None,
|
||||
|
@ -49,35 +60,32 @@ impl SendGame {
|
|||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SendGame> {
|
||||
pub fn chat_id(mut self, val: i32) -> Self {
|
||||
self.payload.chat_id = val;
|
||||
self.chat_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn game_short_name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.game_short_name = val.into();
|
||||
self.game_short_name = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self.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.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +1,45 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{LabeledPrice, InlineKeyboardMarkup, Message},
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{InlineKeyboardMarkup, LabeledPrice, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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 {
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendInvoice<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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.
|
||||
/// 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
|
||||
/// 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.)
|
||||
/// 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.
|
||||
/// 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.
|
||||
/// 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>,
|
||||
|
@ -39,9 +51,11 @@ pub struct SendInvoice {
|
|||
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
|
||||
/// 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
|
||||
/// 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>,
|
||||
|
@ -49,31 +63,36 @@ pub struct SendInvoice {
|
|||
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.
|
||||
/// 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.
|
||||
/// 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 {
|
||||
#[async_trait::async_trait]
|
||||
impl Request 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())
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendInvoice",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendInvoice {
|
||||
impl<'a> SendInvoice<'a> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new<T, D, Pl, Pt, S, C, Pr>(
|
||||
pub(crate) fn new<T, D, Pl, Pt, S, C, Pr>(
|
||||
bot: &'a Bot,
|
||||
chat_id: i32,
|
||||
title: T,
|
||||
description: D,
|
||||
|
@ -81,7 +100,7 @@ impl SendInvoice {
|
|||
provider_token: Pt,
|
||||
start_parameter: S,
|
||||
currency: C,
|
||||
prices: Pr
|
||||
prices: Pr,
|
||||
) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
|
@ -90,7 +109,7 @@ impl SendInvoice {
|
|||
Pt: Into<String>,
|
||||
S: Into<String>,
|
||||
C: Into<String>,
|
||||
Pr: Into<Vec<LabeledPrice>>
|
||||
Pr: Into<Vec<LabeledPrice>>,
|
||||
{
|
||||
let title = title.into();
|
||||
let description = description.into();
|
||||
|
@ -100,6 +119,7 @@ impl SendInvoice {
|
|||
let currency = currency.into();
|
||||
let prices = prices.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
title,
|
||||
description,
|
||||
|
@ -125,150 +145,147 @@ impl SendInvoice {
|
|||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SendInvoice> {
|
||||
pub fn chat_id(mut self, val: i32) -> Self {
|
||||
self.payload.chat_id = val;
|
||||
self.chat_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.title = val.into();
|
||||
self.title = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn description<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.description = val.into();
|
||||
self.description = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn payload<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.payload = val.into();
|
||||
self.payload = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn provider_token<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.provider_token = val.into();
|
||||
self.provider_token = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn start_parameter<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.start_parameter = val.into();
|
||||
self.start_parameter = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn currency<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.currency = val.into();
|
||||
self.currency = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn prices<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<Vec<LabeledPrice>>
|
||||
T: Into<Vec<LabeledPrice>>,
|
||||
{
|
||||
self.payload.prices = val.into();
|
||||
self.prices = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn provider_data<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.provider_data = Some(val.into());
|
||||
self.provider_data = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo_url<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.photo_url = Some(val.into());
|
||||
self.photo_url = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo_size(mut self, val: i32) -> Self {
|
||||
self.payload.photo_size = Some(val);
|
||||
self.photo_size = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo_width(mut self, val: i32) -> Self {
|
||||
self.payload.photo_width = Some(val);
|
||||
self.photo_width = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo_height(mut self, val: i32) -> Self {
|
||||
self.payload.photo_height = Some(val);
|
||||
self.photo_height = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn need_name(mut self, val: bool) -> Self {
|
||||
self.payload.need_name = Some(val);
|
||||
self.need_name = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn need_phone_number(mut self, val: bool) -> Self {
|
||||
self.payload.need_phone_number = Some(val);
|
||||
self.need_phone_number = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn need_email(mut self, val: bool) -> Self {
|
||||
self.payload.need_email = Some(val);
|
||||
self.need_email = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn need_shipping_address(mut self, val: bool) -> Self {
|
||||
self.payload.need_shipping_address = Some(val);
|
||||
self.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.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.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.is_flexible = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self.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.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
@ -1,51 +1,69 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, ReplyMarkup, Message},
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send point on the map. On success, the sent Message is returned.
|
||||
/// 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)
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendLocation<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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.
|
||||
/// 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.
|
||||
/// 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.
|
||||
/// 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 {
|
||||
#[async_trait::async_trait]
|
||||
impl Request 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())
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendLocation",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendLocation {
|
||||
pub fn new<C>(chat_id: C, latitude: f32, longitude: f32) -> Self
|
||||
impl<'a> SendLocation<'a> {
|
||||
pub(crate) fn new<C>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
latitude: f32,
|
||||
longitude: f32,
|
||||
) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
latitude,
|
||||
longitude,
|
||||
|
@ -55,45 +73,42 @@ impl SendLocation {
|
|||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SendLocation> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn latitude(mut self, val: f32) -> Self {
|
||||
self.payload.latitude = val;
|
||||
self.latitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn longitude(mut self, val: f32) -> Self {
|
||||
self.payload.longitude = val;
|
||||
self.longitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn live_period(mut self, val: i64) -> Self {
|
||||
self.payload.live_period = Some(val);
|
||||
self.live_period = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self.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.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
93
src/requests/all/send_media_group.rs
Normal file
93
src/requests/all/send_media_group.rs
Normal file
|
@ -0,0 +1,93 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{form_builder::FormBuilder, Request, ResponseResult},
|
||||
types::{ChatId, InputMedia, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct SendMediaGroup<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SendMediaGroup<'_> {
|
||||
type Output = Vec<Message>;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Vec<Message>> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendMediaGroup",
|
||||
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(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendMediaGroup<'a> {
|
||||
pub(crate) fn new<C, M>(bot: &'a Bot, 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 {
|
||||
bot,
|
||||
chat_id,
|
||||
media,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn media<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<Vec<InputMedia>>,
|
||||
{
|
||||
self.media = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message, ParseMode, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send text messages.
|
||||
|
@ -11,8 +13,11 @@ use crate::{
|
|||
///
|
||||
/// [`Message`]: crate::types::Message
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SendMessage {
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendMessage<'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,
|
||||
|
@ -39,27 +44,29 @@ pub struct SendMessage {
|
|||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
impl Method for SendMessage {
|
||||
#[async_trait::async_trait]
|
||||
impl Request 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())
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendMessage",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendMessage {
|
||||
pub fn new<C, T>(chat_id: C, text: T) -> Self
|
||||
impl<'a> SendMessage<'a> {
|
||||
pub(crate) fn new<C, T>(bot: &'a Bot, chat_id: C, text: T) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
T: Into<String>, // TODO: into?
|
||||
T: Into<String>,
|
||||
{
|
||||
SendMessage {
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
text: text.into(),
|
||||
parse_mode: None,
|
||||
|
@ -69,42 +76,40 @@ impl SendMessage {
|
|||
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.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn text<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>, // TODO: into?
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.text = value.into();
|
||||
self.text = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, value: ParseMode) -> Self {
|
||||
self.payload.parse_mode = Some(value);
|
||||
self.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.disable_web_page_preview = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, value: bool) -> Self {
|
||||
self.payload.disable_notification = Some(value);
|
||||
self.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.reply_to_message_id = Some(value);
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -112,7 +117,7 @@ impl json::Request<'_, SendMessage> {
|
|||
where
|
||||
T: Into<ReplyMarkup>,
|
||||
{
|
||||
self.payload.reply_markup = Some(value.into());
|
||||
self.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
122
src/requests/all/send_photo.rs
Normal file
122
src/requests/all/send_photo.rs
Normal file
|
@ -0,0 +1,122 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{form_builder::FormBuilder, Request, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send photos. On success, the sent Message is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendPhoto<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SendPhoto<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendPhoto",
|
||||
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(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendPhoto<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, photo: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
photo,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo(mut self, val: InputFile) -> Self {
|
||||
self.photo = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,53 +1,71 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, ReplyMarkup, Message},
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send a native poll. A native poll can't be sent to a private chat. On success, the sent Message is returned.
|
||||
/// 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.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendPoll<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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.
|
||||
/// 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.
|
||||
/// 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 {
|
||||
#[async_trait::async_trait]
|
||||
impl Request 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())
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendPoll",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendPoll {
|
||||
pub fn new<C, Q, O>(chat_id: C, question: Q, options: O) -> Self
|
||||
impl<'a> SendPoll<'a> {
|
||||
pub(crate) fn new<C, Q, O>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
question: Q,
|
||||
options: O,
|
||||
) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
Q: Into<String>,
|
||||
O: Into<Vec<String>>
|
||||
O: Into<Vec<String>>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let question = question.into();
|
||||
let options = options.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
question,
|
||||
options,
|
||||
|
@ -56,46 +74,43 @@ impl SendPoll {
|
|||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SendPoll> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn question<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.question = val.into();
|
||||
self.question = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn options<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<Vec<String>>
|
||||
T: Into<Vec<String>>,
|
||||
{
|
||||
self.payload.options = val.into();
|
||||
self.options = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self.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.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
100
src/requests/all/send_sticker.rs
Normal file
100
src/requests/all/send_sticker.rs
Normal file
|
@ -0,0 +1,100 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{form_builder::FormBuilder, Request, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct SendSticker<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SendSticker<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendSticker",
|
||||
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(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendSticker<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, sticker: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
sticker,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn sticker(mut self, val: InputFile) -> Self {
|
||||
self.sticker = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,15 +1,22 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{ChatId, ReplyMarkup, Message},
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send information about a venue. On success, the sent Message is returned.
|
||||
/// 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)
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendVenue<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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,
|
||||
|
@ -21,41 +28,55 @@ pub struct SendVenue {
|
|||
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 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.
|
||||
/// 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.
|
||||
/// 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 {
|
||||
#[async_trait::async_trait]
|
||||
impl Request 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())
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendVenue",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendVenue {
|
||||
pub fn new<C, T, A>(chat_id: C, latitude: f32, longitude: f32, title: T, address: A) -> Self
|
||||
impl<'a> SendVenue<'a> {
|
||||
pub(crate) fn new<C, T, A>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
latitude: f32,
|
||||
longitude: f32,
|
||||
title: T,
|
||||
address: A,
|
||||
) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
T: Into<String>,
|
||||
A: Into<String>
|
||||
A: Into<String>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let title = title.into();
|
||||
let address = address.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
latitude,
|
||||
longitude,
|
||||
|
@ -68,72 +89,69 @@ impl SendVenue {
|
|||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SendVenue> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn latitude(mut self, val: f32) -> Self {
|
||||
self.payload.latitude = val;
|
||||
self.latitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn longitude(mut self, val: f32) -> Self {
|
||||
self.payload.longitude = val;
|
||||
self.longitude = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.title = val.into();
|
||||
self.title = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn address<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.address = val.into();
|
||||
self.address = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn foursquare_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.foursquare_id = Some(val.into());
|
||||
self.foursquare_id = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn foursquare_type<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.foursquare_type = Some(val.into());
|
||||
self.foursquare_type = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.payload.disable_notification = Some(val);
|
||||
self.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.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
177
src/requests/all/send_video.rs
Normal file
177
src/requests/all/send_video.rs
Normal file
|
@ -0,0 +1,177 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{form_builder::FormBuilder, Request, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct SendVideo<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SendVideo<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendVideo",
|
||||
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(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendVideo<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, video: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn video(mut self, val: InputFile) -> Self {
|
||||
self.video = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn duration(mut self, val: i32) -> Self {
|
||||
self.duration = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn width(mut self, val: i32) -> Self {
|
||||
self.width = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn height(mut self, val: i32) -> Self {
|
||||
self.height = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn thumb(mut self, val: InputFile) -> Self {
|
||||
self.thumb = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn supports_streaming(mut self, val: bool) -> Self {
|
||||
self.supports_streaming = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
139
src/requests/all/send_video_note.rs
Normal file
139
src/requests/all/send_video_note.rs
Normal file
|
@ -0,0 +1,139 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{form_builder::FormBuilder, Request, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1
|
||||
/// minute long. Use this method to send video messages. On success, the sent
|
||||
/// Message is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendVideoNote<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SendVideoNote<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendVideoNote",
|
||||
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(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendVideoNote<'a> {
|
||||
pub(crate) fn new<C>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
video_note: InputFile,
|
||||
) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
video_note,
|
||||
duration: None,
|
||||
length: None,
|
||||
thumb: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn video_note(mut self, val: InputFile) -> Self {
|
||||
self.video_note = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn duration(mut self, val: i32) -> Self {
|
||||
self.duration = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn length(mut self, val: i32) -> Self {
|
||||
self.length = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn thumb(mut self, val: InputFile) -> Self {
|
||||
self.thumb = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
135
src/requests/all/send_voice.rs
Normal file
135
src/requests/all/send_voice.rs
Normal file
|
@ -0,0 +1,135 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{form_builder::FormBuilder, Request, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to send audio files, if you want Telegram clients to display
|
||||
/// the file as a playable voice message. For this to work, your audio must be
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct SendVoice<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SendVoice<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendVoice",
|
||||
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(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendVoice<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, voice: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
voice,
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
duration: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn voice(mut self, val: InputFile) -> Self {
|
||||
self.voice = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode(mut self, val: ParseMode) -> Self {
|
||||
self.parse_mode = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn duration(mut self, val: i32) -> Self {
|
||||
self.duration = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification(mut self, val: bool) -> Self {
|
||||
self.disable_notification = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id(mut self, val: i32) -> Self {
|
||||
self.reply_to_message_id = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: ReplyMarkup) -> Self {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,15 +1,20 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{True, ChatId},
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to set a custom title for an administrator in a supergroup
|
||||
/// promoted by the bot.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct SetChatAdministratorCustomTitle {
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetChatAdministratorCustomTitle<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target
|
||||
/// supergroup (in the format `@supergroupusername`)
|
||||
pub chat_id: ChatId,
|
||||
|
@ -22,22 +27,28 @@ pub struct SetChatAdministratorCustomTitle {
|
|||
pub custom_title: String,
|
||||
}
|
||||
|
||||
impl Method for SetChatAdministratorCustomTitle {
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SetChatAdministratorCustomTitle<'_> {
|
||||
type Output = True;
|
||||
|
||||
const NAME: &'static str = "setChatAdministratorCustomTitle";
|
||||
}
|
||||
|
||||
impl json::Payload for SetChatAdministratorCustomTitle {}
|
||||
|
||||
impl dynamic::Payload for SetChatAdministratorCustomTitle {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"setChatAdministratorCustomTitle",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatAdministratorCustomTitle {
|
||||
pub fn new<C, CT>(chat_id: C, user_id: i32, custom_title: CT) -> Self
|
||||
impl<'a> SetChatAdministratorCustomTitle<'a> {
|
||||
pub(crate) fn new<C, CT>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
user_id: i32,
|
||||
custom_title: CT,
|
||||
) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
CT: Into<String>,
|
||||
|
@ -45,24 +56,23 @@ impl SetChatAdministratorCustomTitle {
|
|||
let chat_id = chat_id.into();
|
||||
let custom_title = custom_title.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
user_id,
|
||||
custom_title,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, SetChatAdministratorCustomTitle> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.payload.user_id = val;
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -70,7 +80,7 @@ impl json::Request<'_, SetChatAdministratorCustomTitle> {
|
|||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload.custom_title = val.into();
|
||||
self.custom_title = val.into();
|
||||
self
|
||||
}
|
||||
}
|
69
src/requests/all/set_chat_description.rs
Normal file
69
src/requests/all/set_chat_description.rs
Normal file
|
@ -0,0 +1,69 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct SetChatDescription<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SetChatDescription<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"setChatDescription",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SetChatDescription<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
description: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn description<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.description = Some(val.into());
|
||||
self
|
||||
}
|
||||
}
|
70
src/requests/all/set_chat_permissions.rs
Normal file
70
src/requests/all/set_chat_permissions.rs
Normal file
|
@ -0,0 +1,70 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, ChatPermissions, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct SetChatPermissions<'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,
|
||||
/// New default chat permissions
|
||||
permissions: ChatPermissions,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SetChatPermissions<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendChatPermissions",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SetChatPermissions<'a> {
|
||||
pub(crate) fn new<C>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
permissions: ChatPermissions,
|
||||
) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
permissions,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn permissions(mut self, val: ChatPermissions) -> Self {
|
||||
self.permissions = val;
|
||||
self
|
||||
}
|
||||
}
|
67
src/requests/all/set_chat_photo.rs
Normal file
67
src/requests/all/set_chat_photo.rs
Normal file
|
@ -0,0 +1,67 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, InputFile, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct SetChatPhoto<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SetChatPhoto<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"setChatPhoto",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SetChatPhoto<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, photo: InputFile) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
photo,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo(mut self, val: InputFile) -> Self {
|
||||
self.photo = val;
|
||||
self
|
||||
}
|
||||
}
|
77
src/requests/all/set_chat_sticker_set.rs
Normal file
77
src/requests/all/set_chat_sticker_set.rs
Normal file
|
@ -0,0 +1,77 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct SetChatStickerSet<'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,
|
||||
/// Name of the sticker set to be set as the group sticker set
|
||||
sticker_set_name: String,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SetChatStickerSet<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"setChatStickerSet",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SetChatStickerSet<'a> {
|
||||
pub(crate) fn new<C, S>(
|
||||
bot: &'a Bot,
|
||||
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 {
|
||||
bot,
|
||||
chat_id,
|
||||
sticker_set_name,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn sticker_set_name<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.sticker_set_name = val.into();
|
||||
self
|
||||
}
|
||||
}
|
71
src/requests/all/set_chat_title.rs
Normal file
71
src/requests/all/set_chat_title.rs
Normal file
|
@ -0,0 +1,71 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct SetChatTitle<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// 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,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SetChatTitle<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"setChatTitle",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SetChatTitle<'a> {
|
||||
pub(crate) fn new<C, T>(bot: &'a Bot, chat_id: C, title: T) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
T: Into<String>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
let title = title.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
title,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.title = val.into();
|
||||
self
|
||||
}
|
||||
}
|
91
src/requests/all/set_game_score.rs
Normal file
91
src/requests/all/set_game_score.rs
Normal file
|
@ -0,0 +1,91 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatOrInlineMessage, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// 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, Clone, Serialize)]
|
||||
pub struct SetGameScore<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
#[serde(flatten)]
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SetGameScore<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"setGameScore",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SetGameScore<'a> {
|
||||
pub(crate) fn new(
|
||||
bot: &'a Bot,
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
user_id: i32,
|
||||
score: i32,
|
||||
) -> Self {
|
||||
Self {
|
||||
bot,
|
||||
chat_or_inline_message,
|
||||
user_id,
|
||||
score,
|
||||
force: None,
|
||||
disable_edit_message: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
|
||||
self.chat_or_inline_message = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn score(mut self, val: i32) -> Self {
|
||||
self.score = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn force(mut self, val: bool) -> Self {
|
||||
self.force = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_edit_message(mut self, val: bool) -> Self {
|
||||
self.disable_edit_message = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
64
src/requests/all/set_sticker_position_in_set.rs
Normal file
64
src/requests/all/set_sticker_position_in_set.rs
Normal file
|
@ -0,0 +1,64 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::True,
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to move a sticker in a set created by the bot to a specific
|
||||
/// position . Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetStickerPositionInSet<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// File identifier of the sticker
|
||||
sticker: String,
|
||||
/// New sticker position in the set, zero-based
|
||||
position: i32,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SetStickerPositionInSet<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"setStickerPositionInSet",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SetStickerPositionInSet<'a> {
|
||||
pub(crate) fn new<S>(bot: &'a Bot, sticker: S, position: i32) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
let sticker = sticker.into();
|
||||
Self {
|
||||
bot,
|
||||
sticker,
|
||||
position,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sticker<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.sticker = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn position(mut self, val: i32) -> Self {
|
||||
self.position = val;
|
||||
self
|
||||
}
|
||||
}
|
106
src/requests/all/set_webhook.rs
Normal file
106
src/requests/all/set_webhook.rs
Normal file
|
@ -0,0 +1,106 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{InputFile, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to specify a url and receive incoming updates via an
|
||||
/// outgoing webhook. Whenever there is an update for the bot, we will send an
|
||||
/// HTTPS POST request to the specified url, containing a JSON-serialized
|
||||
/// Update. In case of an unsuccessful request, we will give up after a
|
||||
/// reasonable amount of attempts. Returns True on success. If you'd like to
|
||||
/// make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/<token>. Since nobody else
|
||||
/// knows your bot‘s token, you can be pretty sure it’s us.Notes1. You will not
|
||||
/// be able to receive updates using getUpdates for as long as an outgoing
|
||||
/// webhook is set up.2. To use a self-signed certificate, you need to upload
|
||||
/// your public key certificate using certificate parameter. Please upload as
|
||||
/// InputFile, sending a String will not work.3. Ports currently supported for
|
||||
/// Webhooks: 443, 80, 88, 8443.NEW! If you're having any trouble setting up
|
||||
/// webhooks, please check out this amazing guide to Webhooks.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetWebhook<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// HTTPS url to send updates to. Use an empty string to remove webhook
|
||||
/// integration
|
||||
url: String,
|
||||
/// Upload your public key certificate so that the root certificate in use
|
||||
/// can be checked. See our self-signed guide for details.
|
||||
certificate: Option<InputFile>,
|
||||
/// Maximum allowed number of simultaneous HTTPS connections to the webhook
|
||||
/// for update delivery, 1-100. Defaults to 40. Use lower values to limit
|
||||
/// the load on your bot‘s server, and higher values to increase your bot’s
|
||||
/// throughput.
|
||||
max_connections: Option<i32>,
|
||||
/// List the types of updates you want your bot to receive. For example,
|
||||
/// specify [“message”, “edited_channel_post”, “callback_query”] to only
|
||||
/// receive updates of these types. See Update 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.Please note that this parameter doesn't affect updates
|
||||
/// created before the call to the setWebhook, so unwanted updates may be
|
||||
/// received for a short period of time.
|
||||
allowed_updates: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for SetWebhook<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"setWebhook",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SetWebhook<'a> {
|
||||
pub(crate) fn new<U>(bot: &'a Bot, url: U) -> Self
|
||||
where
|
||||
U: Into<String>,
|
||||
{
|
||||
let url = url.into();
|
||||
Self {
|
||||
bot,
|
||||
url,
|
||||
certificate: None,
|
||||
max_connections: None,
|
||||
allowed_updates: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn url<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.url = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn certificate(mut self, val: InputFile) -> Self {
|
||||
self.certificate = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn max_connections(mut self, val: i32) -> Self {
|
||||
self.max_connections = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn allowed_updates<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<Vec<String>>,
|
||||
{
|
||||
self.allowed_updates = Some(val.into());
|
||||
self
|
||||
}
|
||||
}
|
62
src/requests/all/stop_message_live_location.rs
Normal file
62
src/requests/all/stop_message_live_location.rs
Normal file
|
@ -0,0 +1,62 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to stop updating a live location message before live_period
|
||||
/// expires. On success, if the message was sent by the bot, the sent Message is
|
||||
/// returned, otherwise True is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct StopMessageLiveLocation<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
#[serde(flatten)]
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
|
||||
/// A JSON-serialized object for a new inline keyboard.
|
||||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for StopMessageLiveLocation<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send(&self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"stopMessageLiveLocation",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> StopMessageLiveLocation<'a> {
|
||||
pub(crate) fn new(
|
||||
bot: &'a Bot,
|
||||
chat_or_inline_message: ChatOrInlineMessage,
|
||||
) -> Self {
|
||||
Self {
|
||||
bot,
|
||||
chat_or_inline_message,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
|
||||
self.chat_or_inline_message = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,15 +1,22 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, InlineKeyboardMarkup, Poll},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to stop a poll which was sent by the bot. On success, the stopped Poll with the final results is returned.
|
||||
/// Use this method to stop a poll which was sent by the bot. On success, the
|
||||
/// stopped Poll with the final results is returned.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
|
||||
pub struct StopPoll {
|
||||
/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct StopPoll<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target channel
|
||||
/// (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
/// Identifier of the original message with the poll
|
||||
message_id: i32,
|
||||
|
@ -17,51 +24,49 @@ pub struct StopPoll {
|
|||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
impl Method for StopPoll {
|
||||
#[async_trait::async_trait]
|
||||
impl Request for StopPoll<'_> {
|
||||
type Output = Poll;
|
||||
|
||||
const NAME: &'static str = "stopPoll";
|
||||
}
|
||||
|
||||
impl json::Payload for StopPoll {}
|
||||
|
||||
impl dynamic::Payload for StopPoll {
|
||||
fn kind(&self) -> dynamic::Kind {
|
||||
dynamic::Kind::Json(serde_json::to_string(self).unwrap())
|
||||
async fn send(&self) -> ResponseResult<Poll> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"stopPoll",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl StopPoll {
|
||||
pub fn new<C>(chat_id: C, message_id: i32) -> Self
|
||||
impl<'a> StopPoll<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, message_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
message_id,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl json::Request<'_, StopPoll> {
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.payload.chat_id = val.into();
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id(mut self, val: i32) -> Self {
|
||||
self.payload.message_id = val;
|
||||
self.message_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
|
||||
self.payload.reply_markup = Some(val);
|
||||
self.reply_markup = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
67
src/requests/all/unban_chat_member.rs
Normal file
67
src/requests/all/unban_chat_member.rs
Normal file
|
@ -0,0 +1,67 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to unban a previously kicked user in a supergroup or
|
||||
/// channel. The user will not return to the group or channel automatically, but
|
||||
/// will be able to join via link, etc. The bot must be an administrator for
|
||||
/// this to work. Returns True on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct UnbanChatMember<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target group or username of the target
|
||||
/// supergroup or channel (in the format @username)
|
||||
chat_id: ChatId,
|
||||
/// Unique identifier of the target user
|
||||
user_id: i32,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for UnbanChatMember<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"unbanChatMember",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> UnbanChatMember<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, user_id: i32) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self {
|
||||
bot,
|
||||
chat_id,
|
||||
user_id,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
}
|
56
src/requests/all/unpin_chat_message.rs
Normal file
56
src/requests/all/unpin_chat_message.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to unpin 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, Clone, Serialize)]
|
||||
pub struct UnpinChatMessage<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target channel
|
||||
/// (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Request for UnpinChatMessage<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"unpinChatMessage",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> UnpinChatMessage<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
let chat_id = chat_id.into();
|
||||
Self { bot, chat_id }
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = val.into();
|
||||
self
|
||||
}
|
||||
}
|
63
src/requests/all/upload_sticker_file.rs
Normal file
63
src/requests/all/upload_sticker_file.rs
Normal file
|
@ -0,0 +1,63 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{File, InputFile},
|
||||
Bot,
|
||||
};
|
||||
|
||||
/// Use this method to upload a .png file with a sticker for later use in
|
||||
/// createNewStickerSet and addStickerToSet methods (can be used multiple
|
||||
/// times). Returns the uploaded File on success.
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct UploadStickerFile<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// User identifier of sticker file owner
|
||||
user_id: i32,
|
||||
/// 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. More info on Sending Files »
|
||||
png_sticker: InputFile,
|
||||
}
|
||||
#[async_trait::async_trait]
|
||||
impl Request for UploadStickerFile<'_> {
|
||||
type Output = File;
|
||||
|
||||
async fn send(&self) -> ResponseResult<File> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"uploadStickerFile",
|
||||
&serde_json::to_string(self).unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> UploadStickerFile<'a> {
|
||||
pub(crate) fn new(
|
||||
bot: &'a Bot,
|
||||
user_id: i32,
|
||||
png_sticker: InputFile,
|
||||
) -> Self {
|
||||
Self {
|
||||
bot,
|
||||
user_id,
|
||||
png_sticker,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn user_id(mut self, val: i32) -> Self {
|
||||
self.user_id = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn png_sticker(mut self, val: InputFile) -> Self {
|
||||
self.png_sticker = val;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
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
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ pub(crate) struct FormBuilder {
|
|||
}
|
||||
|
||||
impl FormBuilder {
|
||||
pub fn new() -> Self {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self { form: Form::new() }
|
||||
}
|
||||
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
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,195 +1,20 @@
|
|||
//! API requests.
|
||||
|
||||
mod all;
|
||||
mod form_builder;
|
||||
mod utils;
|
||||
|
||||
pub mod dynamic;
|
||||
pub mod json;
|
||||
pub mod multipart;
|
||||
pub use all::*;
|
||||
|
||||
/// A type that is returned when making requests to telegram
|
||||
/// A type that is returned after making a request to Telegram.
|
||||
pub type ResponseResult<T> = Result<T, crate::RequestError>;
|
||||
|
||||
/// Signature of telegram method.
|
||||
pub trait Method {
|
||||
/// Return-type of the method.
|
||||
/// Designates an API request.
|
||||
#[async_trait::async_trait]
|
||||
pub trait Request {
|
||||
/// A data structure returned if success.
|
||||
type 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;
|
||||
mod set_chat_administrator_custom_title;
|
||||
|
||||
pub use {
|
||||
get_updates::GetUpdates,
|
||||
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,
|
||||
set_chat_administrator_custom_title::SetChatAdministratorCustomTitle,
|
||||
};
|
||||
/// Asynchronously sends this request to Telegram and returns the result.
|
||||
async fn send(&self) -> ResponseResult<Self::Output>;
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
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
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
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
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,126 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
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
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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 {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
requests::{dynamic, json, Method},
|
||||
types::{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 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
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
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
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
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
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue