trabajo-afectivo/lib/sequencer/unit/import/freshdesk/description/mapping.rb

68 lines
2.9 KiB
Ruby
Raw Normal View History

2021-05-25 12:30:12 +00:00
class Sequencer
class Unit
module Import
module Freshdesk
module Description
class Mapping < Sequencer::Unit::Base
include ::Sequencer::Unit::Import::Common::Mapping::Mixin::ProvideMapped
uses :resource, :id_map
SOURCE_MAP = {
0 => ::Ticket::Article::Type.select(:id).find_by(name: 'email').id, # Reply
1 => ::Ticket::Article::Type.select(:id).find_by(name: 'email').id, # Email
2 => ::Ticket::Article::Type.select(:id).find_by(name: 'web').id, # Note
3 => ::Ticket::Article::Type.select(:id).find_by(name: 'phone').id, # Phone
4 => ::Ticket::Article::Type.select(:id).find_by(name: 'note').id, # UNKNOWN!
5 => ::Ticket::Article::Type.select(:id).find_by(name: 'twitter status').id, # Created from tweets
6 => ::Ticket::Article::Type.select(:id).find_by(name: 'web').id, # Created from survey feedback
7 => ::Ticket::Article::Type.select(:id).find_by(name: 'facebook feed post').id, # Created from Facebook post
8 => ::Ticket::Article::Type.select(:id).find_by(name: 'email').id, # Created from Forwarded Email
9 => ::Ticket::Article::Type.select(:id).find_by(name: 'note').id, # Created from Phone
10 => ::Ticket::Article::Type.select(:id).find_by(name: 'note').id, # Created from Mobihelp
11 => ::Ticket::Article::Type.select(:id).find_by(name: 'note').id, # E-Commerce
}.freeze
def process # rubocop:disable Metrics/AbcSize
provide_mapped do
{
from: from,
to: resource['to_emails']&.join(', '),
cc: resource['cc_emails']&.join(', '),
ticket_id: ticket_id,
body: resource['description'],
content_type: 'text/html',
internal: false,
message_id: "ticketid#{resource['id']}@freshdesk.com",
sender_id: ::Ticket::Article::Sender.select(:id).find_by(name: 'Customer').id,
type_id: SOURCE_MAP[ resource['source'] ],
updated_by_id: requester_id,
created_by_id: requester_id,
created_at: resource['created_at'],
updated_at: resource['updated_at'],
}
end
end
private
def from
return nil if resource['to_emails'].blank?
::User.find(requester_id).email
end
def requester_id
id_map['User'][resource['requester_id']]
end
def ticket_id
id_map['Ticket'][resource['id']]
end
end
end
end
end
end
end