mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
Remove old requests
This commit is contained in:
parent
be11633d6e
commit
521eef7550
43 changed files with 0 additions and 4600 deletions
|
@ -1,125 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::True,
|
||||
};
|
||||
|
||||
/// Use this method to send answers to callback queries sent from inline
|
||||
/// keyboards. The answer will be displayed to the user as a notification at the
|
||||
/// top of the chat screen or as an alert. On success, True is returned.
|
||||
///
|
||||
/// Alternatively, the user can be redirected to the specified Game URL. For
|
||||
/// this option to work, you must first create a game for your bot via
|
||||
/// @Botfather and accept the terms. Otherwise, you may use links like
|
||||
/// t.me/your_bot?start=XXXX that open your bot with a parameter.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct AnswerCallbackQuery<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the query to be answered.
|
||||
callback_query_id: String,
|
||||
|
||||
/// Text of the notification. If not specified, nothing will be shown to
|
||||
/// the user, 0-200 characters
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
text: Option<String>,
|
||||
|
||||
/// If true, an alert will be shown by the client instead of a notification
|
||||
/// at the top of the chat screen. Defaults to false.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
show_alert: Option<bool>,
|
||||
|
||||
/// URL that will be opened by the user's client. If you have created a
|
||||
/// Game and accepted the conditions via @Botfather, specify the URL that
|
||||
/// opens your game – note that this will only work if the query comes from
|
||||
/// a callback_game button.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
url: Option<String>,
|
||||
|
||||
/// The maximum amount of time in seconds that the result of the callback
|
||||
/// query may be cached client-side. Telegram apps will support caching
|
||||
/// starting in version 3.14. Defaults to 0.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
cache_time: Option<i32>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for AnswerCallbackQuery<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl AnswerCallbackQuery<'_> {
|
||||
pub async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"answerCallbackQuery",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AnswerCallbackQuery<'a> {
|
||||
pub(crate) fn new<S>(bot: &'a Bot, callback_query_id: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
callback_query_id: callback_query_id.into(),
|
||||
text: None,
|
||||
show_alert: None,
|
||||
url: None,
|
||||
cache_time: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn callback_query_id<S>(mut self, value: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.callback_query_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn text<S>(mut self, value: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.text = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn show_alert<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.show_alert = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn url<S>(mut self, value: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.url = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn cache_time<I>(mut self, value: I) -> Self
|
||||
where
|
||||
I: Into<i32>,
|
||||
{
|
||||
self.cache_time = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::True,
|
||||
};
|
||||
|
||||
#[derive(Debug, Serialize, Clone)]
|
||||
/// Once the user has confirmed their payment and shipping details, the Bot API
|
||||
/// sends the final confirmation in the form of an [`Update`] with the field
|
||||
/// pre_checkout_query. Use this method to respond to such pre-checkout queries.
|
||||
/// On success, True is returned. Note: The Bot API must receive an answer
|
||||
/// within 10 seconds after the pre-checkout query was sent.
|
||||
///
|
||||
/// [`Update`]: crate::types::Update
|
||||
pub struct AnswerPreCheckoutQuery<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the query to be answered
|
||||
pub pre_checkout_query_id: String,
|
||||
|
||||
/// Specify True if everything is alright (goods are available, etc.) and
|
||||
/// the bot is ready to proceed with the order. Use False if there are any
|
||||
/// problems.
|
||||
pub ok: bool,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Required if ok is False. Error message in human readable form that
|
||||
/// explains the reason for failure to proceed with the checkout (e.g.
|
||||
/// "Sorry, somebody just bought the last of our amazing black T-shirts
|
||||
/// while you were busy filling out your payment details. Please choose a
|
||||
/// different color or garment!"). Telegram will display this message to
|
||||
/// the user.
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for AnswerPreCheckoutQuery<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl AnswerPreCheckoutQuery<'_> {
|
||||
pub async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"answerPreCheckoutQuery",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AnswerPreCheckoutQuery<'a> {
|
||||
pub(crate) fn new<S, B>(
|
||||
bot: &'a Bot,
|
||||
pre_checkout_query_id: S,
|
||||
ok: B,
|
||||
) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
B: Into<bool>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
pre_checkout_query_id: pre_checkout_query_id.into(),
|
||||
ok: ok.into(),
|
||||
error_message: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pre_checkout_query_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.pre_checkout_query_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ok<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.ok = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn error_message<S>(mut self, value: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.error_message = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ShippingOption, True},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
/// If you sent an invoice requesting a shipping address and the parameter
|
||||
/// is_flexible was specified, the Bot API will send an [`Update`] with a
|
||||
/// shipping_query field to the bot. Use this method to reply to shipping
|
||||
/// queries. On success, True is returned.
|
||||
///
|
||||
/// [`Update`]: crate::types::Update
|
||||
pub struct AnswerShippingQuery<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the query to be answered
|
||||
pub shipping_query_id: String,
|
||||
/// Specify True if delivery to the specified address is possible and False
|
||||
/// if there are any problems (for example, if delivery to the specified
|
||||
/// address is not possible)
|
||||
pub ok: bool,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Required if ok is True. A JSON-serialized array of available shipping
|
||||
/// options.
|
||||
pub shipping_options: Option<Vec<ShippingOption>>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Required if ok is False. Error message in human readable form that
|
||||
/// explains why it is impossible to complete the order (e.g. "Sorry,
|
||||
/// delivery to your desired address is unavailable'). Telegram will
|
||||
/// display this message to the user.
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for AnswerShippingQuery<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl AnswerShippingQuery<'_> {
|
||||
pub async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"answerShippingQuery",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AnswerShippingQuery<'a> {
|
||||
pub(crate) fn new<S, B>(bot: &'a Bot, shipping_query_id: S, ok: B) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
B: Into<bool>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
shipping_query_id: shipping_query_id.into(),
|
||||
ok: ok.into(),
|
||||
shipping_options: None,
|
||||
error_message: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shipping_query_id<S>(mut self, value: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.shipping_query_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ok<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.ok = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn shipping_options<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<Vec<ShippingOption>>,
|
||||
{
|
||||
self.shipping_options = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn error_message<S>(mut self, value: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.error_message = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct DeleteChatPhoto<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for DeleteChatPhoto<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl DeleteChatPhoto<'_> {
|
||||
async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"deleteChatPhoto",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DeleteChatPhoto<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = chat_id.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn serialize() {
|
||||
let bot = Bot::new("token");
|
||||
let chat_id = 123;
|
||||
let method = DeleteChatPhoto::new(&bot, chat_id);
|
||||
|
||||
let expected = r#"{"chat_id":123}"#;
|
||||
let actual = serde_json::to_string::<DeleteChatPhoto>(&method).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
/// Use this method to delete a group sticker set from a supergroup. The bot
|
||||
/// must be an administrator in the chat for this to work and must have the
|
||||
/// appropriate admin rights. Use the field can_set_sticker_set optionally
|
||||
/// returned in getChat requests to check if the bot can use this method.
|
||||
/// Returns True on success.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct DeleteChatStickerSet<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target
|
||||
/// supergroup (in the format @supergroupusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for DeleteChatStickerSet<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl DeleteChatStickerSet<'_> {
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"deleteChatStickerSet",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DeleteChatStickerSet<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message, ReplyMarkup},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
/// Use this method to edit live location messages. A location can be edited
|
||||
/// until its live_period expires or editing is explicitly disabled by a
|
||||
/// call to [`StopMessageLiveLocation`]. On success, if the edited message
|
||||
/// was sent by the bot, the edited [`Message`] is returned, otherwise True
|
||||
/// is returned.
|
||||
///
|
||||
/// [`StopMessageLiveLocation`]: crate::requests::StopMessageLiveLocation
|
||||
/// [`Message`]: crate::types::Message
|
||||
pub struct EditMessageLiveLocation<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Required if inline_message_id is not specified. Unique identifier for
|
||||
/// the target chat or username of the target channel (in the format
|
||||
/// @channelusername)
|
||||
chat_id: Option<ChatId>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Required if inline_message_id is not specified. Identifier of the
|
||||
/// message to edit
|
||||
message_id: Option<i32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Required if chat_id and message_id are not specified. Identifier of
|
||||
/// the inline message
|
||||
inline_message_id: Option<String>,
|
||||
/// Latitude of new location
|
||||
latitude: f64,
|
||||
/// Longitude of new location
|
||||
longitude: f64,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// A JSON-serialized object for a new inline keyboard.
|
||||
reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for EditMessageLiveLocation<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl EditMessageLiveLocation<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"editMessageLiveLocation",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> EditMessageLiveLocation<'a> {
|
||||
pub(crate) fn new<Lt, Lg>(bot: &'a Bot, latitude: Lt, longitude: Lg) -> Self
|
||||
where
|
||||
Lt: Into<f64>,
|
||||
Lg: Into<f64>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: None,
|
||||
message_id: None,
|
||||
inline_message_id: None,
|
||||
latitude: latitude.into(),
|
||||
longitude: longitude.into(),
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn inline_message_id<S>(mut self, value: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.inline_message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn latitude<Lt>(mut self, value: Lt) -> Self
|
||||
where
|
||||
Lt: Into<f64>,
|
||||
{
|
||||
self.latitude = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn longitude<Lg>(mut self, value: Lg) -> Self
|
||||
where
|
||||
Lg: Into<f64>,
|
||||
{
|
||||
self.longitude = value.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::ChatId,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct ExportCharInviteLink<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for ExportCharInviteLink<'_> {
|
||||
type Output = String;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl ExportCharInviteLink<'_> {
|
||||
async fn send(self) -> ResponseResult<String> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"exportChatInviteLink",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExportCharInviteLink<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = chat_id.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn serialize() {
|
||||
let bot = Bot::new("token");
|
||||
let chat_id = 123;
|
||||
let method = ExportCharInviteLink::new(&bot, chat_id);
|
||||
|
||||
let expected = r#"{"chat_id":123}"#;
|
||||
let actual =
|
||||
serde_json::to_string::<ExportCharInviteLink>(&method).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
/// Use this method to forward messages of any kind. On success, the sent
|
||||
/// [`Message`] is returned.
|
||||
pub struct ForwardMessage<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target channel
|
||||
/// (in the format @channelusername)
|
||||
pub chat_id: ChatId,
|
||||
/// Unique identifier for the target chat or username of the target channel
|
||||
/// (in the format @channelusername)
|
||||
pub from_chat_id: ChatId,
|
||||
/// Message identifier in the chat specified in from_chat_id
|
||||
pub message_id: i32,
|
||||
|
||||
/// Sends the message silently. Users will receive a notification with no
|
||||
/// sound.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub disable_notification: Option<bool>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for ForwardMessage<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl ForwardMessage<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"forwardMessage",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ForwardMessage<'a> {
|
||||
pub(crate) fn new<C, Fc, M>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
from_chat_id: Fc,
|
||||
message_id: M,
|
||||
) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
Fc: Into<ChatId>,
|
||||
M: Into<i32>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
from_chat_id: from_chat_id.into(),
|
||||
message_id: message_id.into(),
|
||||
disable_notification: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
pub fn from_chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.from_chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id<M>(mut self, value: M) -> Self
|
||||
where
|
||||
M: Into<i32>,
|
||||
{
|
||||
self.message_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{Chat, ChatId},
|
||||
};
|
||||
|
||||
/// Use this method to get up to date information about the chat
|
||||
/// (current name of the user for one-on-one conversations,
|
||||
/// current username of a user, group or channel, etc.).
|
||||
/// Returns a Chat object on success.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetChat<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
/// Unique identifier for the target chat or username
|
||||
/// of the target supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetChat<'_> {
|
||||
type Output = Chat;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChat<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Chat> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getChat",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetChat<'a> {
|
||||
pub(crate) fn new<F>(bot: &'a Bot, chat_id: F) -> Self
|
||||
where
|
||||
F: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = chat_id.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, ChatMember},
|
||||
};
|
||||
|
||||
/// Use this method to get a list of administrators in a chat. On success,
|
||||
/// returns an Array of ChatMember objects that contains information about all
|
||||
/// chat administrators except other bots. If the chat is a group or a
|
||||
/// supergroup and no administrators were appointed, only the creator will be
|
||||
/// returned
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetChatAdministrators<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target
|
||||
/// supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetChatAdministrators<'_> {
|
||||
type Output = Vec<ChatMember>;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChatAdministrators<'_> {
|
||||
async fn send(&self) -> ResponseResult<Vec<ChatMember>> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getChatAdministrators",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetChatAdministrators<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, ChatMember},
|
||||
};
|
||||
|
||||
/// Use this method to get information about a member of a chat. Returns a
|
||||
/// ChatMember object on success.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetChatMember<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target
|
||||
/// supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
|
||||
/// Unique identifier of the target user
|
||||
user_id: i32,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetChatMember<'_> {
|
||||
type Output = ChatMember;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChatMember<'_> {
|
||||
async fn send(&self) -> ResponseResult<ChatMember> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getChatMember",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetChatMember<'a> {
|
||||
pub(crate) fn new<C, I>(bot: &'a Bot, chat_id: C, user_id: I) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
I: Into<i32>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
user_id: user_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id<I>(mut self, value: I) -> Self
|
||||
where
|
||||
I: Into<i32>,
|
||||
{
|
||||
self.user_id = value.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{Chat, ChatId},
|
||||
};
|
||||
|
||||
/// Use this method to get the number of members in a chat. Returns Int on
|
||||
/// success.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetChatMembersCount<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username
|
||||
/// of the target supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetChatMembersCount<'_> {
|
||||
type Output = Chat;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetChatMembersCount<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Chat> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getChatMembersCount",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetChatMembersCount<'a> {
|
||||
pub fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::File,
|
||||
};
|
||||
|
||||
/// Use this method to get basic info about a file and prepare it for
|
||||
/// downloading. For the moment, bots can download files of up to 20MB in size.
|
||||
/// On success, a File object is returned.
|
||||
/// The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>,
|
||||
/// where <file_path> is taken from the response.
|
||||
/// It is guaranteed that the link will be valid for at least 1 hour.
|
||||
/// When the link expires, a new one can be requested by calling getFile again.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetFile<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
/// File identifier to get info about
|
||||
pub file_id: String,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetFile<'_> {
|
||||
type Output = File;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetFile<'_> {
|
||||
pub async fn send(self) -> ResponseResult<File> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getFile",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetFile<'a> {
|
||||
pub(crate) fn new<F>(bot: &'a Bot, value: F) -> Self
|
||||
where
|
||||
F: Into<String>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
file_id: value.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn file_id<F>(mut self, value: F) -> Self
|
||||
where
|
||||
F: Into<String>,
|
||||
{
|
||||
self.file_id = value.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::User,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
/// A filter method for testing your bot's auth token. Requires no parameters.
|
||||
/// Returns basic information about the bot in form of a [`User`] object.
|
||||
pub struct GetMe<'a> {
|
||||
bot: &'a Bot,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetMe<'_> {
|
||||
type Output = User;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetMe<'_> {
|
||||
pub async fn send(self) -> ResponseResult<User> {
|
||||
network::request_simple(self.bot.client(), self.bot.token(), "getMe")
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetMe<'a> {
|
||||
pub(crate) fn new(bot: &'a Bot) -> Self {
|
||||
GetMe { bot }
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::Update,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetUpdates<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
pub offset: Option<i32>,
|
||||
pub limit: Option<u8>,
|
||||
pub timeout: Option<u32>,
|
||||
pub allowed_updates: Option<Vec<AllowedUpdate>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Eq, Hash, PartialEq, Clone, Copy)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum AllowedUpdate {
|
||||
Message,
|
||||
EditedMessage,
|
||||
ChannelPost,
|
||||
EditedChannelPost,
|
||||
InlineQuery,
|
||||
ChosenInlineResult,
|
||||
CallbackQuery,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetUpdates<'_> {
|
||||
type Output = Vec<Update>;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetUpdates<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Vec<Update>> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getUpdates",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetUpdates<'a> {
|
||||
pub(crate) fn new(bot: &'a Bot) -> Self {
|
||||
Self {
|
||||
bot,
|
||||
offset: None,
|
||||
limit: None,
|
||||
timeout: None,
|
||||
allowed_updates: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn offset<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.offset = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn limit<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<u8>,
|
||||
{
|
||||
self.limit = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn timeout<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<u32>,
|
||||
{
|
||||
self.timeout = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn allowed_updates<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<Vec<AllowedUpdate>>,
|
||||
{
|
||||
self.allowed_updates = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::UserProfilePhotos,
|
||||
};
|
||||
|
||||
///Use this method to get a list of profile pictures for a user. Returns a
|
||||
/// UserProfilePhotos object.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct GetUserProfilePhotos<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
/// Unique identifier of the target user
|
||||
pub user_id: i32,
|
||||
/// Sequential number of the first photo to be returned. By default, all
|
||||
/// photos are returned.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub offset: Option<i64>,
|
||||
///Limits the number of photos to be retrieved. Values between 1—100 are
|
||||
/// accepted. Defaults to 100.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub limit: Option<i64>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for GetUserProfilePhotos<'_> {
|
||||
type Output = UserProfilePhotos;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl GetUserProfilePhotos<'_> {
|
||||
async fn send(self) -> ResponseResult<UserProfilePhotos> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"getUserProfilePhotos",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetUserProfilePhotos<'a> {
|
||||
pub fn new<U>(bot: &'a Bot, user_id: U) -> Self
|
||||
where
|
||||
U: Into<i32>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
user_id: user_id.into(),
|
||||
offset: None,
|
||||
limit: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn user_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.user_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn offset<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i64>,
|
||||
{
|
||||
self.offset = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn limit<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i64>,
|
||||
{
|
||||
self.limit = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
/// Use this method to kick a user from a group, a supergroup or a channel. In
|
||||
/// the case of supergroups and channels, the user will not be able to return to
|
||||
/// the group on their own using invite links, etc., unless unbanned first. The
|
||||
/// bot must be an administrator in the chat for this to work and must have the
|
||||
/// appropriate admin rights. Returns True on success.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct KickChatMember<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
///Unique identifier for the target group or username of the target
|
||||
/// supergroup or channel (in the format @channelusername)
|
||||
pub chat_id: ChatId,
|
||||
/// Unique identifier of the target user
|
||||
pub user_id: i32,
|
||||
///Date when the user will be unbanned, unix time. If user is banned for
|
||||
/// more than 366 days or less than 30 seconds from the current time they
|
||||
/// are considered to be banned forever
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub until_date: Option<u64>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for KickChatMember<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl KickChatMember<'_> {
|
||||
async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"kickChatMember",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> KickChatMember<'a> {
|
||||
pub(crate) fn new<C, U>(bot: &'a Bot, chat_id: C, user_id: U) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
U: Into<i32>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
user_id: user_id.into(),
|
||||
until_date: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id<U>(mut self, value: U) -> Self
|
||||
where
|
||||
U: Into<i32>,
|
||||
{
|
||||
self.user_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn until_date<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<u64>,
|
||||
{
|
||||
self.until_date = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::ChatId,
|
||||
};
|
||||
|
||||
/// Use this method for your bot to leave a group, supergroup or channel.
|
||||
/// Returns True on success.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct LeaveChat<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
/// Unique identifier for the target chat or username
|
||||
/// of the target supergroup or channel (in the format @channelusername)
|
||||
chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for LeaveChat<'_> {
|
||||
type Output = bool;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl LeaveChat<'_> {
|
||||
pub async fn send(self) -> ResponseResult<bool> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"leaveChat",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> LeaveChat<'a> {
|
||||
pub(crate) fn new<F>(bot: &'a Bot, chat_id: F) -> Self
|
||||
where
|
||||
F: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
}
|
||||
}
|
||||
pub fn chat_id<C>(mut self, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = chat_id.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
/// Use this method to get up to date information about the chat
|
||||
/// (current name of the user for one-on-one conversations,
|
||||
/// current username of a user, group or channel, etc.).
|
||||
/// Returns a Chat object on success.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct PinChatMessage<'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)
|
||||
pub chat_id: ChatId,
|
||||
pub message_id: i32,
|
||||
pub disable_notification: Option<bool>,
|
||||
}
|
||||
|
||||
impl<'a> PinChatMessage<'a> {
|
||||
pub(crate) fn new<C, M>(bot: &'a Bot, chat_id: C, message_id: M) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
M: Into<i32>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
message_id: message_id.into(),
|
||||
disable_notification: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disable_notification<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for PinChatMessage<'_> {
|
||||
type Output = True;
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl PinChatMessage<'_> {
|
||||
async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"pinChatMessage",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
|
@ -1,175 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
///Use this method to promote or demote a user in a supergroup or a channel.
|
||||
/// The bot must be an administrator in the chat for this to work and must have
|
||||
/// the appropriate admin rights. Pass False for all boolean parameters to
|
||||
/// demote a user. Returns True on success.
|
||||
#[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)
|
||||
pub chat_id: ChatId,
|
||||
///Unique identifier of the target user
|
||||
pub user_id: i32,
|
||||
///Pass True, if the administrator can change chat title, photo and other
|
||||
/// settings
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
can_change_info: Option<bool>,
|
||||
///Pass True, if the administrator can create channel posts, channels only
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub can_post_messages: Option<bool>,
|
||||
///Pass True, if the administrator can edit messages of other users and
|
||||
/// can pin messages, channels only
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub can_edit_messages: Option<bool>,
|
||||
///Pass True, if the administrator can delete messages of other users
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub can_delete_messages: Option<bool>,
|
||||
///Pass True, if the administrator can invite new users to the chat
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub can_invite_users: Option<bool>,
|
||||
///Pass True, if the administrator can restrict, ban or unban chat members
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub can_restrict_members: Option<bool>,
|
||||
///Pass True, if the administrator can pin messages, supergroups only
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub 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)
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub can_promote_members: Option<bool>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for PromoteChatMember<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl PromoteChatMember<'_> {
|
||||
pub async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"promoteChatMember",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PromoteChatMember<'a> {
|
||||
pub(crate) fn new<C, U>(bot: &'a Bot, chat_id: C, user_id: U) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
U: Into<i32>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
user_id: user_id.into(),
|
||||
can_change_info: None,
|
||||
can_post_messages: None,
|
||||
can_edit_messages: None,
|
||||
can_delete_messages: None,
|
||||
can_invite_users: None,
|
||||
can_restrict_members: None,
|
||||
can_pin_messages: None,
|
||||
can_promote_members: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id<U>(mut self, value: U) -> Self
|
||||
where
|
||||
U: Into<i32>,
|
||||
{
|
||||
self.user_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_change_info<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.can_change_info = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_post_messages<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.can_post_messages = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_edit_messages<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.can_edit_messages = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_delete_messages<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.can_delete_messages = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_invite_users<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.can_invite_users = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_restrict_members<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.can_restrict_members = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_pin_messages<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.can_pin_messages = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn can_promote_members<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: Into<bool>,
|
||||
{
|
||||
self.can_promote_members = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, ChatPermissions, True},
|
||||
};
|
||||
|
||||
/// Use this method to restrict a user in a supergroup. The bot must be an
|
||||
/// administrator in the supergroup for this to work and must have the
|
||||
/// appropriate admin rights. Pass True for all permissions to lift restrictions
|
||||
/// from a user. Returns True on success.
|
||||
#[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)
|
||||
pub chat_id: ChatId,
|
||||
///Unique identifier of the target user
|
||||
pub user_id: i32,
|
||||
///New user permissions
|
||||
pub 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
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub until_date: Option<u64>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for RestrictChatMember<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl RestrictChatMember<'_> {
|
||||
async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"restrictChatMember",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RestrictChatMember<'a> {
|
||||
pub(crate) fn new<C, U, P>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
user_id: U,
|
||||
permissions: P,
|
||||
) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
U: Into<i32>,
|
||||
P: Into<ChatPermissions>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
user_id: user_id.into(),
|
||||
permissions: permissions.into(),
|
||||
until_date: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id<U>(mut self, value: U) -> Self
|
||||
where
|
||||
U: Into<i32>,
|
||||
{
|
||||
self.user_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn permissions<P>(mut self, value: P) -> Self
|
||||
where
|
||||
P: Into<ChatPermissions>,
|
||||
{
|
||||
self.permissions = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn until_date<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<u64>,
|
||||
{
|
||||
self.until_date = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,182 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
};
|
||||
|
||||
///Use this method to send animation files (GIF or H.264/MPEG-4 AVC video
|
||||
/// without sound). On success, the sent Message is returned. Bots can currently
|
||||
/// send animation files of up to 50 MB in size, this limit may be changed in
|
||||
/// the future.
|
||||
#[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,
|
||||
///Animation to send. Pass a file_id as String to send an animation that
|
||||
/// exists on the Telegram servers (recommended), pass an HTTP URL as a
|
||||
/// String for Telegram to get an animation from the Internet, or upload a
|
||||
/// new animation using multipart/form-data. More info on Sending Files »
|
||||
pub animation: InputFile,
|
||||
///Duration of sent animation in seconds
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub duration: Option<u64>,
|
||||
///Animation width
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub width: Option<i32>,
|
||||
///Animation height
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub 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> »
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub thumb: Option<InputFile>,
|
||||
///Animation caption (may also be used when resending animation by
|
||||
/// file_id), 0-1024 characters
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub caption: Option<String>,
|
||||
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||
/// fixed-width text or inline URLs in the media caption.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
///Sends the message silently. Users will receive a notification with no
|
||||
/// sound.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub disable_notification: Option<bool>,
|
||||
///If the message is a reply, ID of the original message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub 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.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SendAnimation<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendAnimation<'_> {
|
||||
async fn send(self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendAnimation",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendAnimation<'a> {
|
||||
pub(crate) fn new<C, S>(bot: &'a Bot, chat_id: C, animation: S) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
S: Into<InputFile>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
animation: animation.into(),
|
||||
duration: None,
|
||||
width: None,
|
||||
height: None,
|
||||
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, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn duration<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<u64>,
|
||||
{
|
||||
self.duration = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn width<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.width = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn height<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.height = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn thumb<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>,
|
||||
{
|
||||
self.thumb = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn caption<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn parse_mode<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ParseMode>,
|
||||
{
|
||||
self.parse_mode = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn disable_notification<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn reply_to_message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.reply_to_message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn reply_markup<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ReplyMarkup>,
|
||||
{
|
||||
self.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,199 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{form_builder::FormBuilder, Request, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
};
|
||||
|
||||
/// Use this method to send audio files, if you want Telegram clients to display
|
||||
/// them in the music player. Your audio must be in the .mp3 format. On success,
|
||||
/// 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.
|
||||
///
|
||||
/// [`Message`]: crate::types::Message
|
||||
/// [`SendVoice`]: crate::requests::SendVoice
|
||||
pub struct SendAudio<'a> {
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target channel
|
||||
/// (in the format @channelusername)
|
||||
pub chat_id: ChatId,
|
||||
/// Audio to send.
|
||||
/// [`InputFile::FileId`] - Pass a file_id as String to send an audio that
|
||||
/// exists on the Telegram servers (recommended).
|
||||
/// [`InputFile::Url`] - Pass an HTTP URL as a String for Telegram
|
||||
/// to get an audio from the Internet.
|
||||
/// [`InputFile::File`] - Upload a new audio.
|
||||
pub audio: InputFile,
|
||||
/// Audio caption, 0-1024 characters
|
||||
pub caption: Option<String>,
|
||||
/// Send [Markdown] or [HTML],
|
||||
/// if you want Telegram apps to show [bold, italic, fixed-width text
|
||||
/// or inline URLs] in the media caption.
|
||||
///
|
||||
/// [Markdown]: crate::types::ParseMode::Markdown
|
||||
/// [HTML]: crate::types::ParseMode::HTML
|
||||
/// [bold, italic, fixed-width text or inline URLs]:
|
||||
/// crate::types::ParseMode
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
/// Duration of the audio in seconds
|
||||
pub duration: Option<i32>,
|
||||
/// Performer
|
||||
pub performer: Option<String>,
|
||||
/// Track name
|
||||
pub 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. 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>
|
||||
pub thumb: Option<InputFile>,
|
||||
/// Sends the message silently. Users will receive a notification with no
|
||||
/// sound.
|
||||
pub disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SendAudio<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendAudio<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Message> {
|
||||
let params = FormBuilder::new()
|
||||
.add("chat_id", self.chat_id)
|
||||
.add("caption", self.caption)
|
||||
.add("parse_mode", self.parse_mode)
|
||||
.add("duration", self.duration)
|
||||
.add("performer", self.performer)
|
||||
.add("title", self.title)
|
||||
.add("disable_notification", self.disable_notification)
|
||||
.add("reply_to_message_id", self.reply_to_message_id)
|
||||
.add("audio", self.audio)
|
||||
.add("thumb", self.thumb);
|
||||
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendAudio",
|
||||
params.build(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendAudio<'a> {
|
||||
pub(crate) fn new<C, A>(bot: &'a Bot, chat_id: C, audio: A) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
A: Into<InputFile>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
audio: audio.into(),
|
||||
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, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn audio<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>,
|
||||
{
|
||||
self.audio = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ParseMode>,
|
||||
{
|
||||
self.parse_mode = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn duration<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.duration = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn performer<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.performer = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn title<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.title = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn thumb<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>,
|
||||
{
|
||||
self.thumb = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.reply_to_message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatAction, ChatId, True},
|
||||
};
|
||||
|
||||
///Use this method when you need to tell the user that something is happening
|
||||
/// on the bot's side. The status is set for 5 seconds or less (when a message
|
||||
/// arrives from your bot, Telegram clients clear its typing status).
|
||||
/// Returns True on success.
|
||||
#[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)
|
||||
pub chat_id: ChatId,
|
||||
/// Type of action to broadcast. Choose one, depending on what the user is
|
||||
/// about to receive: typing for text messages, upload_photo for photos,
|
||||
/// record_video or upload_video for videos, record_audio or upload_audio
|
||||
/// for audio files, upload_document for general files, find_location for
|
||||
/// location data, record_video_note or upload_video_note for video notes.
|
||||
pub action: ChatAction,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SendChatAction<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendChatAction<'_> {
|
||||
pub async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendChatAction",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendChatAction<'a> {
|
||||
pub(crate) fn new<Cid, Ca>(bot: &'a Bot, chat_id: Cid, action: Ca) -> Self
|
||||
where
|
||||
Cid: Into<ChatId>,
|
||||
Ca: Into<ChatAction>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
action: action.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn action<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatAction>,
|
||||
{
|
||||
self.action = value.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,155 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message, ReplyMarkup},
|
||||
};
|
||||
|
||||
/// Use this method to send phone contacts.
|
||||
/// returned.
|
||||
#[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)
|
||||
pub chat_id: ChatId,
|
||||
/// Contact's phone number
|
||||
pub phone_number: String,
|
||||
/// Contact's first name
|
||||
pub first_name: String,
|
||||
/// Contact's last name
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub last_name: Option<String>,
|
||||
/// Additional data about the contact in the form of a
|
||||
/// vCard, 0-2048 bytes
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub vcard: Option<String>,
|
||||
/// Sends the message silently. Users will receive a
|
||||
/// notification with no sound.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original
|
||||
/// message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
/// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove
|
||||
/// or ForceReply Optional 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.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SendContact<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendContact<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendContact",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
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>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
phone_number: phone_number.into(),
|
||||
first_name: first_name.into(),
|
||||
last_name: None,
|
||||
vcard: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn phone_number<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.phone_number = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn first_name<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.first_name = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn last_name<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.last_name = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn vcard<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.vcard = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.reply_to_message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ReplyMarkup>,
|
||||
{
|
||||
self.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,160 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
};
|
||||
|
||||
///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.
|
||||
#[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)
|
||||
pub 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.»
|
||||
pub 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 »
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub thumb: Option<InputFile>,
|
||||
/// Document caption (may also be used when resending documents by
|
||||
/// file_id), 0-1024 characters
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub caption: Option<String>,
|
||||
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||
/// fixed-width text or inline URLs in the media caption.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
/// Sends the message silently. Users will receive a notification with
|
||||
/// no sound.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub 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.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SendDocument<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendDocument<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendDocument",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendDocument<'a> {
|
||||
pub(crate) fn new<C, D>(bot: &'a Bot, chat_id: C, document: D) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
D: Into<InputFile>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
document: document.into(),
|
||||
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, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn document<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>,
|
||||
{
|
||||
self.document = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn thumb<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>,
|
||||
{
|
||||
self.thumb = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ParseMode>,
|
||||
{
|
||||
self.parse_mode = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.reply_to_message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ReplyMarkup>,
|
||||
{
|
||||
self.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message, ReplyMarkup},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
/// Use this method to send point on the map. On success, the sent [`Message`]
|
||||
/// is returned.
|
||||
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: f64,
|
||||
/// Longitude of the location
|
||||
longitude: f64,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Period in seconds for which the location will be updated
|
||||
/// (see [Live Locations](https://telegram.org/blog/live-locations)),
|
||||
/// should be between 60 and 86400.
|
||||
live_period: Option<i32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Sends the message silently. Users will receive a notification with
|
||||
/// no sound.
|
||||
disable_notification: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// If the message is a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SendLocation<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendLocation<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendLocation",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendLocation<'a> {
|
||||
pub(crate) fn new<Lt, Lg, C>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
latitude: Lt,
|
||||
longitude: Lg,
|
||||
) -> Self
|
||||
where
|
||||
Lt: Into<f64>,
|
||||
Lg: Into<f64>,
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
latitude: latitude.into(),
|
||||
longitude: longitude.into(),
|
||||
live_period: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn latitude<Lt>(mut self, value: Lt) -> Self
|
||||
where
|
||||
Lt: Into<f64>,
|
||||
{
|
||||
self.latitude = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn longitude<Lg>(mut self, value: Lg) -> Self
|
||||
where
|
||||
Lg: Into<f64>,
|
||||
{
|
||||
self.longitude = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn live_period<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.live_period = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.reply_to_message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network::request_multipart,
|
||||
requests::{form_builder::FormBuilder, Request, ResponseResult},
|
||||
types::{ChatId, InputFile, InputMedia, Message},
|
||||
};
|
||||
|
||||
/// Use this method to send a group of photos or videos as an album.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SendMediaGroup<'a> {
|
||||
bot: &'a Bot,
|
||||
|
||||
pub chat_id: ChatId,
|
||||
pub media: Vec<InputMedia>,
|
||||
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SendMediaGroup<'_> {
|
||||
type Output = Vec<Message>;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendMediaGroup<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Vec<Message>> {
|
||||
let form = FormBuilder::new()
|
||||
.add("chat_id", self.chat_id)
|
||||
.add("media", &self.media[..])
|
||||
.add("disable_notification", self.disable_notification)
|
||||
.add("reply_to_message_id", self.reply_to_message_id);
|
||||
|
||||
let form = self
|
||||
.media
|
||||
.into_iter()
|
||||
.filter_map(|e| InputFile::from(e).into())
|
||||
.fold(form, |acc, path: std::path::PathBuf| {
|
||||
acc.add_file(
|
||||
&path.file_name().unwrap().to_string_lossy().into_owned(),
|
||||
path,
|
||||
)
|
||||
});
|
||||
|
||||
request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendMediaGroup",
|
||||
form.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>>,
|
||||
{
|
||||
SendMediaGroup {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
media: media.into(),
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn media<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<Vec<InputMedia>>,
|
||||
{
|
||||
self.media = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.reply_to_message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message, ParseMode, ReplyMarkup},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
/// Use this method to send text messages. On success, the sent [`Message`] is
|
||||
/// returned.
|
||||
pub struct SendMessage<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target channel
|
||||
/// (in the format @channelusername)
|
||||
pub chat_id: ChatId,
|
||||
/// Text of the message to be sent
|
||||
pub text: String,
|
||||
|
||||
/// Send [Markdown] or [HTML],
|
||||
/// if you want Telegram apps to show [bold, italic, fixed-width text
|
||||
/// or inline URLs] in the media caption.
|
||||
///
|
||||
/// [Markdown]: crate::types::ParseMode::Markdown
|
||||
/// [HTML]: crate::types::ParseMode::HTML
|
||||
/// [bold, italic, fixed-width text or inline URLs]:
|
||||
/// crate::types::ParseMode
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
/// Disables link previews for links in this message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub disable_web_page_preview: Option<bool>,
|
||||
/// Sends the message silently. Users will receive a notification with no
|
||||
/// sound.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SendMessage<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendMessage<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendMessage",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendMessage<'a> {
|
||||
pub(crate) fn new<C, S>(bot: &'a Bot, chat_id: C, text: S) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
S: Into<String>,
|
||||
{
|
||||
SendMessage {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
text: text.into(),
|
||||
parse_mode: None,
|
||||
disable_web_page_preview: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn text<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.text = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ParseMode>,
|
||||
{
|
||||
self.parse_mode = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_web_page_preview<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.disable_web_page_preview = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.reply_to_message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ReplyMarkup>,
|
||||
{
|
||||
self.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,140 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{form_builder::FormBuilder, Request, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
/// Use this method to send photos. On success, the sent [`Message`] is
|
||||
/// returned.
|
||||
pub struct SendPhoto<'a> {
|
||||
bot: &'a Bot,
|
||||
|
||||
/// Unique identifier for the target chat or username of the target channel
|
||||
/// (in the format @channelusername)
|
||||
pub chat_id: ChatId,
|
||||
/// Photo to send.
|
||||
/// [`InputFile::FileId`] - Pass a file_id as String to send a photo that
|
||||
/// exists on the Telegram servers (recommended)
|
||||
/// [`InputFile::Url`] - Pass an HTTP URL as a String for Telegram
|
||||
/// to get a photo from the Internet
|
||||
/// [`InputFile::File`] - Upload a new photo.
|
||||
pub photo: InputFile,
|
||||
/// Photo caption (may also be used when resending photos by file_id),
|
||||
/// 0-1024 characters
|
||||
pub caption: Option<String>,
|
||||
/// Send [Markdown] or [HTML],
|
||||
/// if you want Telegram apps to show [bold, italic, fixed-width text
|
||||
/// or inline URLs] in the media caption.
|
||||
///
|
||||
/// [Markdown]: crate::types::ParseMode::Markdown
|
||||
/// [HTML]: crate::types::ParseMode::HTML
|
||||
/// [bold, italic, fixed-width text or inline URLs]:
|
||||
/// crate::types::ParseMode
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
/// Sends the message silently. Users will receive a notification with no
|
||||
/// sound.
|
||||
pub disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SendPhoto<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendPhoto<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Message> {
|
||||
let params = FormBuilder::new()
|
||||
.add("chat_id", self.chat_id)
|
||||
.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("photo", self.photo);
|
||||
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendPhoto",
|
||||
params.build(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendPhoto<'a> {
|
||||
pub(crate) fn new<C, P>(bot: &'a Bot, chat_id: C, photo: P) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
P: Into<InputFile>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
photo: photo.into(),
|
||||
caption: None,
|
||||
parse_mode: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>,
|
||||
{
|
||||
self.photo = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ParseMode>,
|
||||
{
|
||||
self.parse_mode = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.reply_to_message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message, ReplyMarkup},
|
||||
};
|
||||
|
||||
/// Use this method to send a native poll. A native poll can't be sent to a
|
||||
/// private chat. On success, the sent Message is returned.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SendPoll<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
/// identifier for the target chat or username of the target channel (in
|
||||
/// the format @channelusername). A native poll can't be sent to a private
|
||||
/// chat.
|
||||
chat_id: ChatId,
|
||||
/// Poll question, 1-255 characters
|
||||
question: String,
|
||||
/// List of answer options, 2-10 strings 1-100 characters each
|
||||
options: Vec<String>,
|
||||
/// Sends the message silently. Users will receive a notification with no
|
||||
/// sound.
|
||||
disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
reply_to_message_id: Option<i32>,
|
||||
/// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove
|
||||
/// or ForceReply Optional 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]
|
||||
impl Request for SendPoll<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendPoll<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendPoll",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
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>>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
question: question.into(),
|
||||
options: options.into(),
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn question<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.question = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn options<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<Vec<String>>,
|
||||
{
|
||||
self.options = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.reply_to_message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ReplyMarkup>,
|
||||
{
|
||||
self.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,173 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, Message, ReplyMarkup},
|
||||
};
|
||||
|
||||
/// Use this method to send information about a venue.
|
||||
/// Message is returned.
|
||||
#[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)
|
||||
pub chat_id: ChatId,
|
||||
/// Latitude of the venue
|
||||
pub latitude: f64,
|
||||
/// Longitude of the venue
|
||||
pub longitude: f64,
|
||||
/// Name of the venue
|
||||
pub title: String,
|
||||
/// Address of the venue
|
||||
pub address: String,
|
||||
/// Foursquare identifier of the venue
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub foursquare_id: Option<String>,
|
||||
/// Foursquare type of the venue, if known. (For
|
||||
/// example, “arts_entertainment/default”, “arts_entertainment/aquarium” or
|
||||
/// “food/icecream”.)
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub foursquare_type: Option<String>,
|
||||
/// Sends the message silently. Users will receive a
|
||||
/// notification with no sound.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original
|
||||
/// message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
/// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or
|
||||
/// ForceReply Optional 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.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SendVenue<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendVenue<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendVenue",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendVenue<'a> {
|
||||
pub(crate) fn new<Lt, Lg, C, T, A>(
|
||||
bot: &'a Bot,
|
||||
chat_id: C,
|
||||
latitude: Lt,
|
||||
longitude: Lg,
|
||||
title: T,
|
||||
address: A,
|
||||
) -> Self
|
||||
where
|
||||
Lt: Into<f64>,
|
||||
Lg: Into<f64>,
|
||||
C: Into<ChatId>,
|
||||
T: Into<String>,
|
||||
A: Into<String>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
latitude: latitude.into(),
|
||||
longitude: longitude.into(),
|
||||
title: title.into(),
|
||||
address: address.into(),
|
||||
foursquare_id: None,
|
||||
foursquare_type: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn longitude<Lg>(mut self, value: Lg) -> Self
|
||||
where
|
||||
Lg: Into<f64>,
|
||||
{
|
||||
self.longitude = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn latitude<Lt>(mut self, value: Lt) -> Self
|
||||
where
|
||||
Lt: Into<f64>,
|
||||
{
|
||||
self.latitude = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn title<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.title = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn address<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.address = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn foursquare_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.foursquare_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn foursquare_type<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.foursquare_type = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ReplyMarkup>,
|
||||
{
|
||||
self.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,199 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
};
|
||||
|
||||
///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.
|
||||
#[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)
|
||||
pub 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 »
|
||||
pub video: InputFile,
|
||||
///Duration of sent video in seconds
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub duration: Option<u64>,
|
||||
///Video width
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub width: Option<i32>,
|
||||
///Video height
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub 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 »
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub thumb: Option<InputFile>,
|
||||
///Video caption (may also be used when resending videos by file_id),
|
||||
/// 0-1024 characters
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub caption: Option<String>,
|
||||
///Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||
/// fixed-width text or inline URLs in the media caption.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
///Pass True, if the uploaded video is suitable for streaming
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub supports_streaming: Option<bool>,
|
||||
/// Sends the message silently. Users will receive a notification with no
|
||||
/// sound.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub disable_notification: Option<bool>,
|
||||
///If the message is a reply, ID of the original message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub 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.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SendVideo<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendVideo<'_> {
|
||||
async fn send(self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendVideo",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendVideo<'a> {
|
||||
pub(crate) fn new<C, V>(bot: &'a Bot, chat_id: C, video: V) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
V: Into<InputFile>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
video: video.into(),
|
||||
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, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn video<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>,
|
||||
{
|
||||
self.video = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn duration<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<u64>,
|
||||
{
|
||||
self.duration = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn width<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.width = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn height<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.height = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn thumb<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>,
|
||||
{
|
||||
self.thumb = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn caption<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn parse_mode<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ParseMode>,
|
||||
{
|
||||
self.parse_mode = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn supports_streaming<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.supports_streaming = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn disable_notification<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn reply_to_message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.reply_to_message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
pub fn reply_markup<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ReplyMarkup>,
|
||||
{
|
||||
self.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,158 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ReplyMarkup},
|
||||
};
|
||||
|
||||
///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.
|
||||
#[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)
|
||||
pub 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
|
||||
pub video_note: InputFile,
|
||||
///Duration of sent video in seconds
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub duration: Option<u64>,
|
||||
/// Video width and height, i.e. diameter of the video message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub length: Option<u64>,
|
||||
///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 »
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub thumb: Option<InputFile>,
|
||||
///Sends the message silently. Users will receive a notification with no
|
||||
/// sound.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub disable_notification: Option<bool>,
|
||||
///If the message is a reply, ID of the original message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub 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.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SendVideoNote<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendVideoNote<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendVideoNote",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendVideoNote<'a> {
|
||||
pub(crate) fn new<C, V>(bot: &'a Bot, chat_id: C, video_note: V) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
V: Into<InputFile>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
video_note: video_note.into(),
|
||||
duration: None,
|
||||
length: None,
|
||||
thumb: None,
|
||||
disable_notification: None,
|
||||
reply_to_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn video_note<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>,
|
||||
{
|
||||
self.video_note = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn duration<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<u64>,
|
||||
{
|
||||
self.duration = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn length<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<u64>,
|
||||
{
|
||||
self.length = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn thumb<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>,
|
||||
{
|
||||
self.thumb = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.reply_to_message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ReplyMarkup>,
|
||||
{
|
||||
self.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,156 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
};
|
||||
|
||||
///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.
|
||||
#[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)
|
||||
pub 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 »
|
||||
pub voice: InputFile,
|
||||
/// Voice message caption, 0-1024 characters
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub caption: Option<String>,
|
||||
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
|
||||
/// fixed-width text or inline URLs in the media caption.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub parse_mode: Option<ParseMode>,
|
||||
///Duration of the voice message in seconds
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub duration: Option<u64>,
|
||||
/// Sends the message silently. Users will receive a notification with
|
||||
/// no sound.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub disable_notification: Option<bool>,
|
||||
/// If the message is a reply, ID of the original message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reply_to_message_id: Option<i32>,
|
||||
/// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or
|
||||
/// ForceReply Optional 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.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reply_markup: Option<ReplyMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SendVoice<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SendVoice<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"sendVoice",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SendVoice<'a> {
|
||||
pub(crate) fn new<C, V>(bot: &'a Bot, chat_id: C, voice: V) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
V: Into<InputFile>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
voice: voice.into(),
|
||||
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, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn voice<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<InputFile>,
|
||||
{
|
||||
self.voice = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn caption<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.caption = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn parse_mode<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ParseMode>,
|
||||
{
|
||||
self.parse_mode = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn duration<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<u64>,
|
||||
{
|
||||
self.duration = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn disable_notification<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<bool>,
|
||||
{
|
||||
self.disable_notification = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_to_message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.reply_to_message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ReplyMarkup>,
|
||||
{
|
||||
self.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetChatDescription<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
chat_id: ChatId,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
description: Option<String>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SetChatDescription<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatDescription<'_> {
|
||||
pub async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
&self.bot.client(),
|
||||
&self.bot.token(),
|
||||
"setChatDescription",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SetChatDescription<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
description: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, chat_id: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = chat_id.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn description<T>(mut self, description: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.description = Some(description.into());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn serialize_new() {
|
||||
let bot = Bot::new("token");
|
||||
let chat_id = 123;
|
||||
let method = SetChatDescription::new(&bot, chat_id);
|
||||
|
||||
let expected = r#"{"chat_id":123}"#;
|
||||
let actual =
|
||||
serde_json::to_string::<SetChatDescription>(&method).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_description() {
|
||||
let bot = Bot::new("token");
|
||||
let chat_id = 123;
|
||||
let description = "description";
|
||||
let method =
|
||||
SetChatDescription::new(&bot, chat_id).description(description);
|
||||
|
||||
let expected = r#"{"chat_id":123,"description":"description"}"#;
|
||||
let actual =
|
||||
serde_json::to_string::<SetChatDescription>(&method).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, ChatPermissions, True},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetChatPermissions<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
chat_id: ChatId,
|
||||
permissions: ChatPermissions,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SetChatPermissions<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatPermissions<'_> {
|
||||
async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"setChatPermissions",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SetChatPermissions<'a> {
|
||||
pub(crate) fn new<C, CP>(bot: &'a Bot, chat_id: C, permissions: CP) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
CP: Into<ChatPermissions>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
permissions: permissions.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = chat_id.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn permissions<CP>(mut self, permissions: CP) -> Self
|
||||
where
|
||||
CP: Into<ChatPermissions>,
|
||||
{
|
||||
self.permissions = permissions.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn serialize() {
|
||||
let bot = Bot::new("token");
|
||||
let chat_id = 123;
|
||||
let permissions = ChatPermissions {
|
||||
can_send_messages: Some(true),
|
||||
can_send_media_messages: None,
|
||||
can_send_polls: None,
|
||||
can_send_other_messages: None,
|
||||
can_add_web_page_previews: None,
|
||||
can_change_info: None,
|
||||
can_invite_users: None,
|
||||
can_pin_messages: None,
|
||||
};
|
||||
let method = SetChatPermissions::new(&bot, chat_id, permissions);
|
||||
|
||||
let expected =
|
||||
r#"{"chat_id":123,"permissions":{"can_send_messages":true}}"#;
|
||||
let actual =
|
||||
serde_json::to_string::<SetChatPermissions>(&method).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{form_builder::FormBuilder, Request, ResponseResult},
|
||||
types::{ChatId, InputFile, True},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetChatPhoto<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
chat_id: ChatId,
|
||||
photo: InputFile,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SetChatPhoto<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatPhoto<'_> {
|
||||
async fn send(self) -> ResponseResult<True> {
|
||||
let params = FormBuilder::new()
|
||||
.add("chat_id", self.chat_id)
|
||||
.add("photo", self.photo);
|
||||
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"setChatPhoto",
|
||||
params.build(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SetChatPhoto<'a> {
|
||||
pub(crate) fn new<C, P>(bot: &'a Bot, chat_id: C, photo: P) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
P: Into<InputFile>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
photo: photo.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = chat_id.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo<P>(mut self, photo: P) -> Self
|
||||
where
|
||||
P: Into<InputFile>,
|
||||
{
|
||||
self.photo = photo.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn serialize() {
|
||||
let bot = Bot::new("token");
|
||||
let chat_id = 123;
|
||||
let photo_url = "https://some_url".to_string();
|
||||
let method =
|
||||
SetChatPhoto::new(&bot, chat_id, InputFile::Url(photo_url));
|
||||
|
||||
let expected = r#"{"chat_id":123,"photo":"https://some_url"}"#;
|
||||
let actual = serde_json::to_string::<SetChatPhoto>(&method).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
/// Use this method to set a new group sticker set for a supergroup. The bot
|
||||
/// must be an administrator in the chat for this to work and must have the
|
||||
/// appropriate admin rights. Use the field can_set_sticker_set optionally
|
||||
/// returned in getChat requests to check if the bot can use this method.
|
||||
/// Returns True on success.
|
||||
#[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]
|
||||
impl Request for SetChatStickerSet<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatStickerSet<'_> {
|
||||
async fn send(&self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"setChatStickerSet",
|
||||
&self,
|
||||
)
|
||||
.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>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
sticker_set_name: sticker_set_name.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn sticker_set_name<S>(mut self, value: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.sticker_set_name = value.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SetChatTitle<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
chat_id: ChatId,
|
||||
title: String,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for SetChatTitle<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl SetChatTitle<'_> {
|
||||
async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
&self.bot.client(),
|
||||
&self.bot.token(),
|
||||
"setChatTitle",
|
||||
&self,
|
||||
)
|
||||
.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>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
title: title.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<C>(mut self, chat_id: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = chat_id.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn title<C>(mut self, title: C) -> Self
|
||||
where
|
||||
C: Into<String>,
|
||||
{
|
||||
self.title = title.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn serialize() {
|
||||
let bot = Bot::new("token");
|
||||
let chat_id = 123;
|
||||
let title = "title";
|
||||
let method = SetChatTitle::new(&bot, chat_id, title);
|
||||
|
||||
let expected = r#"{"chat_id":123,"title":"title"}"#;
|
||||
let actual = serde_json::to_string::<SetChatTitle>(&method).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, InlineKeyboardMarkup, Message},
|
||||
};
|
||||
|
||||
/// 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.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct StopMessageLiveLocation<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
/// Required if inline_message_id is not specified. Unique identifier for
|
||||
/// the target chat or username of the target channel (in the format
|
||||
/// @channelusername)
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub chat_id: Option<ChatId>,
|
||||
/// Required if inline_message_id is not specified. Identifier of the
|
||||
/// message with live location to stop
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub message_id: Option<i32>,
|
||||
/// Required if chat_id and message_id are not specified. Identifier of the
|
||||
/// inline message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub inline_message_id: Option<String>,
|
||||
/// A JSON-serialized object InlineKeyboardMarkup for a new inline
|
||||
/// keyboard.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for StopMessageLiveLocation<'_> {
|
||||
type Output = Message;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl StopMessageLiveLocation<'_> {
|
||||
pub async fn send(self) -> ResponseResult<Message> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"stopMessageLiveLocation",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> StopMessageLiveLocation<'a> {
|
||||
pub(crate) fn new(bot: &'a Bot) -> Self {
|
||||
Self {
|
||||
bot,
|
||||
chat_id: None,
|
||||
message_id: None,
|
||||
inline_message_id: None,
|
||||
reply_markup: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn inline_message_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.inline_message_id = Some(value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn reply_markup<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<InlineKeyboardMarkup>,
|
||||
{
|
||||
self.reply_markup = Some(value.into());
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::ChatId,
|
||||
};
|
||||
|
||||
/// 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.
|
||||
#[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 @channelusername)
|
||||
pub chat_id: ChatId,
|
||||
/// Unique identifier of the target user
|
||||
pub user_id: i32,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for UnbanChatMember<'_> {
|
||||
type Output = bool;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl UnbanChatMember<'_> {
|
||||
pub async fn send(self) -> ResponseResult<bool> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"unbanChatMember",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> UnbanChatMember<'a> {
|
||||
pub(crate) fn new<C, U>(bot: &'a Bot, chat_id: C, user_id: U) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
U: Into<i32>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: chat_id.into(),
|
||||
user_id: user_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn user_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<i32>,
|
||||
{
|
||||
self.user_id = value.into();
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
network,
|
||||
requests::{Request, ResponseResult},
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct UnpinChatMessage<'a> {
|
||||
#[serde(skip_serializing)]
|
||||
bot: &'a Bot,
|
||||
|
||||
pub chat_id: ChatId,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for UnpinChatMessage<'_> {
|
||||
type Output = True;
|
||||
|
||||
async fn send_boxed(self) -> ResponseResult<Self::Output> {
|
||||
self.send().await
|
||||
}
|
||||
}
|
||||
|
||||
impl UnpinChatMessage<'_> {
|
||||
pub async fn send(self) -> ResponseResult<True> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
"unpinChatMessage",
|
||||
&self,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> UnpinChatMessage<'a> {
|
||||
pub(crate) fn new<C>(bot: &'a Bot, value: C) -> Self
|
||||
where
|
||||
C: Into<ChatId>,
|
||||
{
|
||||
Self {
|
||||
bot,
|
||||
chat_id: value.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat_id<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<ChatId>,
|
||||
{
|
||||
self.chat_id = value.into();
|
||||
self
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue