Hubot火箭聊天广播通知

问题描述

我正在尝试通过漫游器(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));
    }
}

在Rocket.Chat服务器的管理面板中,我关闭了所有速率限制器,但是每次遇到异常时:

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'
}

我也曾尝试更改极限值,但看起来没有帮助。 我有大约2000个用户,有时它会引发异常。

UPD

就目前而言,我不得不使用如下代码

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);
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)