lib/ruboty/adapters/slack_rtm.rb in ruboty-slack_rtm-2.3.0 vs lib/ruboty/adapters/slack_rtm.rb in ruboty-slack_rtm-2.4.0
- old
+ new
@@ -102,11 +102,11 @@
data = resolve_mention!(data)
user = user_info(data['user']) || {}
channel = channel_info(data['channel'])
- if data['type'] == 'bot_message' && ENV['SLACK_IGNORE_BOT_MESSAGE'] == '1'
+ if data['subtype'] == 'bot_message' && ENV['SLACK_IGNORE_BOT_MESSAGE'] == '1'
return
end
if channel
return if channel['name'] == (ENV['SLACK_GENERAL_NAME'] || 'general') && ENV['SLACK_IGNORE_GENERAL'] == '1'
@@ -114,22 +114,27 @@
channel_to = expose_channel_name? ? "##{channel['name']}" : channel['id']
else # direct message
channel_to = data['channel']
end
- robot.receive(
- body: CGI.unescapeHTML(data['text']),
+ message_info = {
from: data['channel'],
from_name: user['name'],
to: channel_to,
channel: channel,
user: user,
mention_to: data['mention_to'],
time: Time.at(data['ts'].to_f)
- )
- end
+ }
- alias on_bot_message on_message
+ robot.receive(message_info.merge(body: CGI.unescapeHTML(data['text']))
+
+ (data['attachments'] || []).each do |attachment|
+ body = (attachments['fallback'] || "#{attachment['text']} #{attachment['pretext']}").to_s
+
+ robot.receive(message_info.merge(body: CGI.unescapeHTML(body)) unless text.empty?
+ end
+ end
def on_channel_change(data)
make_channels_cache
end
alias_method :on_channel_deleted, :on_channel_change