diff --git a/app/builders/contact_builder.rb b/app/builders/contact_builder.rb index b63d72627..10ce8ee26 100644 --- a/app/builders/contact_builder.rb +++ b/app/builders/contact_builder.rb @@ -15,11 +15,10 @@ class ContactBuilder end def create_contact_inbox(contact) - ::ContactInbox.create!( + ::ContactInbox.create_with(hmac_verified: hmac_verified || false).find_or_create_by!( contact_id: contact.id, inbox_id: inbox.id, - source_id: source_id, - hmac_verified: hmac_verified || false + source_id: source_id ) end diff --git a/app/builders/messages/facebook/message_builder.rb b/app/builders/messages/facebook/message_builder.rb index 204b452d6..9c9b5829b 100644 --- a/app/builders/messages/facebook/message_builder.rb +++ b/app/builders/messages/facebook/message_builder.rb @@ -43,7 +43,7 @@ class Messages::Facebook::MessageBuilder < Messages::Messenger::MessageBuilder return if contact.present? @contact = Contact.create!(contact_params.except(:remote_avatar_url)) - @contact_inbox = ContactInbox.create(contact: contact, inbox: @inbox, source_id: @sender_id) + @contact_inbox = ContactInbox.find_or_create_by!(contact: contact, inbox: @inbox, source_id: @sender_id) end def build_message diff --git a/app/channels/room_channel.rb b/app/channels/room_channel.rb index 05bff5d86..0680f1458 100644 --- a/app/channels/room_channel.rb +++ b/app/channels/room_channel.rb @@ -45,6 +45,8 @@ class RoomChannel < ApplicationCable::Channel end def current_account + return if current_user.blank? + @current_account ||= if @current_user.is_a? Contact @current_user.account else diff --git a/app/controllers/api/v1/accounts/channels/twilio_channels_controller.rb b/app/controllers/api/v1/accounts/channels/twilio_channels_controller.rb index a53650e65..f5a3c6a6d 100644 --- a/app/controllers/api/v1/accounts/channels/twilio_channels_controller.rb +++ b/app/controllers/api/v1/accounts/channels/twilio_channels_controller.rb @@ -7,7 +7,6 @@ class Api::V1::Accounts::Channels::TwilioChannelsController < Api::V1::Accounts: build_inbox setup_webhooks if @twilio_channel.sms? rescue StandardError => e - Sentry.capture_exception(e) render_could_not_create_error(e.message) end end diff --git a/app/controllers/api/v1/accounts/conversations/base_controller.rb b/app/controllers/api/v1/accounts/conversations/base_controller.rb index b55b72013..da821a3e5 100644 --- a/app/controllers/api/v1/accounts/conversations/base_controller.rb +++ b/app/controllers/api/v1/accounts/conversations/base_controller.rb @@ -5,7 +5,7 @@ class Api::V1::Accounts::Conversations::BaseController < Api::V1::Accounts::Base private def conversation - @conversation ||= Current.account.conversations.find_by(display_id: params[:conversation_id]) + @conversation ||= Current.account.conversations.find_by!(display_id: params[:conversation_id]) authorize @conversation.inbox, :show? end end diff --git a/app/finders/message_finder.rb b/app/finders/message_finder.rb index 63c72bd8e..e2581e0ad 100644 --- a/app/finders/message_finder.rb +++ b/app/finders/message_finder.rb @@ -22,7 +22,7 @@ class MessageFinder def current_messages if @params[:before].present? - messages.reorder('created_at desc').where('id < ?', @params[:before]).limit(20).reverse + messages.reorder('created_at desc').where('id < ?', @params[:before].to_i).limit(20).reverse else messages.reorder('created_at desc').limit(20).reverse end diff --git a/app/jobs/hook_job.rb b/app/jobs/hook_job.rb index 57c2896a5..9414ba432 100644 --- a/app/jobs/hook_job.rb +++ b/app/jobs/hook_job.rb @@ -9,7 +9,7 @@ class HookJob < ApplicationJob process_dialogflow_integration(hook, event_name, event_data) end rescue StandardError => e - Sentry.capture_exception(e) + Rails.logger.error e end private diff --git a/lib/webhooks/trigger.rb b/lib/webhooks/trigger.rb index 6ddd9914b..383994f55 100644 --- a/lib/webhooks/trigger.rb +++ b/lib/webhooks/trigger.rb @@ -7,7 +7,7 @@ class Webhooks::Trigger timeout: 5 ) Rails.logger.info "Performed Request: Code - #{response.code}" - rescue *ExceptionList::REST_CLIENT_EXCEPTIONS => e + rescue *ExceptionList::REST_CLIENT_EXCEPTIONS, URI::InvalidURIError => e Rails.logger.error "Exception: invalid webhook url #{url} : #{e.message}" rescue StandardError => e Rails.logger.error "Exception: invalid webhook url #{url} : #{e.message}"