diff --git a/src/bot.coffee b/src/bot.coffee index 65b5a89f..1cac6dd1 100644 --- a/src/bot.coffee +++ b/src/bot.coffee @@ -272,13 +272,17 @@ class SlackBot extends Adapter # this event type always has a channel user.room = channel @robot.logger.debug "Received enter message for user: #{user.id}, joining: #{channel}" - @receive new EnterMessage user + msg = new EnterMessage user + msg.ts = event.ts + @receive msg else if event.type is "member_left_channel" # this event type always has a channel user.room = channel @robot.logger.debug "Received leave message for user: #{user.id}, joining: #{channel}" - @receive new LeaveMessage user + msg = new LeaveMessage user + msg.ts = event.ts + @receive msg else if event.type is "reaction_added" or event.type is "reaction_removed" diff --git a/test/bot.coffee b/test/bot.coffee index 8e688d60..adb5e413 100644 --- a/test/bot.coffee +++ b/test/bot.coffee @@ -223,13 +223,23 @@ describe 'Handling incoming messages', -> return it 'Should handle member_joined_channel events as envisioned', -> - @slackbot.eventHandler {type: 'member_joined_channel', user: @stubs.user, channel: @stubs.channel.id} + @slackbot.eventHandler + type: 'member_joined_channel' + user: @stubs.user + channel: @stubs.channel.id + ts: @stubs.event_timestamp should.equal @stubs._received.constructor.name, "EnterMessage" + should.equal @stubs._received.ts, @stubs.event_timestamp @stubs._received.user.id.should.equal @stubs.user.id it 'Should handle member_left_channel events as envisioned', -> - @slackbot.eventHandler {type: 'member_left_channel', user: @stubs.user, channel: @stubs.channel.id} + @slackbot.eventHandler + type: 'member_left_channel' + user: @stubs.user + channel: @stubs.channel.id + ts: @stubs.event_timestamp should.equal @stubs._received.constructor.name, "LeaveMessage" + should.equal @stubs._received.ts, @stubs.event_timestamp @stubs._received.user.id.should.equal @stubs.user.id it 'Should handle channel_topic events as envisioned', -> diff --git a/test/stubs.coffee b/test/stubs.coffee index 5e889da9..29ba8491 100644 --- a/test/stubs.coffee +++ b/test/stubs.coffee @@ -112,6 +112,7 @@ beforeEach -> name: 'Example Team' id: 'T123' @stubs.expired_timestamp = 1528238205453 + @stubs.event_timestamp = '1360782804.083113' # Slack client @stubs.client =