Struct awesome_bot::AwesomeBot [−][src]
Main type for building the Telegram Bot.
Create a new instance using new
or from_env
, add routing handlers and start the bot.
Fields
id: Integer
The ID of the bot.
username: String
The username of the bot.
Methods
impl AwesomeBot
[src]
impl AwesomeBot
pub fn new(token: &str) -> AwesomeBot
[src]
pub fn new(token: &str) -> AwesomeBot
Creates a new bot with the given token. This checks that the token is a
valid Telegram Bot Token by calling get_me
.
It panics if the token is invalid.
pub fn from_env(var: &str) -> AwesomeBot
[src]
pub fn from_env(var: &str) -> AwesomeBot
Will receive the Bot Token from the environment variable var
and call new
.
It panics if the environment variable can't be read or if the token is invalid.
pub fn simple_start(&self) -> Result<()>
[src]
pub fn simple_start(&self) -> Result<()>
Start the bot using getUpdates
method, calling the routes defined before calling this method.
pub fn send(&self, id: Integer) -> SendBuilder
[src]
pub fn send(&self, id: Integer) -> SendBuilder
Start a SendBuilder directly with the id, this is useful when you have the id saved and want to send a message.
pub fn answer(&self, m: &Message) -> SendBuilder
[src]
pub fn answer(&self, m: &Message) -> SendBuilder
Start a SendBuilder answering a message directly, this is used to answer in a handler to the sender of the message.
impl AwesomeBot
[src]
impl AwesomeBot
Methods to add function handlers to different routes.
The different parameters of the handlers are:
- Common:
&AwesomeBot
: First argument of all the handlers is the bot itself, so you can send/answer.&Message
: Second argument of all the handlers is the message that has triggered the handler, you can grab all the information you want. This struct comes fromtelegram-bot
crate.
- Specific to some handlers:
String
: Refers to the full text if it's a command or regular expression, or the new title of a group.Vec<String>
: These are only incommand
andregex
methods, and represent a vector of the capture groups.Vec<PhotoSize>
: Represents an image (it's received in different sizes) and you get it when a photo arrives or when someone change a group photo.Video
,Document
,Sticker
,Audio
,Voice
,GeneralSound
,Contact
,Float
: All these parameters are the media that made the handler trigger, for example, invideo_fn
you will receive aVideo
.User
: An User is received when a participants leave or enter a group.Chat::Group
: Whenever someone delete a chat photo, or create a group (add the bot to the group) you receive this.
pub fn command<H>(&mut self, pattern: &str, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, String, Vec<String>) + Send + Sync + 'static,
[src]
pub fn command<H>(&mut self, pattern: &str, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, String, Vec<String>) + Send + Sync + 'static,
Add complex command routing (With capture groups).
This method will transform the pattern to be exhaustive and include the mention to the bot,
for example, the pattern echo (.+)
will be used inside an the regular expression
^/start(?:@usernamebot)? (.+)$
pub fn simple_command<H>(
&mut self,
pattern: &str,
handler: H
) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, String) + Send + Sync + 'static,
[src]
pub fn simple_command<H>(
&mut self,
pattern: &str,
handler: H
) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, String) + Send + Sync + 'static,
Add simple command routing (Without capture groups).
This method will transform the pattern the same as command
method, but the handler
will not receive the capture groups.
pub fn regex<H>(&mut self, pattern: &str, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, String, Vec<String>) + Send + Sync + 'static,
[src]
pub fn regex<H>(&mut self, pattern: &str, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, String, Vec<String>) + Send + Sync + 'static,
Add complex regular expression routing (With capture groups)
This method won't tranform anything about the regular expression, you are free to write the expression you want and receive the capture groups matched.
pub fn simple_regex<H>(&mut self, pattern: &str, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, String) + Send + Sync + 'static,
[src]
pub fn simple_regex<H>(&mut self, pattern: &str, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, String) + Send + Sync + 'static,
Add complex regular expression routing (Without capture groups)
This method won't tranform anything about the regular expression, you are free to write
the expression. The difference from regex
is that you won't receive any capture groups.
pub fn any_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message) + Send + Sync + 'static,
[src]
pub fn any_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message) + Send + Sync + 'static,
Add a routing handler that will be triggerer on every message, useful for logging.
pub fn photo_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Vec<PhotoSize>) + Send + Sync + 'static,
[src]
pub fn photo_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Vec<PhotoSize>) + Send + Sync + 'static,
Add a photo media routing handler.
pub fn video_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Video) + Send + Sync + 'static,
[src]
pub fn video_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Video) + Send + Sync + 'static,
Add a video media routing handler.
pub fn document_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Document) + Send + Sync + 'static,
[src]
pub fn document_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Document) + Send + Sync + 'static,
Add a document media routing handler.
pub fn sticker_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Sticker) + Send + Sync + 'static,
[src]
pub fn sticker_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Sticker) + Send + Sync + 'static,
Add a sticker media routing handler.
pub fn audio_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Audio) + Send + Sync + 'static,
[src]
pub fn audio_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Audio) + Send + Sync + 'static,
Add an audio media routing handler.
pub fn voice_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Voice) + Send + Sync + 'static,
[src]
pub fn voice_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Voice) + Send + Sync + 'static,
Add a voice media routing handler.
pub fn all_music_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, GeneralSound) + Send + Sync + 'static,
[src]
pub fn all_music_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, GeneralSound) + Send + Sync + 'static,
Add a routing handler that is triggered when an Audio
or a Voice
is received.
pub fn contact_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Contact) + Send + Sync + 'static,
[src]
pub fn contact_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Contact) + Send + Sync + 'static,
Add a contact routing handler.
pub fn location_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Float, Float) + Send + Sync + 'static,
[src]
pub fn location_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Float, Float) + Send + Sync + 'static,
Add a location routing handler.
pub fn new_participant_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, User) + Send + Sync + 'static,
[src]
pub fn new_participant_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, User) + Send + Sync + 'static,
Add a routing handler that is triggered when a new participant enters a group.
pub fn left_participant_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, User) + Send + Sync + 'static,
[src]
pub fn left_participant_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, User) + Send + Sync + 'static,
Add a routing handler that is triggered when a participant leaves a group.
pub fn new_title_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, String) + Send + Sync + 'static,
[src]
pub fn new_title_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, String) + Send + Sync + 'static,
Add a routing handler that is triggered when the title of a group chat is changed.
pub fn new_chat_photo_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Vec<PhotoSize>) + Send + Sync + 'static,
[src]
pub fn new_chat_photo_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Vec<PhotoSize>) + Send + Sync + 'static,
Add a routing handler that is triggered when the photo of a group chat is changed.
pub fn delete_chat_photo_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Chat) + Send + Sync + 'static,
[src]
pub fn delete_chat_photo_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Chat) + Send + Sync + 'static,
Add a routing handler that is triggered when the photo of a group chat is deleted.
pub fn group_chat_created_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Chat) + Send + Sync + 'static,
[src]
pub fn group_chat_created_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Chat) + Send + Sync + 'static,
Add a routing handler that is triggered when a group chat is created.
pub fn super_group_chat_created_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, GroupToSuperGroupMigration) + Send + Sync + 'static,
[src]
pub fn super_group_chat_created_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, GroupToSuperGroupMigration) + Send + Sync + 'static,
Add a routing handler that is triggered when a super group chat is created.
pub fn channel_chat_created_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Chat) + Send + Sync + 'static,
[src]
pub fn channel_chat_created_fn<H>(&mut self, handler: H) -> &mut AwesomeBot where
H: Fn(&AwesomeBot, &Message, Chat) + Send + Sync + 'static,
Add a routing handler that is triggered when a channel chat is created.
Trait Implementations
impl Clone for AwesomeBot
[src]
impl Clone for AwesomeBot
fn clone(&self) -> AwesomeBot
[src]
fn clone(&self) -> AwesomeBot
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl Send for AwesomeBot
impl Send for AwesomeBot
impl Sync for AwesomeBot
impl Sync for AwesomeBot