lib/socrates/adapters/slack_adapter.rb in socrates-0.1.1 vs lib/socrates/adapters/slack_adapter.rb in socrates-0.1.2

- old
+ new

@@ -1,33 +1,47 @@ -class SlackAdapter - def initialize(slack_real_time_client) - @slack_real_time_client = slack_real_time_client - end +module Socrates + module Adapters + class SlackAdapter + def initialize(slack_real_time_client) + @slack_real_time_client = slack_real_time_client + end - def client_id_from_context(context) - context&.user - end + def client_id_from_context(context) + context&.user + end - def send_message(message, context:) - @slack_real_time_client.message(text: message, channel: context.channel) - end + def send_message(message, context:) + @slack_real_time_client.message(text: message, channel: context.channel) + end - def send_direct_message(message, user, *) - user = user.id if user.respond_to?(:id) + def send_direct_message(message, user, *) + user = user.id if user.respond_to?(:id) - im_channel = lookup_im_channel(user) + im_channel = lookup_im_channel(user) - @slack_real_time_client.message(text: message, channel: im_channel) - end + @slack_real_time_client.message(text: message, channel: im_channel) + end - private + def users_list + client = @slack_real_time_client.web_client + client.users_list + end - def lookup_im_channel(user) - im = @slack_real_time_client.ims.values.find { |i| i.user == user } + def lookup_email(context:) + client = @slack_real_time_client.web_client + client.users_info(user: context.user) + end - return im if im.present? + private - # Start a new conversation with this user. - response = @slack_real_time_client.web_client.im_open(user: user.id) - response.channel.id + def lookup_im_channel(user) + im = @slack_real_time_client.ims.values.find { |i| i.user == user } + + return im if im.present? + + # Start a new conversation with this user. + response = @slack_real_time_client.web_client.im_open(user: user.id) + response.channel.id + end + end end end