Closed 0ndifined closed 6 years ago
Can you share your webhook configuration? That info-string should not show up on direct messages.
Yes! Here you go. Let me know if that information is sufficient
{
"_id": "N8wF8zrqFDdzPnC9m",
"event": "sendMessage",
"enabled": true,
"username": "rocket.cat",
"channel": [
"all_direct_messages"
],
"name": "Integration Name",
"triggerWords": [],
"urls": [
"https://URL/hooks/TO-DO"
],
"token": "E7JbjXnrWyHANbcAs3bKAcuZ",
"script": "class Script {\n\tprepare_outgoing_request({\n\t\trequest\n\t}) {\n\t\tconsole.log(request.data.room);\n\t\t/* if (request.data.channel_name.toLowerCase() === \"channelName\") {\n\t\t\trequest.data.url = request.data.siteUrl + \"/request/\" + request.data.room.name;\n\t\t\treturn request;\n\t\t} else {\n\t\t\treturn false;\n\t\t}*/\n\t}\n\tprocess_outgoing_response({\n\t\trequest,\n\t\tresponse\n\t}) {}\n}",
"scriptEnabled": true,
"impersonateUser": false,
"retryFailedCalls": true,
"retryCount": 6,
"retryDelay": "powers-of-ten",
"triggerWordAnywhere": false,
"runOnEdits": true,
"scriptCompiled": "function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError(\"Cannot call a class as a function\")}}var Script=function(){function Script(){_classCallCheck(this,Script)}Script.prototype.prepare_outgoing_request=function prepare_outgoing_request(_ref){var request=_ref.request;console.log(request.data.room)};Script.prototype.process_outgoing_response=function process_outgoing_response(_ref2){var request=_ref2.request,response=_ref2.response};return Script}();",
"scriptError": null,
"type": "webhook-outgoing",
"userId": "rocket.cat",
"_createdAt": "2018-04-11T08:06:17.229Z",
"_createdBy": {
"username": "myUsername",
"_id": "zyaX5AbGaA9bH7APu"
},
"_updatedAt": "2018-04-17T07:12:26.559Z",
"avatar": null,
"emoji": null,
"alias": null,
"targetRoom": null,
"_updatedBy": {
"username": "myUsername",
"_id": "zyaX5AbGaA9bH7APu"
}
}
My script says this:
class Script {
prepare_outgoing_request({
request
}) {
console.log(request.data.room);
/* if (request.data.channel_name.toLowerCase() === "channelName") {
request.data.url = request.data.siteUrl + "/request/" + request.data.room.name;
return request;
} else {
return false;
}*/
}
process_outgoing_response({
request,
response
}) {}
}
The object you pasted on the original message is from that console.log line?
{ _id: 'TAQvbQBejX3HDEcKQzyaX5AbGaA9bH7APu', _updatedAt: 2018 - 04 - 11T08: 44: 35.812Z,
t: 'd', msgs: 16, ts: 2018 - 04 - 11T08: 17: 22.471Z, username: 'assistify.admin', lm: 2018 - 04 -
11T08: 44: 35.805Z, usernames: ['this_will_be_filled_in_with_usernames_when_replayed'] }
It doesn't share the same structure with the object that I would expect to see resulting from that line. Are you perhaps on an older verison of Rocket.Chat?
I am going to close, as the sendMessage
doesn't actually send the data you have logged to the integration. You can see the data it sends at this code:
https://github.com/RocketChat/Rocket.Chat/blob/b97b2235b08a593bc34dc877ad8c60880c50a1e4/packages/rocketchat-integrations/server/lib/triggerHandler.js#L379-L399
And then at replay time the data is pull directly from the database/cache: https://github.com/RocketChat/Rocket.Chat/blob/b97b2235b08a593bc34dc877ad8c60880c50a1e4/packages/rocketchat-integrations/server/lib/triggerHandler.js#L764-L784
I decided to copy your Script and I get undefined
when I do console.log(request.data.room)
. And when I change it to console.log(request.data)
I get the following:
I20180417-23:07:55.199(-5)? { token: 'xmRT4vgE2q3oSe9mgzLptQDz',
I20180417-23:07:55.199(-5)? bot: false,
I20180417-23:07:55.199(-5)? channel_id: 'SchifH3X65c5Z42irrocket.cat',
I20180417-23:07:55.200(-5)? channel_name: undefined,
I20180417-23:07:55.200(-5)? message_id: 'TrhrBniPPEFA6ejGg',
I20180417-23:07:55.200(-5)? timestamp: 2018-04-18T04:07:55.126Z,
I20180417-23:07:55.200(-5)? user_id: 'SchifH3X65c5Z42ir',
I20180417-23:07:55.200(-5)? user_name: 'graywolf336',
I20180417-23:07:55.201(-5)? text: 'Testing' }
So, I am going to close as I can not reproduce using the exact same setup. If you're able to get it to where we can replicate, using the latest version, then please respond back so we can open it back up and look into it.
Just for documentation purposes: This was due to a custom enhancement in our fork where we wanted to propagate the room to the integration
I am reopening because after some more investigating work, it actually effects our codebase and not just the fork. However, the reason why I failed to see this is because their fork exposes the room
property on the message sent events. However, this bug effects the room created events and any other events which expose the room data. Pull request incoming.
I'm trying to create a webhook that sends a notification when a direct message has been written to a specified user. For that, I want to add a script that just checks whether the direct message is sent to the specified user. Unfortunately, the username of the user who receives the message is not part of the request that I can access in the script. The request only consists of this:
{ _id: 'TAQvbQBejX3HDEcKQzyaX5AbGaA9bH7APu', _updatedAt: 2018 - 04 - 11T08: 44: 35.812Z, t: 'd', msgs: 16, ts: 2018 - 04 - 11T08: 17: 22.471Z, username: 'assistify.admin', lm: 2018 - 04 - 11T08: 44: 35.805Z, usernames: ['this_will_be_filled_in_with_usernames_when_replayed'] }
So the array for the usernames is not filled but only show this info-string "this_will_be_filled_in_with_usernames_when_replayed". It should actually contain the list of users in that room. Also, replaying the outgoing webhook event doesn't help.