Struct tbot::bot::Bot[][src]

#[must_use]pub struct Bot { /* fields omitted */ }

A Bot is the entry point to interacting with the Bot API.

Using a Bot, you can call methods from the methods module:

let bot = tbot::from_env!("BOT_TOKEN");
let me = bot.get_me().call().await?;
dbg!(me);

A Bot is also used to construct an EventLoop — a struct responsible for configuring handlers and listening to updates:

use tbot::prelude::*;

let mut bot = tbot::from_env!("BOT_TOKEN").event_loop();

bot.start(|context| async move {
   let result = context.send_message_in_reply("Hi!").call().await;

    if let Err(error) = result {
        eprintln!("Failed to send a message: {}", error);
    }
});

bot.polling().start().await?;

A Bot can be constructed in several ways:

The bot’s internal data (its token, proxy and the URL where it makes requests) is kept behind an Arc. It means that you can clone a Bot cheaply to share it between tasks.

Implementations

impl Bot[src]

pub fn new(token: String) -> Self[src]

Constructs a new Bot.

This method is a shorthand for a common case. If you need advanced configuration, e.g. you want to set a proxy or use a local Bot API server, construct a Bot using a bot::Builder.

pub fn from_env(env_var: &'static str) -> Self[src]

Constructs a new Bot, extracting the token from the environment at runtime.

If you need to extract the token at compile time, use from_env!.

This method is a shorthand for a common case. If you need advanced configuration, e.g. you want to set a proxy or use a local Bot API server, construct a Bot using a bot::Builder.

Example

use tbot::Bot;

let bot = Bot::from_env("BOT_TOKEN");
let me = bot.get_me().call().await.unwrap();
dbg!(me);

pub async fn download_file(&self, file: &File) -> Result<Vec<u8>, Download>[src]

Downloads a file.

If you use a self-hosted Bot API server, file.path may be an absolute local path. In this case, tbot reads the file at the given and returns it. If the server is running on another machine, you have to handle this case manually before calling this method.

pub fn event_loop(self) -> EventLoop[src]

Constructs an EventLoop.

pub fn stateful_event_loop<S>(self, state: S) -> StatefulEventLoop<S> where
    S: Send + Sync + 'static, 
[src]

Constructs a stateful event loop.

pub fn add_sticker_to_set(
    &self,
    user_id: Id,
    name: impl Into<String>,
    png_sticker: impl Into<StickerForStickerSet>,
    emojis: impl Into<String>
) -> AddStickerToSet<'_>
[src]

Adds a new sticker to an existing sticker set.

pub fn copy_message(
    &self,
    chat_id: impl ImplicitChatId,
    from_chat_id: impl ImplicitChatId,
    message_id: Id
) -> CopyMessage<'_>
[src]

Copies a message.

Creates a secondary invite link for a chat.

pub fn create_new_sticker_set(
    &self,
    user_id: Id,
    name: impl Into<String>,
    title: impl Into<String>,
    png_sticker: impl Into<StickerForStickerSet>,
    emojis: impl Into<String>
) -> CreateNewStickerSet<'_>
[src]

Creates a new sticker set.

pub fn delete_chat_photo(
    &self,
    chat_id: impl ImplicitChatId
) -> DeleteChatPhoto<'_>
[src]

Deletes a chat’s photo.

pub fn delete_chat_sticker_set(
    &self,
    chat_id: impl ImplicitChatId
) -> DeleteChatStickerSet<'_>
[src]

Deletes a chat’s sticker set.

pub fn delete_message(
    &self,
    chat_id: impl ImplicitChatId,
    message_id: Id
) -> DeleteMessage<'_>
[src]

Deletes a message from a chat.

pub fn delete_sticker_from_set(
    &self,
    sticker: impl Into<String>
) -> DeleteStickerFromSet<'_>
[src]

Deletes a sticker from a sticker set.

Edits a secondary invite link for a chat.

pub fn edit_inline_caption(
    &self,
    inline_message_id: InlineMessageId,
    caption: impl Into<Text>
) -> EditInlineCaption<'_>
[src]

Edits the caption of a media message sent via the inline mode.

pub fn edit_inline_location(
    &self,
    inline_message_id: InlineMessageId,
    position: (f64, f64)
) -> EditInlineLocation<'_>
[src]

Edits a live location sent via the inline mode.

pub fn edit_inline_media(
    &self,
    inline_message_id: InlineMessageId,
    media: impl Into<EditableMedia>
) -> EditInlineMedia<'_>
[src]

Edits the media of a message sent via the inline mode.

pub fn edit_inline_reply_markup(
    &self,
    inline_message_id: InlineMessageId,
    reply_markup: Keyboard
) -> EditInlineReplyMarkup<'_>
[src]

Edits the inline keyboard of a message sent via the inline mode.

pub fn edit_inline_text(
    &self,
    inline_message_id: InlineMessageId,
    text: impl Into<Text>
) -> EditInlineText<'_>
[src]

Edits the text of a message sent via the inline mode.

pub fn edit_message_caption(
    &self,
    chat_id: impl ImplicitChatId,
    message_id: Id,
    caption: impl Into<Text>
) -> EditMessageCaption<'_>
[src]

Edits the caption of a media message sent by the bot itself.

pub fn edit_message_location(
    &self,
    chat_id: impl ImplicitChatId,
    message_id: Id,
    position: (f64, f64)
) -> EditMessageLocation<'_>
[src]

Edits a live location sent by the bot itself.

pub fn edit_message_media(
    &self,
    chat_id: impl ImplicitChatId,
    message_id: Id,
    media: impl Into<EditableMedia>
) -> EditMessageMedia<'_>
[src]

Edits a live location sent by the bot itself.

pub fn edit_message_reply_markup(
    &self,
    chat_id: impl ImplicitChatId,
    message_id: Id,
    reply_markup: Keyboard
) -> EditMessageReplyMarkup<'_>
[src]

Edits the inline keyboard of a message sent by the bot itself.

pub fn edit_message_text(
    &self,
    chat_id: impl ImplicitChatId,
    message_id: Id,
    text: impl Into<Text>
) -> EditMessageText<'_>
[src]

Edits the text of a message sent by the bot itself.

Exports a chat’s invite link.

pub fn forward_message(
    &self,
    chat_id: impl ImplicitChatId,
    from_chat_id: impl ImplicitChatId,
    message_id: Id
) -> ForwardMessage<'_>
[src]

Forwards a message.

pub fn get_chat(&self, chat_id: impl ImplicitChatId) -> GetChat<'_>[src]

Gets information about a chat.

pub fn get_file(&self, file_id: Id) -> GetFile<'_>[src]

Gets information about a file.

pub fn get_inline_game_high_scores(
    &self,
    inline_message_id: InlineMessageId,
    user_id: Id
) -> GetInlineGameHighScores<'_>
[src]

Gets an excerpt from the high score table of a game sent via the inline mode.

pub fn get_chat_administrators(
    &self,
    chat_id: impl ImplicitChatId
) -> GetChatAdministrators<'_>
[src]

Gets information about a chat’s admins.

pub fn get_chat_member(
    &self,
    chat_id: impl ImplicitChatId,
    user_id: Id
) -> GetChatMember<'_>
[src]

Gets information about a chat’s member.

pub fn get_chat_members_count(
    &self,
    chat_id: impl ImplicitChatId
) -> GetChatMembersCount<'_>
[src]

Gets a chat’s member count.

pub fn get_message_game_high_scores(
    &self,
    chat_id: impl ImplicitChatId,
    message_id: Id,
    user_id: Id
) -> GetMessageGameHighScores<'_>
[src]

Gets an excerpt from the high score table of a game sent by the bot itself.

pub fn get_me(&self) -> GetMe<'_>[src]

Gets information about the bot.

pub fn get_my_commands(&self) -> GetMyCommands<'_>[src]

Gets the list of the bot’s commands.

pub fn get_sticker_set(&self, name: impl Into<String>) -> GetStickerSet<'_>[src]

Gets a sticker set by its name.

pub fn get_user_profile_photos(&self, user_id: Id) -> GetUserProfilePhotos<'_>[src]

Gets a user’s profile photos.

pub fn get_webhook_info(&self) -> GetWebhookInfo<'_>[src]

Gets information about the bot’s webhook.

pub fn kick_chat_member(
    &self,
    chat_id: impl ImplicitChatId,
    user_id: Id
) -> KickChatMember<'_>
[src]

Kicks a member out of a chat.

pub fn leave_chat(&self, chat_id: impl ImplicitChatId) -> LeaveChat<'_>[src]

Leaves a chat.

pub fn pin_chat_message(
    &self,
    chat_id: impl ImplicitChatId,
    message_id: Id
) -> PinChatMessage<'_>
[src]

Pins a message in a chat.

pub fn promote_chat_member(
    &self,
    chat_id: impl ImplicitChatId,
    user_id: Id
) -> PromoteChatMember<'_>
[src]

Promotes a chat member to an admin.

pub fn restrict_chat_member(
    &self,
    chat_id: impl ImplicitChatId,
    user_id: Id,
    permissions: Permissions
) -> RestrictChatMember<'_>
[src]

Restricts a chat member.

Revokes an invite link for a chat.

pub fn send_animation(
    &self,
    chat_id: impl ImplicitChatId,
    animation: Animation
) -> SendAnimation<'_>
[src]

Sends an animation.

pub fn send_audio(
    &self,
    chat_id: impl ImplicitChatId,
    audio: Audio
) -> SendAudio<'_>
[src]

Sends an audio.

pub fn send_chat_action(
    &self,
    chat_id: impl ImplicitChatId,
    action: Action
) -> SendChatAction<'_>
[src]

Sends a chat action.

pub fn send_contact(
    &self,
    chat_id: impl ImplicitChatId,
    phone_number: impl Into<String>,
    first_name: impl Into<String>
) -> SendContact<'_>
[src]

Sends a contact.

pub fn send_game(
    &self,
    chat_id: impl ImplicitChatId,
    game_short_name: impl Into<String>
) -> SendGame<'_>
[src]

Sends a game.

pub fn send_dice(&self, chat_id: impl ImplicitChatId) -> SendDice<'_>[src]

Sends a dice.

pub fn send_document(
    &self,
    chat_id: impl ImplicitChatId,
    document: Document
) -> SendDocument<'_>
[src]

Sends a document.

pub fn send_invoice(
    &self,
    chat_id: impl Into<Id>,
    title: impl Into<String>,
    description: impl Into<String>,
    payload: impl Into<String>,
    provider_token: impl Into<String>,
    start_parameter: impl Into<String>,
    currency: impl Into<String>,
    prices: impl Into<Vec<LabeledPrice>>
) -> SendInvoice<'_>
[src]

Sends an invoice.

pub fn send_location(
    &self,
    chat_id: impl ImplicitChatId,
    position: (f64, f64)
) -> SendLocation<'_>
[src]

Sends a location.

pub fn send_media_group(
    &self,
    chat_id: impl ImplicitChatId,
    media: impl Into<MediaGroup>
) -> SendMediaGroup<'_>
[src]

Sends an album.

pub fn send_message(
    &self,
    chat_id: impl ImplicitChatId,
    text: impl Into<Text>
) -> SendMessage<'_>
[src]

Sends a text message.

pub fn send_photo(
    &self,
    chat_id: impl ImplicitChatId,
    photo: Photo
) -> SendPhoto<'_>
[src]

Sends a photo.

pub fn send_poll(&self, chat_id: impl ImplicitChatId, poll: Any) -> SendPoll<'_>[src]

Sends a poll.

pub fn send_sticker(
    &self,
    chat_id: impl ImplicitChatId,
    sticker: Sticker
) -> SendSticker<'_>
[src]

Sends a sticker.

pub fn send_venue(
    &self,
    chat_id: impl ImplicitChatId,
    position: (f64, f64),
    title: impl Into<String>,
    address: impl Into<String>
) -> SendVenue<'_>
[src]

Sends a venue.

pub fn send_video_note(
    &self,
    chat_id: impl ImplicitChatId,
    video_note: VideoNote
) -> SendVideoNote<'_>
[src]

Sends a video note.

pub fn send_video(
    &self,
    chat_id: impl ImplicitChatId,
    video: Video
) -> SendVideo<'_>
[src]

Sends a video.

pub fn send_voice(
    &self,
    chat_id: impl ImplicitChatId,
    voice: Voice
) -> SendVoice<'_>
[src]

Sends a voice.

pub fn set_chat_administrator_custom_title(
    &self,
    chat_id: impl ImplicitChatId,
    user_id: Id,
    custom_title: impl Into<String>
) -> SetChatAdministratorCustomTitle<'_>
[src]

Sets a custom title for an admin in a chat.

pub fn set_chat_description(
    &self,
    chat_id: impl ImplicitChatId,
    description: impl Into<String>
) -> SetChatDescription<'_>
[src]

Sets a chat’s description.

pub fn set_chat_permissions(
    &self,
    chat_id: impl ImplicitChatId,
    permissions: Permissions
) -> SetChatPermissions<'_>
[src]

Sets a group’s global permissions.

pub fn set_chat_photo(
    &self,
    chat_id: impl ImplicitChatId,
    photo: ChatPhoto
) -> SetChatPhoto<'_>
[src]

Sets a chat’s photo.

pub fn set_chat_sticker_set(
    &self,
    chat_id: impl ImplicitChatId,
    sticker_set_name: impl Into<String>
) -> SetChatStickerSet<'_>
[src]

Sets a group’s sticker set.

pub fn set_chat_title(
    &self,
    chat_id: impl ImplicitChatId,
    title: impl Into<String>
) -> SetChatTitle<'_>
[src]

Sets a group’s title.

pub fn set_inline_game_score(
    &self,
    inline_message_id: InlineMessageId,
    user_id: Id,
    score: u32
) -> SetInlineGameScore<'_>
[src]

Sets a user’s new high score in a game sent via the inline mode.

pub fn set_message_game_score(
    &self,
    chat_id: impl ImplicitChatId,
    message_id: Id,
    user_id: Id,
    score: u32
) -> SetMessageGameScore<'_>
[src]

Sets a user’s new high score in a game sent by the bot itself.

pub fn set_my_commands(
    &self,
    commands: impl Into<Vec<BotCommand>>
) -> SetMyCommands<'_>
[src]

Sets the list of the bot’s commands.

pub fn set_passport_data_errors(
    &self,
    user_id: Id,
    errors: impl Into<Vec<Error>>
) -> SetPassportDataErrors<'_>
[src]

Reports passport errors to the user.

pub fn set_sticker_position_in_set(
    &self,
    sticker: impl Into<String>,
    position: u32
) -> SetStickerPositionInSet<'_>
[src]

Changes a sticker’s position in a sticker set.

pub fn set_sticker_set_thumb(
    &self,
    user_id: Id,
    name: impl Into<String>,
    thumb: Option<StickerSetThumb>
) -> SetStickerSetThumb<'_>
[src]

Sets the thumb of a sticker set.

pub fn stop_inline_location(
    &self,
    inline_message_id: InlineMessageId
) -> StopInlineLocation<'_>
[src]

Stops a live location sent via the inline mode.

pub fn stop_message_location(
    &self,
    chat_id: impl ImplicitChatId,
    message_id: Id
) -> StopMessageLocation<'_>
[src]

Stops a live location sent by the bot itself.

pub fn stop_poll(
    &self,
    chat_id: impl ImplicitChatId,
    message_id: Id
) -> StopPoll<'_>
[src]

Stops a poll.

pub fn unban_chat_member(
    &self,
    chat_id: impl ImplicitChatId,
    user_id: Id
) -> UnbanChatMember<'_>
[src]

Lifts all restrictions from a group’s member.

pub fn unpin_all_chat_messages(
    &self,
    chat_id: impl ImplicitChatId
) -> UnpinAllChatMessages<'_>
[src]

Unpins all messages in a chat.

pub fn unpin_chat_message(
    &self,
    chat_id: impl ImplicitChatId
) -> UnpinChatMessage<'_>
[src]

Unpins a chat message.

pub fn upload_sticker_file(
    &self,
    user_id: Id,
    png_sticker: impl Into<Vec<u8>>
) -> UploadStickerFile<'_>
[src]

Uploads a sticker file.

Trait Implementations

impl ChatActionLoopBotExt for Bot[src]

impl Clone for Bot[src]

impl Debug for Bot[src]

Auto Trait Implementations

impl !RefUnwindSafe for Bot

impl Send for Bot

impl Sync for Bot

impl Unpin for Bot

impl !UnwindSafe for Bot

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> WithSubscriber for T[src]