Struct telegram_bot::Api [−][src]
pub struct Api { /* fields omitted */ }
Main type for sending requests to the Telegram bot API.
You can create an API
object via from_token
or from_env
. A Listener
object is obtained via listener
. All remaining methods correspond
directly to a telegram API call and are named like the API method, but in
camel_case
.
Methods
impl Api
[src]
impl Api
pub fn from_token(token: &str) -> Result<Api>
[src]
pub fn from_token(token: &str) -> Result<Api>
Creates a new bot with the given token. If the token is completely
invalid (resulting in an invalid API-URL), the function will return
an Err
value. However, the function will not check if the given token
is a valid Telegram token. You can call get_me
to execute a test
request.
pub fn from_env(var: &str) -> Result<Api>
[src]
pub fn from_env(var: &str) -> Result<Api>
Will receive the bot token from the environment variable var
and call
from_token
with it. Will return an Err
value, if the environment
var could not be read or the token has an invalid format.
pub fn get_me(&self) -> Result<User>
[src]
pub fn get_me(&self) -> Result<User>
Corresponds to the "getMe" method of the API.
pub fn send_message(
&self,
chat_id: Integer,
text: String,
parse_mode: Option<ParseMode>,
disable_web_page_preview: Option<bool>,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
[src]
pub fn send_message(
&self,
chat_id: Integer,
text: String,
parse_mode: Option<ParseMode>,
disable_web_page_preview: Option<bool>,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
Corresponds to the "sendMessage" method of the API.
pub fn forward_message(
&self,
chat_id: Integer,
from_chat_id: Integer,
message_id: Integer
) -> Result<Message>
[src]
pub fn forward_message(
&self,
chat_id: Integer,
from_chat_id: Integer,
message_id: Integer
) -> Result<Message>
Corresponds to the "forwardMessage" method of the API.
pub fn send_location(
&self,
chat_id: Integer,
latitude: Float,
longitude: Float,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
[src]
pub fn send_location(
&self,
chat_id: Integer,
latitude: Float,
longitude: Float,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
Corresponds to the "sendLocation" method of the API.
pub fn send_chat_action(
&self,
chat_id: Integer,
action: ChatAction
) -> Result<bool>
[src]
pub fn send_chat_action(
&self,
chat_id: Integer,
action: ChatAction
) -> Result<bool>
Corresponds to the "sendChatAction" method of the API.
pub fn get_user_profile_photos(
&self,
user_id: Integer,
offset: Option<Integer>,
limit: Option<Integer>
) -> Result<UserProfilePhotos>
[src]
pub fn get_user_profile_photos(
&self,
user_id: Integer,
offset: Option<Integer>,
limit: Option<Integer>
) -> Result<UserProfilePhotos>
Corresponds to the "getUserProfilePhotos" method of the API.
pub fn get_updates(
&self,
offset: Option<Integer>,
limit: Option<Integer>,
timeout: Option<Integer>
) -> Result<Vec<Update>>
[src]
pub fn get_updates(
&self,
offset: Option<Integer>,
limit: Option<Integer>,
timeout: Option<Integer>
) -> Result<Vec<Update>>
Corresponds to the "getUpdates" method of the API.
Note:
The method will not set the offset parameter on its own. To receive
updates in a more high level way, see listener
.
pub fn send_photo(
&self,
chat_id: Integer,
path: String,
caption: Option<String>,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
[src]
pub fn send_photo(
&self,
chat_id: Integer,
path: String,
caption: Option<String>,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
Corresponds to the sendPhoto
method of the API.
pub fn send_audio(
&self,
chat_id: Integer,
path: String,
duration: Option<Integer>,
performer: Option<String>,
title: Option<String>,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
[src]
pub fn send_audio(
&self,
chat_id: Integer,
path: String,
duration: Option<Integer>,
performer: Option<String>,
title: Option<String>,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
Corresponds to the sendAudio
method of the API.
pub fn send_voice(
&self,
chat_id: Integer,
path: String,
duration: Option<Integer>,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
[src]
pub fn send_voice(
&self,
chat_id: Integer,
path: String,
duration: Option<Integer>,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
Corresponds to the sendVoice
method of the API.
pub fn send_document(
&self,
chat_id: Integer,
path: String,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
[src]
pub fn send_document(
&self,
chat_id: Integer,
path: String,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
Corresponds to the sendDocument
method of the API.
pub fn send_sticker(
&self,
chat_id: Integer,
path: String,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
[src]
pub fn send_sticker(
&self,
chat_id: Integer,
path: String,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
Corresponds to the sendSticker
method of the API.
pub fn send_video(
&self,
chat_id: Integer,
path: String,
caption: Option<String>,
duration: Option<Integer>,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
[src]
pub fn send_video(
&self,
chat_id: Integer,
path: String,
caption: Option<String>,
duration: Option<Integer>,
reply_to_message_id: Option<Integer>,
reply_markup: Option<ReplyMarkup>
) -> Result<Message>
Corresponds to the sendVideo
method of the API.
pub fn set_webhook<U: IntoUrl>(&self, url: Option<U>) -> Result<bool>
[src]
pub fn set_webhook<U: IntoUrl>(&self, url: Option<U>) -> Result<bool>
Corresponds to the setWebhook
method of the API.
Note: This library does not yet offer the feature to listen via webhook. This is just the raw telegram API request and will do nothing more. Use only if you know what you're doing.
pub fn listener(&self, method: ListeningMethod) -> Listener
[src]
pub fn listener(&self, method: ListeningMethod) -> Listener
Receive and handle updates via "getUpdates".
This method will repeatedly call get_updates
to receive new updates.
It will then call the given handler for every update and increase the
update offset accordingly, so the handler will never be called with
the same update twice.
The timeout
parameter influences how long (in seconds) each poll may
last. Defaults to 30.
The handler gets a mutable reference to the bot since borrowing it
from the outer scope won't work. When the handler returns an Err
value the bot will stop listening for updates and long_poll
will
return the Error. If you want to stop listening you can just return
Error::UserInterrupt
.
Note: If the bot is restarted, but the last received updates are not yet confirmed (the last poll was not empty), there will be some duplicate updates.