Skip to content

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

712 B
Raw Blame
module ConversationCustomAttributesConcern
  def custom_attributes
    attributes = params.permit(custom_attributes: {})[:custom_attributes]
    # When `merge` is truthy, only the keys sent are updated and the rest are kept, matching the contacts endpoint.
    # Replace stays the default so existing integrations are unaffected.
    attributes = @conversation.custom_attributes.merge(attributes || {}) if ActiveModel::Type::Boolean.new.cast(params[:merge])
    @conversation.custom_attributes = attributes
    @conversation.save!
  end

  def destroy_custom_attributes
    @conversation.custom_attributes = @conversation.custom_attributes.excluding(params[:custom_attributes])
    @conversation.save!
  end
end