Struct teloxide::Bot[][src]

pub struct Bot { /* fields omitted */ }
Expand description

A requests sender.

This is the main type of the library, it allows to send requests to the Telegram Bot API and download files.

TBA methods

All TBA methods are located in the Requester impl for Bot. This allows for opt-in behaviours using requester adaptors.

use teloxide_core::prelude::*;

let bot = Bot::new("TOKEN");
dbg!(bot.get_me().send().await?);

File download

In the similar way as with TBA methods, file downloading methods are located in a trait — Download<'_>. See its documentation for more.

Clone cost

Bot::clone is relatively cheap, so if you need to share Bot, it’s recommended to clone it, instead of wrapping it in Arc<_>.

Implementations

Constructors

Creates a new Bot with the specified token and the default http-client.

Panics

If it cannot create [reqwest::Client].

Creates a new Bot with the specified token and your reqwest::Client.

Caution

Your custom client might not be configured correctly to be able to work in long time durations, see issue 223.

Creates a new Bot with the TELOXIDE_TOKEN & TELOXIDE_PROXY environmental variables (a bot’s token & a proxy) and the default reqwest::Client.

This function passes the value of TELOXIDE_PROXY into reqwest::Proxy::all, if it exists, otherwise returns the default client.

Panics
  • If cannot get the TELOXIDE_TOKEN environmental variable.
  • If it cannot create reqwest::Client.

Creates a new Bot with the TELOXIDE_TOKEN environmental variable (a bot’s token) and your reqwest::Client.

Panics

If cannot get the TELOXIDE_TOKEN environmental variable.

Caution

Your custom client might not be configured correctly to be able to work in long time durations, see issue 223.

Sets a custom API URL.

For example, you can run your own Telegram bot API server and set its URL using this method.

Examples
use teloxide_core::{
    requests::{Request, Requester},
    Bot,
};

let url = reqwest::Url::parse("https://localhost/tbas").unwrap();
let bot = Bot::new("TOKEN").set_api_url(url);
// From now all methods will use "https://localhost/tbas" as an API URL.
bot.get_me().send().await
Multi-instance behaviour

This method only sets the url for one bot instace, older clones are unaffected.

use teloxide_core::Bot;

let bot = Bot::new("TOKEN");
let bot2 = bot.clone();
let bot = bot.set_api_url(reqwest::Url::parse("https://example.com/").unwrap());

assert_eq!(bot.api_url().as_str(), "https://example.com/");
assert_eq!(bot.clone().api_url().as_str(), "https://example.com/");
assert_ne!(bot2.api_url().as_str(), "https://example.com/");

Getters

Returns currently used token.

Returns currently used http-client.

Returns currently used token API url.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

An error returned from download_file.

A future returned from download_file.

Download a file from Telegram into destination. Read more

An error returned from download_file_stream. Read more

A stream returned from download_file_stream. Read more

Download a file from Telegram as [Stream]. Read more

Error type returned by all requests.

For Telegram documentation see GetUpdates.

For Telegram documentation see SetWebhook.

For Telegram documentation see DeleteWebhook.

For Telegram documentation see GetWebhookInfo.

For Telegram documentation see GetMe.

For Telegram documentation see SendMessage.

For Telegram documentation see ForwardMessage.

For Telegram documentation see SendPhoto.

For Telegram documentation see SendAudio.

For Telegram documentation see SendDocument.

For Telegram documentation see SendVideo.

For Telegram documentation see SendAnimation.

For Telegram documentation see SendVoice.

For Telegram documentation see SendVideoNote.

For Telegram documentation see SendMediaGroup.

For Telegram documentation see SendLocation.

For Telegram documentation see EditMessageLiveLocation.

For Telegram documentation see EditMessageLiveLocationInline.

For Telegram documentation see StopMessageLiveLocation.

For Telegram documentation see StopMessageLiveLocationInline.

For Telegram documentation see SendVenue.

For Telegram documentation see SendContact.

For Telegram documentation see SendPoll.

For Telegram documentation see SendDice.

For Telegram documentation see SendChatAction.

For Telegram documentation see GetUserProfilePhotos.

For Telegram documentation see GetFile.

For Telegram documentation see KickChatMember.

For Telegram documentation see BanChatMember.

For Telegram documentation see UnbanChatMember.

For Telegram documentation see RestrictChatMember.

For Telegram documentation see PromoteChatMember.

For Telegram documentation see SetChatAdministratorCustomTitle.

For Telegram documentation see SetChatPermissions.

For Telegram documentation see ExportChatInviteLink.

For Telegram documentation see CreateChatInviteLink.

For Telegram documentation see EditChatInviteLink.

For Telegram documentation see RevokeChatInviteLink.

For Telegram documentation see SetChatPhoto.

For Telegram documentation see DeleteChatPhoto.

For Telegram documentation see SetChatTitle.

For Telegram documentation see SetChatDescription.

For Telegram documentation see PinChatMessage.

For Telegram documentation see UnpinChatMessage.

For Telegram documentation see LeaveChat.

For Telegram documentation see GetChat.

For Telegram documentation see GetChatAdministrators.

For Telegram documentation see GetChatMembersCount.

For Telegram documentation see GetChatMemberCount.

For Telegram documentation see GetChatMember.

For Telegram documentation see SetChatStickerSet.

For Telegram documentation see DeleteChatStickerSet.

For Telegram documentation see AnswerCallbackQuery.

For Telegram documentation see SetMyCommands.

For Telegram documentation see GetMyCommands.

For Telegram documentation see DeleteMyCommands.

For Telegram documentation see AnswerInlineQuery.

For Telegram documentation see EditMessageText.

For Telegram documentation see EditMessageTextInline.

For Telegram documentation see EditMessageCaption.

For Telegram documentation see EditMessageCaptionInline.

For Telegram documentation see EditMessageMedia.

For Telegram documentation see EditMessageMediaInline.

For Telegram documentation see EditMessageReplyMarkup.

For Telegram documentation see EditMessageReplyMarkupInline.

For Telegram documentation see StopPoll.

For Telegram documentation see DeleteMessage.

For Telegram documentation see SendSticker.

For Telegram documentation see GetStickerSet.

For Telegram documentation see UploadStickerFile.

For Telegram documentation see CreateNewStickerSet.

For Telegram documentation see AddStickerToSet.

For Telegram documentation see SetStickerPositionInSet.

For Telegram documentation see DeleteStickerFromSet.

For Telegram documentation see SetStickerSetThumb.

For Telegram documentation see SendInvoice.

For Telegram documentation see AnswerShippingQuery.

For Telegram documentation see AnswerPreCheckoutQuery.

For Telegram documentation see SetPassportDataErrors.

For Telegram documentation see SendGame.

For Telegram documentation see SetGameScore.

For Telegram documentation see SetGameScoreInline.

For Telegram documentation see GetGameHighScores.

For Telegram documentation see LogOut.

For Telegram documentation see Close.

For Telegram documentation see CopyMessage.

For Telegram documentation see UnpinAllChatMessages.

For Telegram documentation see GetUpdatesFaultTolerant.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Extract a subset of the possible types in a coproduct (or get the remaining possibilities) Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Performs the indexed conversion.

This is supported on crate feature cache_me only.

Add get_me caching ability, see CacheMe for more. Read more

This is supported on crate feature auto_send only.

Send requests automatically, see AutoSend for more.

This is supported on crate feature erased only.

Erase requester type.

This is supported on crate feature trace_adaptor only.

Trace requests, see Trace for more.

This is supported on crate feature throttle only.

Add throttling ability, see Throttle for more. Read more

Specifies default ParseMode, which will be used during all calls to: Read more

Consumes the current HList and returns an HList with the requested shape. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more