Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timestamps for enter and leave messages #596

Merged
merged 1 commit into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/bot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
14 changes: 12 additions & 2 deletions test/bot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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', ->
Expand Down
1 change: 1 addition & 0 deletions test/stubs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ beforeEach ->
name: 'Example Team'
id: 'T123'
@stubs.expired_timestamp = 1528238205453
@stubs.event_timestamp = '1360782804.083113'

# Slack client
@stubs.client =
Expand Down