refactored and added docs

This commit is contained in:
P0lunin 2019-09-07 20:07:01 +03:00
parent 58ae51f318
commit fa8cefe504
4 changed files with 39 additions and 1 deletions

View file

@ -5,6 +5,8 @@ use crate::core::requests::{
use crate::core::types::User;
#[derive(Debug, Clone)]
/// A simple method for testing your bot's auth token. Requires no parameters.
/// Returns basic information about the bot in form of a [`User`] object.
pub struct GetMe<'a> {
info: RequestContext<'a>,
}

View file

@ -5,15 +5,30 @@ use crate::core::requests::{
use crate::core::{network, types::Message, types::ParseMode};
#[derive(Debug, Clone)]
/// Use this method to send text messages. On success, the sent [`Message`] is returned.
pub struct SendMessage<'a> {
info: RequestContext<'a>,
/// 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::core::types::ParseMode::Markdown
/// [Html]: crate::core::types::ParseMode::Html
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::core::types::ParseMode
pub parse_mode: Option<ParseMode>,
/// Disables link previews for links in this message
pub disable_web_page_preview: Option<bool>,
/// Sends the message silently. Users will receive a notification with no sound.
pub disable_notification: Option<bool>,
/// If the message is a reply, ID of the original message
pub reply_to_message_id: Option<i64>,
pub reply_markup: Option<()>, // TODO: ReplyMarkup enum
}

View file

@ -6,14 +6,34 @@ use crate::core::requests::form_builder::FormBuilder;
use crate::core::network;
#[derive(Debug, Clone)]
/// Use this method to send photos. On success, the sent [`Message`] is returned.
pub struct SendPhoto<'a> {
ctx: RequestContext<'a>,
/// 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::core::types::ParseMode::Markdown
/// [Html]: crate::core::types::ParseMode::Html
/// [bold, italic, fixed-width text or inline URLs]:
/// crate::core::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<i64>,
// TODO: add reply_markup

View file

@ -23,6 +23,7 @@ pub fn file_to_part(path_to_file: &PathBuf) -> Part {
let file = tokio::fs::File::open(path_to_file.clone())
.map(|file| FramedRead::new(file, FileDecoder))
.flatten_stream();
let part = Part::stream(file).file_name(path_to_file.file_name().unwrap().to_str().unwrap().to_string());
let part = Part::stream(file)
.file_name(path_to_file.file_name().unwrap().to_string_lossy().into_owned());
part
}