From f51befbcdc1f14ea3f594cdd914c5d733a1e4367 Mon Sep 17 00:00:00 2001 From: Rodrigo Nardi Date: Mon, 14 Oct 2024 17:02:22 -0300 Subject: [PATCH] Translate Username to ID Adding a route to translate --- lib/github_app/server.rb | 8 ++++++++ lib/slack/client.rb | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/github_app/server.rb b/lib/github_app/server.rb index 9b03433..39810c9 100644 --- a/lib/github_app/server.rb +++ b/lib/github_app/server.rb @@ -19,6 +19,14 @@ class Server < Sinatra::Base halt 200 end + get '/translate/:name' do + user_info = Client.new.find_user_id_by_name(params[:name]) + + halt 404, 'User not found' unless user_info + + halt 200, user_info.profile.display_name + end + post '/comment' do halt 401, 'Invalid user / password' unless authentication Client.new.chat(request.body.read) diff --git a/lib/slack/client.rb b/lib/slack/client.rb index 2b25bd0..aac5575 100644 --- a/lib/slack/client.rb +++ b/lib/slack/client.rb @@ -20,7 +20,14 @@ def initialize config.open_timeout = 60 end - @client = Slack::Web::Client.new + @client = Slack::Web::Client.new do |faraday| + faraday.ssl[:ca_file] = '/home/rnardi/.rvm/gems/ruby-3.3.1@slack_bot/gems/certified-1.0.0/ca-certificates.crt' + end + end + + def find_user_id_by_name(username) + user = @client.users_info(user: "@#{username}") + user ? user.id : nil end def chat(message, channel: fetch_channel)