GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Avoiding flood limits Avoiding flood limits
feltroid Prime edited this page
Considering Telegram's Bot documentation, currently the maximum amount of messages being sent by bots is limited to ~30 messages/second for all ordinary messages and ~20 messages/minute for group messages. According to @BotSupport the limit for group also applies to channels (this is not confirmed by Telegram in their documentation however). We emphasize that Telegram does not document the precise limits, neither for sending messages nor for other kinds of API requests. Moreover, the limits may differ between bots and also over time. When your bot hits spam limits, it starts to get That means, if you're making a production-ready bot that is expected to have a large number of users, it's a good idea to use throughput limiting mechanism for messages being sent/requests being made to the Bot API. This way you can ensure that all messages would be delivered to end-users as soon as possible in ordered way. Tip With Bot API 7.1 (PTB v27.1), Telegram introduced the parameter Caution PTBs rate limiting mechanism doesn't take Since v20 (v20.0a3, to be precise), PTB comes with a built-in mechanism to throttle the number of API requests that your bot makes per time interval.
This mechanism is exposed through the The from telegram import Update from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler application = ApplicationBuilder().token("TOKEN").rate_limiter(MyLimiter()).build() async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): # This is automatically passed through `MyLimiter.process_request`! await update.message.reply_text(text="Hello World!") application.add_handler(CommandHandler('start', start)) You may also pass additional information to import asyncio from telegram import Update from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler application = ApplicationBuilder().token("TOKEN").rate_limiter(MyLimiter()).build() user_ids = [1, 2, 3] async def broadcast(update: Update, context: ContextTypes.DEFAULT_TYPE): await update.message.reply_text(text="Starting the broadcast...") context.application.create_task( asyncio.gather( *( context.bot.send_message( chat_id=user_id, text="Hello World!", rate_limit_args={'priority': -1} ) for user_id in user_ids ) ) ) application.add_handler(CommandHandler('broadcast', broadcast)) What kind of input is allowed for the PTB comes with a built-in implementation of
Wiki of
Clone this wiki locally |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |