## Description Adds Freshdesk as an integration import source so administrators can validate a Freshdesk domain and API key, then import contacts, tickets, public replies, customer replies, and private notes while tracking progress from Data Imports. The integration has now been validated against a live Freshdesk trial tenant with contacts, Web Chat and phone tickets, public replies, customer replies, a private note, pagination, requester expansion, and attachment metadata. That validation found and fixed the current Web Chat source mapping and prevented the ticket description from duplicating the initial Web Chat message. Related: #15116 ## Closes Closes [CW-7639](https://linear.app/chatwoot/issue/CW-7639/freshdesk-freshworks-migration) ## Type of change - [x] New feature (non-breaking change which adds functionality) ## What changed - Added a shared source adapter, importer, job, retry, restart, creation, and placeholder inbox contract used by Intercom and Freshdesk. - Added Freshdesk API authentication, contact and ticket pagination, requester expansion, conversation retrieval, normalization, channel grouping, and error handling. - Added current Freshdesk source identifiers through SMS, including Web Chat source `15`, and grouped equivalent sources into placeholder inboxes. - Used Web Chat conversation events as the complete message history so the generated ticket description does not duplicate the initial customer message. - Preserved Freshdesk ticket subjects in source metadata and added a sanitized live-derived Web Chat fixture with structured bodies and attachment metadata. - Added Freshdesk selection, domain and API key validation, and provider-neutral import status handling in the Data Imports UI. ## How to test 1. Enable the data_import feature for an account and open Settings > Data > New import. 2. Select Freshdesk and enter a Freshdesk domain and API key. 3. Select contacts and/or conversations, validate the credentials, and start the import. 4. Confirm progress is displayed and imported tickets appear as resolved conversations in Freshdesk placeholder inboxes with public replies and private notes preserved. 5. Verify Web Chat tickets appear in the Chat placeholder inbox and the initial customer message is imported once. 6. Verify an abandoned import can be restarted and a stalled import can be retried. ## Current scope - **Product decision:** Attachment binaries are intentionally not imported in the current migration scope. Attachment metadata is preserved and messages include a skipped-attachment marker. - Adaptive Retry-After scheduling and handling the 30,000-ticket listing ceiling are covered by stacked follow-up PRs. ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
66 lines
1.8 KiB
Ruby
66 lines
1.8 KiB
Ruby
class DataImports::CreationService
|
|
def initialize(account:, initiated_by:, source_params:)
|
|
@account = account
|
|
@initiated_by = initiated_by
|
|
@source_params = source_params.symbolize_keys
|
|
@access_token = @source_params[:access_token].to_s.strip
|
|
@provider = @source_params[:source_provider].to_s
|
|
@source_class = DataImports::Source.source_class(@provider)
|
|
end
|
|
|
|
def perform
|
|
return if active_import?
|
|
|
|
totals = validate_source
|
|
@account.with_lock do
|
|
next if active_import?
|
|
|
|
@account.data_imports.new(attributes(totals)).tap do |data_import|
|
|
data_import.assign_active_import_run_id
|
|
data_import.save!
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def validate_source
|
|
@source_class.credentials_validator(source_params: @source_params, import_types: import_types).perform
|
|
end
|
|
|
|
def attributes(totals)
|
|
{
|
|
name: @source_params[:name].presence || @source_class.default_import_name,
|
|
data_type: @provider,
|
|
source_type: 'api',
|
|
source_provider: @provider,
|
|
import_types: import_types,
|
|
initiated_by: @initiated_by,
|
|
access_token: @access_token,
|
|
source_metadata: @source_class.source_metadata(@source_params),
|
|
stats: initial_stats(totals)
|
|
}
|
|
end
|
|
|
|
def import_types
|
|
return DataImports::Importer::DEFAULT_IMPORT_TYPES unless @source_params.key?(:import_types)
|
|
|
|
Array(@source_params[:import_types]).compact_blank
|
|
end
|
|
|
|
def initial_stats(totals)
|
|
{
|
|
'contacts' => { 'imported' => 0, 'skipped' => 0 },
|
|
'conversations' => { 'imported' => 0, 'skipped' => 0 },
|
|
'messages' => { 'imported' => 0, 'skipped' => 0 },
|
|
'errors' => { 'count' => 0 }
|
|
}.tap do |stats|
|
|
totals.each { |type, total| stats[type]['total'] = total unless total.nil? }
|
|
end
|
|
end
|
|
|
|
def active_import?
|
|
@account.data_imports.active_integrations.exists?
|
|
end
|
|
end
|