Bulk messaging issues with Telegram Bot: Error 400 encountered

I’m working on a Telegram Bot for our company. It’s supposed to let admins send messages to all employees (we have over 10,000). We store everyone’s chat_id in a database. When an admin uses a special command, it should message everyone.

Here’s the problem: It works for the first bunch of users, but then we get Error 400 (Bad request) for the rest. We’re logging these errors.

I’m using C# WebRequest and sending messages in batches of 100 users. After each batch, it moves to the next 100.

Any ideas what’s going wrong? Is there a better way to do bulk messaging with a Telegram Bot?

foreach (var batch in userBatches)
{
    foreach (var user in batch)
    {
        try
        {
            SendMessage(user.ChatId, messageText);
        }
        catch (Exception ex)
        {
            LogError($"Error sending to {user.ChatId}: {ex.Message}");
        }
    }
    await Task.Delay(1000); // Pause between batches
}

I’m not sure if this is the best approach. Any suggestions would be super helpful!

yo, i’ve dealt with this before. telegram’s got some strict limits, man. try spreading out ur messages more. like, maybe send 30-50 per minute instead of 100 at once. and def add more time between batches, like 5-10 secs. also, double check ur chat IDs are legit. sometimes ppl block the bot or delete their account. good luck with ur project bro!

I’ve encountered this issue before when working with Telegram bots for large-scale messaging.

The Error 400 you’re seeing is likely due to Telegram’s rate limiting mechanisms. To mitigate this, I’d suggest implementing a more robust error handling and retry system. Consider using an exponential backoff strategy for retries—start with a short delay and then increase it progressively if errors persist. Ensuring adherence to Telegram’s guidelines on bulk messaging can also help avoid bot restrictions.

Another approach that has worked well for me is to implement a message queue system like RabbitMQ or Azure Service Bus. This allows for better control of the message sending rate and offers built-in retry mechanisms. Finally, double-check that you are using the latest Telegram Bot API to take advantage of any performance improvements.

I’ve seen similar problems when sending mass messages via Telegram bots. It seems that the error may be caused by hitting Telegram’s rate limits on API requests. In my own experience, slowing down requests by using an exponential backoff strategy helped overcome these limits. Instead of sending messages in fixed batches, spacing them out based on the error feedback can make a big difference. Also, checking that each chat ID is active helps avoid unnecessary errors from invalid targets. It might be helpful to explore using a message queuing system to better manage the sending process, as well as consulting the latest Telegram documentation.