hubot-rocketchat: Can't use Hubot initiative send message in the private group, getRoomIdByNameOrId not allowed.
Hi there,
I use hubot send notification message to my users. the function is working fine in 0.57, but when i update rocketchat server from 0.57 to 0.68, the hubot can’t initiates send message. Server return “getRoomIdByNameOrId not allowed”.
I use HTTP Post to send message to hubot, then hubot pass the message to rocketchat private group.
Now i change the hubot version 2.19.0 to hubot-rocketchat-boilerplate and use same script, but server return same error message.
Can you help me to find what wrong in my setting? Thank you.
There are my config and script:
user permission use bot permission.
create-d
create-p
join-without-join-code
leave-c
leave-d
leave-p
manage-own-integrations
preview-c-room
send-many-messages
view-c-room
view-d-room
view-history
view-join-code
view-joined-room
view-l-room
view-livechat-rooms
view-outside-room
view-p-room
hubot user config
hubot package.js
{
"name": "hubot-rocketchat-boilerplate",
"version": "0.0.0-develop",
"description": "An example Hubot demonstrating usage of the Rocket.Chat adaptor.",
"main": "bin/hubot",
"repository": "git@github.com:RocketChat/hubot-rocketchat-boilerplate.git",
"author": "Tim Kinnane <tim.kinnane@rocket.chat>",
"license": "MIT",
"private": false,
"keywords": [
"hubot",
"rocketchat",
"chatbot",
"chat"
],
"engines": {
"node": ">=8.x",
"npm": ">=5.x"
},
"scripts": {
"debug": "node --inspect --inspect-brk -r dotenv/config node_modules/hubot/bin/hubot.js -a rocketchat",
"shell": "node -r dotenv/config node_modules/hubot/bin/hubot.js -a shell",
"local": "node -r dotenv/config node_modules/hubot/bin/hubot.js -a rocketchat"
},
"dependencies": {
"coffeescript": "^2.3.1",
"connect": "^2.30.2",
"hubot": "3",
"hubot-rocketchat": "rocketchat/hubot-rocketchat",
"net-ping": "^1.2.3"
},
"devDependencies": {
"dotenv": "^5.0.1"
}
}
hubot-rocketchat package.js
{
"_from": "github:rocketchat/hubot-rocketchat",
"_id": "hubot-rocketchat@2.0.0-development",
"_inBundle": false,
"_location": "/hubot-rocketchat",
"_phantomChildren": {},
"_requested": {
"type": "git",
"raw": "hubot-rocketchat@github:rocketchat/hubot-rocketchat",
"name": "hubot-rocketchat",
"escapedName": "hubot-rocketchat",
"rawSpec": "github:rocketchat/hubot-rocketchat",
"saveSpec": "github:rocketchat/hubot-rocketchat",
"fetchSpec": null,
"gitCommittish": null
},
"_requiredBy": [
"/"
],
"_resolved": "github:rocketchat/hubot-rocketchat#930d085472bb9afa122721fa1b0bec59a783b86b",
"_spec": "hubot-rocketchat@github:rocketchat/hubot-rocketchat",
"_where": "/opt/Hubot",
"author": {
"name": "Rocket.Chat",
"url": "https://rocket.chat/"
},
"bugs": {
"url": "https://github.com/RocketChat/hubot-rocketchat/issues",
"email": "support@rocket.chat"
},
"bundleDependencies": false,
"contributors": [
{
"name": "Sing Li",
"email": "sing.li@rocket.chat"
},
{
"name": "Gabriel Engel",
"email": "gabriel.engel@rocket.chat"
},
{
"name": "Aaron Ogle",
"email": "aaron.ogle@rocket.chat"
},
{
"name": "Tim Kinnane",
"email": "tim.kinnane@rocket.chat"
}
],
"dependencies": {
"@rocket.chat/sdk": "^0.2.1",
"hubot": "3"
},
"deprecated": false,
"description": "Hubot Rocket.Chat Adapter",
"files": [
"index.js"
],
"homepage": "https://github.com/RocketChat/hubot-rocketchat#readme",
"keywords": [
"hubot",
"adapter",
"rocketchat",
"rocket",
"chat"
],
"license": "MIT",
"main": "index.js",
"name": "hubot-rocketchat",
"peerDependencies": {
"hubot": "3"
},
"repository": {
"type": "git",
"url": "git+https://github.com/RocketChat/hubot-rocketchat.git"
},
"version": "2.0.0-development"
}
hubot script
module.exports = function(robot) {
return robot.router.post("/nagios", function(req, res) {
var body, envelope, messages, room;
body = req.body;
room = body.room;
messages = body.messages;
robot.logger.info("Messages '" + messages + "' received for room " + room);
envelope = robot.brain.userForId('broadcast');
envelope.user = {};
if (room) {
envelope.user.room = envelope.room = room;
}
envelope.user.type = body.type || 'groupchat';
if (messages) {
robot.send(envelope, messages);
}
res.writeHead(200, {'Content-Type': 'text/plain'});
return res.end('Thanks\n');
});
};
Hubot Log
call hubot to ping server
[Mon Jul 30 2018 14:44:26 GMT+0800 (CST)] INFO [received] Message in room EbksrjZQH3ZNdC7v3
[Mon Jul 30 2018 14:44:26 GMT+0800 (CST)] INFO Message receive callback ID vqSTzcnKQW6e8qZNN at Mon Jul 30 2018 14:44:26 GMT+0800 (CST)
[Mon Jul 30 2018 14:44:26 GMT+0800 (CST)] INFO [Incoming] kartwang: ping server 8.8.4.4
[Mon Jul 30 2018 14:44:26 GMT+0800 (CST)] INFO Filters passed, will receive message
[Mon Jul 30 2018 14:44:26 GMT+0800 (CST)] DEBUG TextMessage: ping server 8.8.4.4
[Mon Jul 30 2018 14:44:26 GMT+0800 (CST)] DEBUG Message 'ping server 8.8.4.4' matched regex //ping server (.*)/i/; listener.options = { id: null }
[Mon Jul 30 2018 14:44:26 GMT+0800 (CST)] DEBUG Executing listener callback for Message 'ping server 8.8.4.4'
[Mon Jul 30 2018 14:44:26 GMT+0800 (CST)] INFO [sendMessage] Calling (async): [{"msg":"進行Ping Server 作業....","bot":{"i":"js.SDK"},"rid":"EbksrjZQH3ZNdC7v3"}]
[Mon Jul 30 2018 14:44:26 GMT+0800 (CST)] INFO [received] Message in room EbksrjZQH3ZNdC7v3
[Mon Jul 30 2018 14:44:26 GMT+0800 (CST)] INFO [sendMessage] Calling (async): [{"msg":"8.8.4.4: Online","bot":{"i":"js.SDK"},"rid":"EbksrjZQH3ZNdC7v3"}]
[Mon Jul 30 2018 14:44:26 GMT+0800 (CST)] DEBUG [sendMessage] Success: {"msg":"進行Ping Server 作業....","bot":{"i":"js.SDK"},"rid":"EbksrjZQH3ZNdC7v3","ts":{"$date":1532933066386},"u":{"_id":"AX2jBD9Sn5S5qt6mw","username":"kbot","name":"kbot"},"mentions":[],"channels":[],"_updatedAt":{"$date":1532933066407},"_id":"3Ywfq4KKEmMPjQvmL"}
[Mon Jul 30 2018 14:44:26 GMT+0800 (CST)] INFO [received] Message in room EbksrjZQH3ZNdC7v3
[Mon Jul 30 2018 14:44:26 GMT+0800 (CST)] DEBUG [sendMessage] Success: {"msg":"8.8.4.4: Online","bot":{"i":"js.SDK"},"rid":"EbksrjZQH3ZNdC7v3","ts":{"$date":1532933066430},"u":{"_id":"AX2jBD9Sn5S5qt6mw","username":"kbot","name":"kbot"},"mentions":[],"channels":[],"_updatedAt":{"$date":1532933066439},"_id":"3DgzoCD5DWe5izFQX"}
Hubot initiates send message in the general group
[Mon Jul 30 2018 14:44:47 GMT+0800 (CST)] INFO Messages '-------------------------------------
主機名稱: HOSTALIAS
服務名稱: SERVICEDESC
服務狀態: SERVICESTATE
額外資訊: SERVICEOUTPUT
-------------------------------------' received for room general
[Mon Jul 30 2018 14:44:47 GMT+0800 (CST)] DEBUG [getRoomIdByNameOrId] Calling (caching): general
[Mon Jul 30 2018 14:44:47 GMT+0800 (CST)] DEBUG [getRoomIdByNameOrId] Success: "GENERAL"
[Mon Jul 30 2018 14:44:47 GMT+0800 (CST)] INFO [sendMessage] Calling (async): [{"msg":"------------------------------------- \n 主機名稱: HOSTALIAS \n 服務名稱: SERVICEDESC \n 服務狀態: SERVICESTATE \n 額外資訊: SERVICEOUTPUT \n -------------------------------------","bot":{"i":"js.SDK"},"rid":"GENERAL"}]
[Mon Jul 30 2018 14:44:47 GMT+0800 (CST)] INFO [received] Message in room GENERAL
[Mon Jul 30 2018 14:44:47 GMT+0800 (CST)] DEBUG [sendMessage] Success: {"msg":"------------------------------------- \n 主機名稱: HOSTALIAS \n 服務名稱: SERVICEDESC \n 服務狀態: SERVICESTATE \n 額外資訊: SERVICEOUTPUT \n -------------------------------------","bot":{"i":"js.SDK"},"rid":"GENERAL","ts":{"$date":1532933087228},"u":{"_id":"AX2jBD9Sn5S5qt6mw","username":"kbot","name":"kbot"},"mentions":[],"channels":[],"_updatedAt":{"$date":1532933087236},"_id":"KFETCr2ses6NuRXTu"}
Hubot initiates send message in the private group
[Mon Jul 30 2018 14:44:59 GMT+0800 (CST)] INFO Messages '-------------------------------------
主機名稱: HOSTALIAS
服務名稱: SERVICEDESC
服務狀態: SERVICESTATE
額外資訊: SERVICEOUTPUT
-------------------------------------' received for room kart-test
[Mon Jul 30 2018 14:44:59 GMT+0800 (CST)] DEBUG [getRoomIdByNameOrId] Calling (caching): kart-test
[Mon Jul 30 2018 14:44:59 GMT+0800 (CST)] ERROR [getRoomIdByNameOrId] Error: { isClientSafe: true,
error: 'error-not-allowed',
reason: 'Not allowed',
details: { method: 'getRoomIdByNameOrId' },
message: 'Not allowed [error-not-allowed]',
errorType: 'Meteor.Error' }
(node:14370) UnhandledPromiseRejectionWarning: #<Object>
(node:14370) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14370) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (4 by maintainers)
@erikyuzwa I wrote most of the current Hubot adapter, so I feel responsible when it breaks. Turns out this had nothing to do with me though. 👼
Fix submitted on core issue. Please comment there… RocketChat/Rocket.Chat#11552
Found the issue: https://github.com/RocketChat/Rocket.Chat/commit/9e0a8f50d70edf1e5d46d3eaa2aa2cd636a002a6#r29998066
Updates to the method changed the logic to not check if the user is in the room anymore. So if it’s not a public room (type==c), it always throws a permission error.
It seems the room object no longer contains usernames, so that couldn’t be checked that way. So instead of updating the logic, it was just removed 😦
I’m looking for a solution now and will PR to core.
I’m looking into it now also. Had no time recently, still don’t really but it’s obviously becoming more critical. Will update ASAP.
I have a few test systems always up and running… let me know if I can be of any help. Deploying test code, standing up a quick server or multiple servers on multiple versions… I’d love to get this resolved! Our ops team really relies on the bots we’ve written for day to day administration!