1

I'm trying to send broadcast notification in direct message via bot (bot repository):

const { driver } = require('@rocket.chat/sdk');
    
module.exports = (robot) => {
    robot.respond(/notify/i, (msg) => {
         let userNames = ['1','2','3'];
         userNames.forEach(userName => driver.sendDirectToUser(message, userName));
    }
}

In the administration panel of Rocket.Chat server I turned off all rate limiters, but every time I get an exception :

ERROR [createDirectMessage] Error: {
isClientSafe: true,
error: 'too-many-requests',
reason: 'Error, too many requests. Please slow down. You must wait 54 seconds before trying again.',
details: { timeToReset: 53009 },
message: 'Error, too many requests. Please slow down. You must wait 54 seconds before trying again. [too-many-requests]',
errorType: 'Meteor.Error'
}

I've also tried to change limit values, but looks like it did't help. I have about 2000 users and at some point it throws an exception.

UPD

As for now I had to use code like this:

function sendMessages(userNames, message, timeOut = 120 /*ms*/) {
        let step = timeOut;
        userNames.forEach(userName => sendWait(() => driver.sendDirectToUser(message, userName).catch(error => {}), timeOut+=step))
    }

    function sendWait(action, milliseconds) {
        if (typeof(action) != 'function')
            return;
        setTimeout(action, milliseconds);
    }

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.