diff --git a/src/requests/send_voice.rs b/src/requests/send_voice.rs index 88b2ef66..7b945fb9 100644 --- a/src/requests/send_voice.rs +++ b/src/requests/send_voice.rs @@ -1,8 +1,155 @@ -use crate::requests::RequestContext; +use crate::network; +use crate::requests::{ChatId, Request, RequestContext, ResponseResult}; +use crate::types::{Message, ReplyMarkup, ParseMode}; +use async_trait::async_trait; -///TODO: add implementation +///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)] ctx: RequestContext<'a>, + /// 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: String, //InputFile or String + /// Voice message caption, 0-1024 characters + #[serde(skip_serializing_if = "Option::is_none")] + pub caption: Option, + /// 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, + ///Duration of the voice message in seconds + #[serde(skip_serializing_if = "Option::is_none")] + pub duration: Option, + /// Sends the message silently. Users will receive a notification with + /// no sound. + #[serde(skip_serializing_if = "Option::is_none")] + pub disable_notification: Option, + /// If the message is a reply, ID of the original message + #[serde(skip_serializing_if = "Option::is_none")] + pub reply_to_message_id: Option, + /// 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, +} + +#[async_trait] +impl Request for SendVoice<'_> { + type ReturnValue = Message; + + async fn send_boxed(self) -> ResponseResult { + self.send().await + } +} + +impl SendVoice<'_> { + pub async fn send(self) -> ResponseResult { + network::request_json( + &self.ctx.client, + &self.ctx.token, + "sendVoice", + &self, + ) + .await + } +} + +impl<'a> SendVoice<'a> { + pub(crate) fn new( + ctx: RequestContext<'a>, + chat_id: ChatId, + voice: String, + ) -> Self { + Self { + ctx, + chat_id, + voice, + caption: None, + parse_mode: None, + duration: None, + disable_notification: None, + reply_to_message_id: None, + reply_markup: None, + } + } + + pub fn chat_id(mut self, chat_id: T) -> Self + where + T: Into, + { + self.chat_id = chat_id.into(); + self + } + + pub fn voice(mut self, voice: T) -> Self + where + T: Into, + { + self.voice = voice.into(); + self + } + + pub fn caption(mut self, caption: T) -> Self + where + T: Into, + { + self.caption = Some(caption.into()); + self + } + + pub fn parse_mode(mut self, parse_mode: T) -> Self + where + T: Into, + { + self.parse_mode = Some(parse_mode.into()); + self + } + + + pub fn duration(mut self, duration: T) -> Self + where + T: Into, + { + self.duration = Some(duration.into()); + self + } + + pub fn disable_notification(mut self, disable_notification: T) -> Self + where + T: Into, + { + self.disable_notification = Some(disable_notification.into()); + self + } + + pub fn reply_to_message_id(mut self, reply_to_message_id: T) -> Self + where + T: Into, + { + self.reply_to_message_id = Some(reply_to_message_id.into()); + self + } + + + pub fn reply_markup(mut self, reply_markup: T) -> Self + where + T: Into, + { + self.reply_markup = Some(reply_markup.into()); + self + } + }