Skip to content

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬

1.1 KB
Raw Blame
class Email::BaseBuilder
  include EmailAddressParseable

  pattr_initialize [:inbox!]

  private

  def channel
    @channel ||= inbox.channel
  end

  def account
    @account ||= inbox.account
  end

  def conversation
    @conversation ||= message.conversation
  end

  def custom_sender_name
    message&.sender&.available_name || I18n.t('conversations.reply.email.header.notifications')
  end

  def sender_name(sender_email)
    # Friendly: <agent_name> from <business_name>
    # Professional: <business_name>
    if inbox.friendly?
      Email::SenderNameBuilder.new(
        account: account,
        sender: message&.sender,
        sender_email: sender_email,
        sender_name: custom_sender_name,
        business_name: business_name
      ).build
    else
      format_email_with_name(business_name, sender_email)
    end
  end

  def business_name
    inbox.sanitized_business_name
  end

  def account_support_email
    # Parse the email to ensure it's in the correct format, the user
    # can save it in the format "Name <[email protected]>"
    parse_email(account.support_email)
  end
end