lib/ruboty/adapters/slack_rtm.rb in ruboty-slack_rtm-2.9.0 vs lib/ruboty/adapters/slack_rtm.rb in ruboty-slack_rtm-3.0.0

- old
+ new

@@ -1,10 +1,11 @@ require 'cgi' require 'time' require 'json' require 'slack' require 'ruboty/adapters/base' +require 'faraday' module Ruboty module Adapters class SlackRTM < Base env :SLACK_TOKEN, "Account's token. get one on https://api.slack.com/web#basics" @@ -35,10 +36,20 @@ parse: message[:parse] || 'full', unfurl_links: true, as_user: true, attachments: message[:attachments].to_json ) + elsif message[:file] + path = message[:file][:path] + client.files_upload( + channels: channel, + as_user: true, + file: Faraday::UploadIO.new(path, message[:file][:content_type]), + title: message[:file][:title] || path, + filename: File.basename(path), + initial_comment: message[:body] || '' + ) else realtime.send_message( type: 'message', channel: channel, text: message[:code] ? "```\n#{message[:body]}\n```" : resolve_send_mention(message[:body]), @@ -82,11 +93,11 @@ end loop do realtime.main_loop rescue nil break unless ENV['SLACK_AUTO_RECONNECT'] - @url = null - @realtime = null + @url = nil + @realtime = nil end end def url @url ||= begin