Skip to content

Commit

Permalink
Prepare message from string or object (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Kinnane authored and geekgonecrazy committed Aug 22, 2016
1 parent a55587b commit 7122be8
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/rocketchat_driver.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,24 @@ class RocketChatDriver

return r.updated

sendMessage: (text, room) =>
prepareMessage: (content, roomid) =>
@logger.debug "Preparing message from #{ typeof content }"
if typeof content is 'string'
message = {msg: content, rid: roomid}
else
message = content
message.rid = roomid
return message

sendMessage: (message, room) =>
@logger.info "Sending Message To Room: #{room}"
r = @getRoomId room
r.then (roomid) =>
@sendMessageByRoomId text, roomid
@sendMessageByRoomId message, roomid

sendMessageByRoomId: (text, roomid) =>
@asteroid.call('sendMessage', {msg: text, rid: roomid})
sendMessageByRoomId: (content, roomid) =>
message = @prepareMessage content, roomid
@asteroid.call('sendMessage', message)
.then (result)->
@logger.debug('[sendMessage] Success:', result)
.catch (error) ->
Expand Down

0 comments on commit 7122be8

Please sign in to comment.