Skip to content

Commit

Permalink
Fine tune signal setup
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwr18 committed Oct 24, 2024
1 parent c0eff8d commit bbe1688
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 0 additions & 2 deletions app/controllers/organizations/signal_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def captcha_form; end

def register
response = SignalAdapter::RegisterPhoneNumberService.new(organization_id: @organization.id, register_data: register_data).call
Rails.logger.debug JSON.parse(response.body) if response.body.present?
case response
when Net::HTTPSuccess
redirect_to organization_signal_verify_path
Expand All @@ -21,7 +20,6 @@ def verify_form; end
def verify
token = params[:organization][:signal][:token]
response = SignalAdapter::VerifyPhoneNumberService.new(organization_id: @organization.id, token: token).call
Rails.logger.debug JSON.parse(response.body) if response.body.present?
case response
when Net::HTTPSuccess
SignalAdapter::SetTrustModeJob.perform_later(signal_server_phone_number: @organization.signal_server_phone_number)
Expand Down
7 changes: 4 additions & 3 deletions app/jobs/signal_adapter/set_username_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ def perform(organization_id:)
Accept: 'application/json',
'Content-Type': 'application/json'
})
request.body = { username: organization.project_name.gsub(/\s+/, '').camelize }.to_json
request.body = { username: organization.project_name.gsub(/[^\w\s]/, '').gsub(/\s+/, '').camelize }.to_json
response = Net::HTTP.start(uri.host, uri.port) do |http|
http.request(request)
end
case response
when Net::HTTPSuccess
organization.update!(signal_complete_onboarding_link: JSON.parse(response.body)['username_link'])
else
handle_error(JSON.parse(response.body)['error'])
handle_error(response)
end
end

private

def handle_error(error_message)
def handle_error(response)
error_message = JSON.parse(response.body)['error']
exception = SignalAdapter::BadRequestError.new(error_code: response.code, message: error_message)
context = {
code: response.code,
Expand Down
4 changes: 2 additions & 2 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def whats_app_onboarding_allowed?
end

def telegram_bot
Telegram.bots[id]
Telegram::Bot::Client.new(telegram_bot_api_key)
end

def twilio_instance
Expand Down Expand Up @@ -117,7 +117,7 @@ def contributors_tags_with_count
private

def set_telegram_webhook
return unless saved_change_to_telegram_bot_username?
return unless saved_change_to_telegram_bot_username? && saved_change_to_telegram_bot_api_key?

TelegramAdapter::SetWebhookUrlJob.perform_later(organization_id: id)
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/fields/setup_signal_link_field/_show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p>Klicken Sie hier, um sich zu registrieren, falls Sie noch nicht registriert sind</p>
<p>Klicke hier, um dich zu registrieren, falls du noch nicht registriert bist.</p>
<%= link_to field.setup_signal_url, style: 'text-decoration: underline' do %>
<%= field.signal_server_phone_number %>
<% end %>

0 comments on commit bbe1688

Please sign in to comment.