Struct teloxide::Bot[][src]

pub struct Bot { /* fields omitted */ }

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

impl Bot[src]

Constructors

pub fn new<S>(token: S) -> Bot where
    S: Into<String>, 
[src]

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

Panics

If it cannot create reqwest::Client.

pub fn with_client<S>(token: S, client: Client) -> Bot where
    S: Into<String>, 
[src]

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.

pub fn from_env() -> Bot[src]

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.

pub fn from_env_with_client(client: Client) -> Bot[src]

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.

pub fn set_api_url(self, url: Url) -> Bot[src]

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/");

impl Bot[src]

Getters

pub fn token(&self) -> &str[src]

Returns currently used token.

pub fn client(&self) -> &Client[src]

Returns currently used http-client.

pub fn api_url(&self) -> Url[src]

Returns currently used token API url.

Trait Implementations

impl Clone for Bot[src]

impl Debug for Bot[src]

impl<'w> Download<'w> for Bot[src]

type Err = DownloadError

An error returned from download_file.

type Fut = Pin<Box<dyn Future<Output = Result<(), <Bot as Download<'w>>::Err>> + 'w + Send, Global>>

A future returned from download_file.

type StreamErr = Error

An error returned from download_file_stream. Read more

type Stream = Pin<Box<dyn Stream<Item = Result<Bytes, <Bot as Download<'w>>::StreamErr>> + 'static + Send, Global>>

A stream returned from download_file_stream. Read more

impl Requester for Bot[src]

type Err = RequestError

Error type returned by all requests.

type GetUpdates = JsonRequest<GetUpdates>

type SetWebhook = JsonRequest<SetWebhook>

type DeleteWebhook = JsonRequest<DeleteWebhook>

type GetWebhookInfo = JsonRequest<GetWebhookInfo>

type GetMe = JsonRequest<GetMe>

type SendMessage = JsonRequest<SendMessage>

type ForwardMessage = JsonRequest<ForwardMessage>

type SendPhoto = MultipartRequest<SendPhoto>

type SendAudio = MultipartRequest<SendAudio>

type SendDocument = MultipartRequest<SendDocument>

type SendVideo = MultipartRequest<SendVideo>

type SendAnimation = MultipartRequest<SendAnimation>

type SendVoice = MultipartRequest<SendVoice>

type SendVideoNote = MultipartRequest<SendVideoNote>

type SendMediaGroup = MultipartRequest<SendMediaGroup>

type SendLocation = JsonRequest<SendLocation>

type EditMessageLiveLocation = JsonRequest<EditMessageLiveLocation>

type EditMessageLiveLocationInline = JsonRequest<EditMessageLiveLocationInline>

type StopMessageLiveLocation = JsonRequest<StopMessageLiveLocation>

type StopMessageLiveLocationInline = JsonRequest<StopMessageLiveLocationInline>

type SendVenue = JsonRequest<SendVenue>

type SendContact = JsonRequest<SendContact>

type SendPoll = JsonRequest<SendPoll>

type SendDice = JsonRequest<SendDice>

type SendChatAction = JsonRequest<SendChatAction>

type GetUserProfilePhotos = JsonRequest<GetUserProfilePhotos>

type GetFile = JsonRequest<GetFile>

type KickChatMember = JsonRequest<KickChatMember>

type UnbanChatMember = JsonRequest<UnbanChatMember>

type RestrictChatMember = JsonRequest<RestrictChatMember>

type PromoteChatMember = JsonRequest<PromoteChatMember>

type SetChatAdministratorCustomTitle = JsonRequest<SetChatAdministratorCustomTitle>

type SetChatPermissions = JsonRequest<SetChatPermissions>

type SetChatPhoto = MultipartRequest<SetChatPhoto>

type DeleteChatPhoto = JsonRequest<DeleteChatPhoto>

type SetChatTitle = JsonRequest<SetChatTitle>

type SetChatDescription = JsonRequest<SetChatDescription>

type PinChatMessage = JsonRequest<PinChatMessage>

type UnpinChatMessage = JsonRequest<UnpinChatMessage>

type LeaveChat = JsonRequest<LeaveChat>

type GetChat = JsonRequest<GetChat>

type GetChatAdministrators = JsonRequest<GetChatAdministrators>

type GetChatMembersCount = JsonRequest<GetChatMembersCount>

type GetChatMember = JsonRequest<GetChatMember>

type SetChatStickerSet = JsonRequest<SetChatStickerSet>

type DeleteChatStickerSet = JsonRequest<DeleteChatStickerSet>

type AnswerCallbackQuery = JsonRequest<AnswerCallbackQuery>

type SetMyCommands = JsonRequest<SetMyCommands>

type GetMyCommands = JsonRequest<GetMyCommands>

type AnswerInlineQuery = JsonRequest<AnswerInlineQuery>

type EditMessageText = JsonRequest<EditMessageText>

type EditMessageTextInline = JsonRequest<EditMessageTextInline>

type EditMessageCaption = JsonRequest<EditMessageCaption>

type EditMessageCaptionInline = JsonRequest<EditMessageCaptionInline>

type EditMessageMedia = MultipartRequest<EditMessageMedia>

type EditMessageMediaInline = MultipartRequest<EditMessageMediaInline>

type EditMessageReplyMarkup = JsonRequest<EditMessageReplyMarkup>

type EditMessageReplyMarkupInline = JsonRequest<EditMessageReplyMarkupInline>

type StopPoll = JsonRequest<StopPoll>

type DeleteMessage = JsonRequest<DeleteMessage>

type SendSticker = MultipartRequest<SendSticker>

type GetStickerSet = JsonRequest<GetStickerSet>

type UploadStickerFile = MultipartRequest<UploadStickerFile>

type CreateNewStickerSet = MultipartRequest<CreateNewStickerSet>

type AddStickerToSet = MultipartRequest<AddStickerToSet>

type SetStickerPositionInSet = JsonRequest<SetStickerPositionInSet>

type DeleteStickerFromSet = JsonRequest<DeleteStickerFromSet>

type SetStickerSetThumb = MultipartRequest<SetStickerSetThumb>

type SendInvoice = JsonRequest<SendInvoice>

type AnswerShippingQuery = JsonRequest<AnswerShippingQuery>

type AnswerPreCheckoutQuery = JsonRequest<AnswerPreCheckoutQuery>

type SetPassportDataErrors = JsonRequest<SetPassportDataErrors>

type SendGame = JsonRequest<SendGame>

type SetGameScore = JsonRequest<SetGameScore>

type SetGameScoreInline = JsonRequest<SetGameScoreInline>

type GetGameHighScores = JsonRequest<GetGameHighScores>

type LogOut = JsonRequest<LogOut>

type Close = JsonRequest<Close>

type CopyMessage = JsonRequest<CopyMessage>

type UnpinAllChatMessages = JsonRequest<UnpinAllChatMessages>

type GetUpdatesFaultTolerant = JsonRequest<GetUpdatesFaultTolerant>

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> Conv for T

impl<T> Conv for T

impl<Choices> CoproductSubsetter<CNil, HNil> for Choices

type Remainder = Choices

impl<T> FmtForward for T

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

impl<T> Instrument for T[src]

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

impl<T, U, I> LiftInto<U, I> for T where
    U: LiftFrom<T, I>, 

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> RequesterExt for T where
    T: Requester
[src]

impl<Source> Sculptor<HNil, HNil> for Source

type Remainder = Source

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T> TryConv for T

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.