Struct teloxide::adaptors::Throttle[][src]

pub struct Throttle<B> { /* fields omitted */ }

Automatic request limits respecting mechanism.

Telegram has strict limits, which, if exceeded will sooner or later cause RequestError::RetryAfter(_) errors. These errors can cause users of your bot to never receive responds from the bot or receive them in wrong order.

This bot wrapper automatically checks for limits, suspending requests until they could be sent without exceeding limits (request order in chats is not changed).

It’s recommended to use this wrapper before other wrappers (i.e.: SomeWrapper<Throttle<Bot>>) because if done otherwise inner wrappers may cause Throttle to miscalculate limits usage.

Examples

use teloxide_core::{adaptors::throttle::Limits, requests::RequesterExt, Bot};

let bot = Bot::new("TOKEN").throttle(Limits::default());

/* send many requests here */

Note about send-by-@channelusername

Telegram have limits on sending messages to the same chat. To check them we store chat_ids of several last requests. However there is no good way to tell if given ChatId::Id(x) corresponds to the same chat as ChatId::ChannelUsername(u).

Our current approach is to just give up and check chat_id_a == chat_id_b. This may give incorrect results.

As such, we encourage not to use ChatId::ChannelUsername(u) with this bot wrapper.

Implementations

impl<B> Throttle<B>[src]

pub fn new(bot: B, limits: Limits) -> (Throttle<B>, impl Future<Output = ()>)[src]

Creates new Throttle alongside with worker future.

Note: Throttle will only send requests if returned worker is polled/spawned/awaited.

pub fn new_spawn(bot: B, limits: Limits) -> Throttle<B> where
    B: 'static, 
[src]

Creates new Throttle spawning the worker with tokio::spawn

Note: it’s recommended to use RequesterExt::throttle instead.

pub fn inner(&self) -> &B[src]

Allows to access inner bot

pub fn into_inner(self) -> B[src]

Unwraps inner bot

Trait Implementations

impl<'w, B> Download<'w> for Throttle<B> where
    B: Download<'w>, 
[src]

type Err = <B as Download<'w>>::Err

An error returned from download_file.

type Fut = <B as Download<'w>>::Fut

A future returned from download_file.

type StreamErr = <B as Download<'w>>::StreamErr

An error returned from download_file_stream. Read more

type Stream = <B as Download<'w>>::Stream

A stream returned from download_file_stream. Read more

impl<B> Requester for Throttle<B> where
    B: Requester,
    <B as Requester>::SendMessage: Send,
    <B as Requester>::ForwardMessage: Send,
    <B as Requester>::CopyMessage: Send,
    <B as Requester>::SendPhoto: Send,
    <B as Requester>::SendAudio: Send,
    <B as Requester>::SendDocument: Send,
    <B as Requester>::SendVideo: Send,
    <B as Requester>::SendAnimation: Send,
    <B as Requester>::SendVoice: Send,
    <B as Requester>::SendVideoNote: Send,
    <B as Requester>::SendMediaGroup: Send,
    <B as Requester>::SendLocation: Send,
    <B as Requester>::SendVenue: Send,
    <B as Requester>::SendContact: Send,
    <B as Requester>::SendPoll: Send,
    <B as Requester>::SendDice: Send,
    <B as Requester>::SendSticker: Send,
    <B as Requester>::SendInvoice: Send
[src]

type Err = <B as Requester>::Err

Error type returned by all requests.

type SendMessage = ThrottlingRequest<<B as Requester>::SendMessage>

type ForwardMessage = ThrottlingRequest<<B as Requester>::ForwardMessage>

type CopyMessage = ThrottlingRequest<<B as Requester>::CopyMessage>

type SendPhoto = ThrottlingRequest<<B as Requester>::SendPhoto>

type SendAudio = ThrottlingRequest<<B as Requester>::SendAudio>

type SendDocument = ThrottlingRequest<<B as Requester>::SendDocument>

type SendVideo = ThrottlingRequest<<B as Requester>::SendVideo>

type SendAnimation = ThrottlingRequest<<B as Requester>::SendAnimation>

type SendVoice = ThrottlingRequest<<B as Requester>::SendVoice>

type SendVideoNote = ThrottlingRequest<<B as Requester>::SendVideoNote>

type SendMediaGroup = ThrottlingRequest<<B as Requester>::SendMediaGroup>

type SendLocation = ThrottlingRequest<<B as Requester>::SendLocation>

type SendVenue = ThrottlingRequest<<B as Requester>::SendVenue>

type SendContact = ThrottlingRequest<<B as Requester>::SendContact>

type SendPoll = ThrottlingRequest<<B as Requester>::SendPoll>

type SendDice = ThrottlingRequest<<B as Requester>::SendDice>

type SendSticker = ThrottlingRequest<<B as Requester>::SendSticker>

type SendInvoice = ThrottlingRequest<<B as Requester>::SendInvoice>

type GetMe = <B as Requester>::GetMe

type LogOut = <B as Requester>::LogOut

type Close = <B as Requester>::Close

type GetUpdates = <B as Requester>::GetUpdates

type SetWebhook = <B as Requester>::SetWebhook

type DeleteWebhook = <B as Requester>::DeleteWebhook

type GetWebhookInfo = <B as Requester>::GetWebhookInfo

type EditMessageLiveLocation = <B as Requester>::EditMessageLiveLocation

type EditMessageLiveLocationInline = <B as Requester>::EditMessageLiveLocationInline

type StopMessageLiveLocation = <B as Requester>::StopMessageLiveLocation

type StopMessageLiveLocationInline = <B as Requester>::StopMessageLiveLocationInline

type SendChatAction = <B as Requester>::SendChatAction

type GetUserProfilePhotos = <B as Requester>::GetUserProfilePhotos

type GetFile = <B as Requester>::GetFile

type KickChatMember = <B as Requester>::KickChatMember

type UnbanChatMember = <B as Requester>::UnbanChatMember

type RestrictChatMember = <B as Requester>::RestrictChatMember

type PromoteChatMember = <B as Requester>::PromoteChatMember

type SetChatAdministratorCustomTitle = <B as Requester>::SetChatAdministratorCustomTitle

type SetChatPermissions = <B as Requester>::SetChatPermissions

type SetChatPhoto = <B as Requester>::SetChatPhoto

type DeleteChatPhoto = <B as Requester>::DeleteChatPhoto

type SetChatTitle = <B as Requester>::SetChatTitle

type SetChatDescription = <B as Requester>::SetChatDescription

type PinChatMessage = <B as Requester>::PinChatMessage

type UnpinChatMessage = <B as Requester>::UnpinChatMessage

type UnpinAllChatMessages = <B as Requester>::UnpinAllChatMessages

type LeaveChat = <B as Requester>::LeaveChat

type GetChat = <B as Requester>::GetChat

type GetChatAdministrators = <B as Requester>::GetChatAdministrators

type GetChatMembersCount = <B as Requester>::GetChatMembersCount

type GetChatMember = <B as Requester>::GetChatMember

type SetChatStickerSet = <B as Requester>::SetChatStickerSet

type DeleteChatStickerSet = <B as Requester>::DeleteChatStickerSet

type AnswerCallbackQuery = <B as Requester>::AnswerCallbackQuery

type SetMyCommands = <B as Requester>::SetMyCommands

type GetMyCommands = <B as Requester>::GetMyCommands

type AnswerInlineQuery = <B as Requester>::AnswerInlineQuery

type EditMessageText = <B as Requester>::EditMessageText

type EditMessageTextInline = <B as Requester>::EditMessageTextInline

type EditMessageCaption = <B as Requester>::EditMessageCaption

type EditMessageCaptionInline = <B as Requester>::EditMessageCaptionInline

type EditMessageMedia = <B as Requester>::EditMessageMedia

type EditMessageMediaInline = <B as Requester>::EditMessageMediaInline

type EditMessageReplyMarkup = <B as Requester>::EditMessageReplyMarkup

type EditMessageReplyMarkupInline = <B as Requester>::EditMessageReplyMarkupInline

type StopPoll = <B as Requester>::StopPoll

type DeleteMessage = <B as Requester>::DeleteMessage

type GetStickerSet = <B as Requester>::GetStickerSet

type UploadStickerFile = <B as Requester>::UploadStickerFile

type CreateNewStickerSet = <B as Requester>::CreateNewStickerSet

type AddStickerToSet = <B as Requester>::AddStickerToSet

type SetStickerPositionInSet = <B as Requester>::SetStickerPositionInSet

type DeleteStickerFromSet = <B as Requester>::DeleteStickerFromSet

type SetStickerSetThumb = <B as Requester>::SetStickerSetThumb

type AnswerShippingQuery = <B as Requester>::AnswerShippingQuery

type AnswerPreCheckoutQuery = <B as Requester>::AnswerPreCheckoutQuery

type SetPassportDataErrors = <B as Requester>::SetPassportDataErrors

type SendGame = <B as Requester>::SendGame

type SetGameScore = <B as Requester>::SetGameScore

type SetGameScoreInline = <B as Requester>::SetGameScoreInline

type GetGameHighScores = <B as Requester>::GetGameHighScores

type GetUpdatesFaultTolerant = <B as Requester>::GetUpdatesFaultTolerant

Auto Trait Implementations

impl<B> !RefUnwindSafe for Throttle<B>

impl<B> Send for Throttle<B> where
    B: Send

impl<B> Sync for Throttle<B> where
    B: Sync

impl<B> Unpin for Throttle<B> where
    B: Unpin

impl<B> !UnwindSafe for Throttle<B>

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> 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.