Skip to content
Snippets Groups Projects
Commit 031cbce4 authored by Gabriel Engel's avatar Gabriel Engel
Browse files

Merge pull request #1964 from RocketChat/improvements/outgoing

Outgoing: Get the room from posted message to reply
parents 149a0e91 ef5028e6
No related branches found
No related tags found
No related merge requests found
...@@ -46,12 +46,16 @@ this.processWebhookMessage = function(messageObj, user, defaultValues) { ...@@ -46,12 +46,16 @@ this.processWebhookMessage = function(messageObj, user, defaultValues) {
username: channel username: channel
} }
] ]
}) || {};
rid = [user._id, roomUser._id].sort().join('');
room = RocketChat.models.Rooms.findOne({
_id: {
$in: [rid, channel]
}
}); });
if (roomUser == null) { if (roomUser == null && room == null) {
throw new Meteor.Error('invalid-channel'); throw new Meteor.Error('invalid-channel');
} }
rid = [user._id, roomUser._id].sort().join('');
room = RocketChat.models.Rooms.findOne(rid);
if (!room) { if (!room) {
Meteor.runAsUser(user._id, function() { Meteor.runAsUser(user._id, function() {
Meteor.call('createDirectMessage', roomUser.username); Meteor.call('createDirectMessage', roomUser.username);
......
...@@ -74,20 +74,17 @@ ExecuteTriggerUrl = (url, trigger, message, room, tries=0) -> ...@@ -74,20 +74,17 @@ ExecuteTriggerUrl = (url, trigger, message, room, tries=0) ->
i: trigger._id i: trigger._id
defaultValues = defaultValues =
channel: trigger.channel
alias: trigger.alias alias: trigger.alias
avatar: trigger.avatar avatar: trigger.avatar
emoji: trigger.emoji emoji: trigger.emoji
try if room.t is 'd'
message = processWebhookMessage result.data, user, defaultValues defaultValues.channel = '@'+room._id
else
defaultValues.channel = '#'+room._id
if not message? message = processWebhookMessage result.data, user, defaultValues
return RocketChat.API.v1.failure 'unknown-error'
return RocketChat.API.v1.success()
catch e
return RocketChat.API.v1.failure e.error
ExecuteTrigger = (trigger, message, room) -> ExecuteTrigger = (trigger, message, room) ->
for url in trigger.urls for url in trigger.urls
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment