class Lita::Adapters::Slack
A Slack
adapter for Lita
. @api private
@api private
Constants
- TeamData
Attributes
rtm_connection[R]
Public Instance Methods
chat_service()
click to toggle source
Provides an object for Slack-specific features.
# File lib/lita/adapters/slack.rb, line 18 def chat_service ChatService.new(config) end
mention_format(name)
click to toggle source
# File lib/lita/adapters/slack.rb, line 22 def mention_format(name) "@#{name}" end
roster(target)
click to toggle source
Returns UID(s) in an Array or String for: Channels, MPIMs, IMs
# File lib/lita/adapters/slack.rb, line 36 def roster(target) api = API.new(config) room_roster target.id, api end
run()
click to toggle source
Starts the connection.
# File lib/lita/adapters/slack.rb, line 27 def run return if rtm_connection @rtm_connection = RTMConnection.build(robot, config) rtm_connection.run end
send_messages(target, strings)
click to toggle source
# File lib/lita/adapters/slack.rb, line 41 def send_messages(target, strings) api = API.new(config) api.send_messages(channel_for(target), strings) end
set_topic(target, topic)
click to toggle source
# File lib/lita/adapters/slack.rb, line 46 def set_topic(target, topic) channel = target.room Lita.logger.debug("Setting topic for channel #{channel}: #{topic}") API.new(config).set_topic(channel, topic) end
shut_down()
click to toggle source
# File lib/lita/adapters/slack.rb, line 52 def shut_down return unless rtm_connection rtm_connection.shut_down robot.trigger(:disconnected) end
Private Instance Methods
channel_for(target)
click to toggle source
# File lib/lita/adapters/slack.rb, line 63 def channel_for(target) if target.private_message? rtm_connection.im_for(target.user.id) else target.room end end
channel_roster(room_id, api)
click to toggle source
# File lib/lita/adapters/slack.rb, line 71 def channel_roster(room_id, api) response = api.channels_info room_id response['channel']['members'] end
group_roster(room_id, api)
click to toggle source
Returns the members of a group, but only can do so if it's a member
# File lib/lita/adapters/slack.rb, line 77 def group_roster(room_id, api) response = api.groups_list group = response['groups'].select { |hash| hash['id'].eql? room_id }.first group.nil? ? [] : group['members'] end
im_roster(room_id, api)
click to toggle source
Returns the user of an im
# File lib/lita/adapters/slack.rb, line 91 def im_roster(room_id, api) response = api.mpim_list im = response['ims'].select { |hash| hash['id'].eql? room_id }.first im.nil? ? '' : im['user'] end
mpim_roster(room_id, api)
click to toggle source
Returns the members of a mpim, but only can do so if it's a member
# File lib/lita/adapters/slack.rb, line 84 def mpim_roster(room_id, api) response = api.mpim_list mpim = response['groups'].select { |hash| hash['id'].eql? room_id }.first mpim.nil? ? [] : mpim['members'] end
room_roster(room_id, api)
click to toggle source
# File lib/lita/adapters/slack.rb, line 97 def room_roster(room_id, api) case room_id when /^C/ channel_roster room_id, api when /^G/ # Groups & MPIMs have the same room ID pattern, check both if needed roster = group_roster room_id, api roster.empty? ? mpim_roster(room_id, api) : roster when /^D/ im_roster room_id, api end end