Skip to content

Commit 4011a9e

Browse files
garychapmangeekgonecrazy
authored andcommitted
Add attachment support back. Originally implemented - #160
Reinstated changes from 72bbf02 that were lost during 9245376 (#160)
1 parent 9041ca3 commit 4011a9e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/rocketchat.coffee

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class RocketChatBotAdapter extends Adapter
149149
edited = new Date(newmsg.editedAt.$date)
150150
curts = if edited > curts then edited else curts
151151
@robot.logger.info "Message receive callback id " + newmsg._id + " ts " + curts
152-
@robot.logger.info "[Incoming] #{newmsg.u.username}: #{newmsg.msg}"
152+
@robot.logger.info "[Incoming] #{newmsg.u.username}: #{if newmsg.file? then newmsg.attachments[0].title else newmsg.msg}"
153153

154154
if curts > @lastts
155155
@lastts = curts
@@ -158,7 +158,25 @@ class RocketChatBotAdapter extends Adapter
158158
@robot.receive new EnterMessage user, null, newmsg._id
159159
else
160160
user = @robot.brain.userForId newmsg.u._id, name: newmsg.u.username, room: newmsg.rid
161-
message = new TextMessage user, newmsg.msg, newmsg._id
161+
162+
# check for the presence of attachments in the message
163+
if newmsg.file? and newmsg.attachments.length
164+
attachment = newmsg.attachments[0]
165+
166+
if attachment.image_url?
167+
attachment.link = "#{RocketChatURL}#{attachment.image_url}"
168+
attachment.type = 'image'
169+
else if attachment.audio_url?
170+
attachment.link = "#{RocketChatURL}#{attachment.audio_url}"
171+
attachment.type = 'audio'
172+
else if attachment.video_url?
173+
attachment.link = "#{RocketChatURL}#{attachment.video_url}"
174+
attachment.type = 'video'
175+
176+
message = new AttachmentMessage user, attachment, attachment.title, newmsg._id
177+
else
178+
message = new TextMessage user, newmsg.msg, newmsg._id
179+
162180
startOfText = if message.text.indexOf('@') == 0 then 1 else 0
163181
robotIsNamed = message.text.indexOf(@robot.name) == startOfText || message.text.indexOf(@robot.alias) == startOfText
164182
if isDM and not robotIsNamed

0 commit comments

Comments
 (0)