lib/socrates/bots/slack_bot.rb in socrates-0.1.6 vs lib/socrates/bots/slack_bot.rb in socrates-0.1.7
- old
+ new
@@ -16,16 +16,23 @@
@adapter = Adapters::SlackAdapter.new(@slack_client)
@dispatcher = Core::Dispatcher.new(adapter: @adapter, state_factory: state_factory)
end
def start
+ reply_to_messages = {}
+
@slack_client.on :message do |data|
# puts "> #{data}"
- # When first connecting, Slack may resend the last message. Ignore it...
- next if data.reply_to.present?
+ if data.reply_to.present?
+ # Stash this message away because we may need it later.
+ reply_to_messages[data.channel] = data.text
+ end
- @dispatcher.dispatch(data.text, context: data)
+ # Only dispatch the message if it does not match a previous reply_to message for the channel.
+ if reply_to_messages[data.channel] != data.text
+ @dispatcher.dispatch(data.text, context: data)
+ end
end
@slack_client.start!
end
end