RocketChat / RocketChat/Rocket.Chat

'send-many-messages' permission not respected when sending via Rocket.Chat.js.SDK

Open
#34,932 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

planned
Dominant language
TypeScript
Stars
46.1k
Forks
13.9k
Avg merge
3d 3h
Merged PRs (30d)
130

Description

Description:

Sending frequent messages (more than 5/sec) using Rocket.Chat.js.SDK raises an error despite having assigned permission 'send-many-messages' to a user.

Steps to reproduce:
  1. Use the bot example from https://developer.rocket.chat/v1/docs/develop-a-rocketchat-sdk-bot
  2. Replace the processMessages function with:
const processMessages = async (err, message, messageOptions) => {
 if (!err) {
   if (message.u._id === myUserId) return;
   for(let i=0;i<10;i++) await driver.sendToRoomId('Hi there! - '+i, message.rid);
 }
};
  1. Run node server.js and send a random message to the user.
Expected behavior:

The response shoule be 10 greetings like Hi there! - 0 with numbers from 0 to 9.

Actual behavior:

5 messages are sent and the error is returned:

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

image

Temporary workaround

An introduction of a send delay like this solves the issue:
for(let i=0;i<10;i++) setTimeout(async ()=>{await driver.sendToRoomId('Hi there! - '+i, message.rid)},i*200);

Server Setup Information:
  • Version of Rocket.Chat Server: 7.1.0
  • License Type: Starter
  • Deployment Method: tar
  • NodeJS Version: 20.17
  • MongoDB Version: 6.0.19

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the Rocket.Chat.js.SDK bot example, replacing processMessages and running node server.js. Start by tracing driver.sendToRoomId and the server-side handling of the send-many-messages permission and request limit. Done means ten messages can be sent without the too-many-requests error when the permission is assigned, while normal limiting remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
authorization, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.