Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vonfatt opened this issue Jan 10, 2025 · 9 comments
Labels
Tasked Added to the internal issue tracking

Comments

@vonfatt
Copy link

vonfatt commented Jan 10, 2025

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
@reetp
Copy link

reetp commented Jan 10, 2025

Version of Rocket.Chat Server: 7.1.0

As per the docs always test on latest code please.

send-many-messages

Doesn't specify how many...... :-)

Sending frequent messages (more than 5/sec)

I'd imagine there's reason for that.....

Check if rate limiting is involved too.

@reetp
Copy link

reetp commented Jan 10, 2025

@reetp
Copy link

reetp commented Jan 10, 2025

@vonfatt
Copy link
Author

vonfatt commented Jan 10, 2025

Version of Rocket.Chat Server: 7.1.0

As per the docs always test on latest code please.

Couldn't have done it, provided that 7.1.0 is very close to the most recent one, took up that risk... Sorry.

send-many-messages

Doesn't specify how many...... :-)

I thought 'send-many-messages' together with 'permission' is obvious. It's about this specification: https://docs.rocket.chat/docs/permissions and 'send-many-messages' Codebase Name permission.

Sending frequent messages (more than 5/sec)

I'd imagine there's reason for that.....

Yes, looks like the reason is that apparent lack of permission triggers the error (despite it being set)

Check if rate limiting is involved too.

Same behaviour for both rate limits settings ('on' or'off').

@vonfatt
Copy link
Author

vonfatt commented Jan 10, 2025

And are you using this?

https://github.com/RocketChat/Rocket.Chat.js.SDK

Looks so, however the example I am referring to is taken from the docs web page, as stated in the first step to reproduce (https://developer.rocket.chat/v1/docs/develop-a-rocketchat-sdk-bot)

Nonetheless, the change from sendToRoomId() to sendToRoom() like here:
for(let i=0;i<10;i++) await driver.sendToRoom('Hi there! - '+i, await driver.getRoomName(message.rid));
makes no difference.

@reetp
Copy link

reetp commented Jan 11, 2025

Version of Rocket.Chat Server: 7.1.0
As per the docs always test on latest code please.

Couldn't have done it, provided that 7.1.0 is very close to the most recent one, took up that risk... Sorry.
I'm sorry but that is what is required qhewn posting issues.

If you check the bug template links

Please see our guide for opening issues: https://developer.rocket.chat/rocket.chat/contribute-to-rocket.chat/ways-to-contribute/report-bugs

And:

Before reporting a bug
Before you report a new issue, please:
....
Ensure you're running the latest version of Rocket.Chat. An update might resolve your issue.

So, setup a test deployment (I always run at least one) and test.

send-many-messages
Doesn't specify how many...... :-)

I thought 'send-many-messages' together with 'permission' is obvious. It's about this specification: https://docs.rocket.chat/docs/permissions and 'send-many-messages' Codebase Name permission.

My bad. It wasn't visible from my mobile phone.

Send Many Messages
send-many-messages
Permission to bypasses rate limit of 5 messages per second.

OK.

Yes, looks like the reason is that apparent lack of permission triggers the error (despite it being set)

OK.

Check if rate limiting is involved too.

Same behaviour for both rate limits settings ('on' or'off').

OK good test thanks.

Looks so, however the example I am referring to is taken from the docs web page, as stated in the first step to reproduce (https://developer.rocket.chat/v1/docs/develop-a-rocketchat-sdk-bot)

Nonetheless, the change from sendToRoomId() to sendToRoom() like here:
for(let i=0;i<10;i++) await driver.sendToRoom('Hi there! - '+i, await driver.getRoomName(message.rid));
makes no difference.

Ok.

Been no work on that repo for a long time. Hmmm.

https://github.com/RocketChat/Rocket.Chat.js.SDK

Not sure if the readme there is aligned with the docs....

This might be worth a look as an aside.

RocketChat/Rocket.Chat.js.SDK#169

I will need to speak to the team about this.

@reetp reetp added the Tasked Added to the internal issue tracking label Jan 11, 2025
@vonfatt
Copy link
Author

vonfatt commented Jan 13, 2025

Been no work on that repo for a long time. Hmmm.

https://github.com/RocketChat/Rocket.Chat.js.SDK

Not sure if the readme there is aligned with the docs....

Not only there - please remember about website dev docs https://developer.rocket.chat/v1/docs/develop-a-rocketchat-sdk-bot

This might be worth a look as an aside.

RocketChat/Rocket.Chat.js.SDK#169

Yes, we also had to deal with this (quick fix implemented already)

I will need to speak to the team about this.

Thanks

@Rachit-31
Copy link

I am intrested in solving this issue. Please assign this issue to me

@reetp
Copy link

reetp commented Jan 15, 2025

I am intrested in solving this issue. Please assign this issue to me

https://gist.github.com/reetp/b0ba4e3d0ea2ff48ca9da00a5a647d42#github

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tasked Added to the internal issue tracking
Projects
None yet
Development

No branches or pull requests

3 participants