Updated

app/models/contact/integrations/chatwoot / generate_conversation_link.rb

A
33 lines of codes
5 methods
2.9 complexity/method
4 churn
14.3 complexity
0 duplications
class Contact::Integrations::Chatwoot::GenerateConversationLink
  1. Contact::Integrations::Chatwoot::GenerateConversationLink has no descriptive comment
def initialize(contact) @contact = contact end def call
  1. Contact::Integrations::Chatwoot::GenerateConversationLink#call has approx 6 statements
chatwoot = fetch_chatwoot_for_account chatwoot_contact_id = @contact.additional_attributes['chatwoot_id'] return { error: 'no_chatwoot_or_id' } unless chatwoot && chatwoot_contact_id conversation_id = fetch_conversation_id(chatwoot, chatwoot_contact_id) return { error: 'no_conversation' } unless conversation_id { ok: build_conversation_url(chatwoot, conversation_id) } end private def fetch_chatwoot_for_account
  1. Contact::Integrations::Chatwoot::GenerateConversationLink#fetch_chatwoot_for_account doesn't depend on instance state (maybe move it to another class?)
Apps::Chatwoot.first end def fetch_conversation_id(chatwoot, chatwoot_contact_id)
  1. Contact::Integrations::Chatwoot::GenerateConversationLink#fetch_conversation_id doesn't depend on instance state (maybe move it to another class?)
conversations = Accounts::Apps::Chatwoots::GetConversations.call(chatwoot, chatwoot_contact_id) conversations.dig(:ok, 0, 'id') end def build_conversation_url(chatwoot, conversation_id)
  1. Contact::Integrations::Chatwoot::GenerateConversationLink#build_conversation_url doesn't depend on instance state (maybe move it to another class?)
conversation_path = "/app/accounts/#{chatwoot.chatwoot_account_id}/conversations/#{conversation_id}" chatwoot.chatwoot_endpoint_url + conversation_path end end