RUBYCRITIC
class Contact::Integrations::Chatwoot::GenerateConversationLink - Contact::Integrations::Chatwoot::GenerateConversationLink has no descriptive comment
def initialize(contact)
@contact = contact
end
def call - 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 - 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) - 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) - 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