2018-08-29 11:43:00 +02:00
|
|
|
class Helpscout::FormAdapter
|
|
|
|
attr_reader :params
|
|
|
|
|
2020-08-25 15:01:54 +02:00
|
|
|
def self.options
|
|
|
|
[
|
2023-01-09 18:16:04 +01:00
|
|
|
[I18n.t(:question, scope: [:support, :index, TYPE_INFO]), TYPE_INFO, I18n.t("links.common.faq.contacter_service_en_charge_url")],
|
2021-09-16 21:51:16 +02:00
|
|
|
[I18n.t(:question, scope: [:support, :index, TYPE_PERDU]), TYPE_PERDU, LISTE_DES_DEMARCHES_URL],
|
2023-01-09 18:16:04 +01:00
|
|
|
[I18n.t(:question, scope: [:support, :index, TYPE_INSTRUCTION]), TYPE_INSTRUCTION, I18n.t("links.common.faq.ou_en_est_mon_dossier_url")],
|
2021-09-16 21:51:16 +02:00
|
|
|
[I18n.t(:question, scope: [:support, :index, TYPE_AMELIORATION]), TYPE_AMELIORATION, FEATURE_UPVOTE_URL],
|
|
|
|
[I18n.t(:question, scope: [:support, :index, TYPE_AUTRE]), TYPE_AUTRE]
|
2020-08-25 15:01:54 +02:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.admin_options
|
|
|
|
[
|
2024-03-20 11:34:54 +01:00
|
|
|
[I18n.t(:question, scope: [:support, :admin, ADMIN_TYPE_QUESTION], app_name: Current.application_name), ADMIN_TYPE_QUESTION],
|
|
|
|
[I18n.t(:question, scope: [:support, :admin, ADMIN_TYPE_RDV], app_name: Current.application_name), ADMIN_TYPE_RDV],
|
|
|
|
[I18n.t(:question, scope: [:support, :admin, ADMIN_TYPE_SOUCIS], app_name: Current.application_name), ADMIN_TYPE_SOUCIS],
|
2021-09-17 05:48:35 +02:00
|
|
|
[I18n.t(:question, scope: [:support, :admin, ADMIN_TYPE_PRODUIT]), ADMIN_TYPE_PRODUIT],
|
|
|
|
[I18n.t(:question, scope: [:support, :admin, ADMIN_TYPE_DEMANDE_COMPTE]), ADMIN_TYPE_DEMANDE_COMPTE],
|
|
|
|
[I18n.t(:question, scope: [:support, :admin, ADMIN_TYPE_AUTRE]), ADMIN_TYPE_AUTRE]
|
2020-08-25 15:01:54 +02:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2018-08-29 11:43:00 +02:00
|
|
|
def initialize(params = {}, api = nil)
|
|
|
|
@params = params
|
|
|
|
@api = api || Helpscout::API.new
|
|
|
|
end
|
|
|
|
|
2020-08-25 15:01:54 +02:00
|
|
|
TYPE_INFO = 'procedure_info'
|
|
|
|
TYPE_PERDU = 'lost_user'
|
|
|
|
TYPE_INSTRUCTION = 'instruction_info'
|
|
|
|
TYPE_AMELIORATION = 'product'
|
|
|
|
TYPE_AUTRE = 'other'
|
2018-08-29 11:43:00 +02:00
|
|
|
|
2018-11-28 15:19:12 +01:00
|
|
|
ADMIN_TYPE_RDV = 'admin demande rdv'
|
|
|
|
ADMIN_TYPE_QUESTION = 'admin question'
|
|
|
|
ADMIN_TYPE_SOUCIS = 'admin soucis'
|
2018-12-20 14:18:42 +01:00
|
|
|
ADMIN_TYPE_PRODUIT = 'admin suggestion produit'
|
|
|
|
ADMIN_TYPE_DEMANDE_COMPTE = 'admin demande compte'
|
2018-11-28 15:19:12 +01:00
|
|
|
ADMIN_TYPE_AUTRE = 'admin autre'
|
|
|
|
|
2018-08-29 11:43:00 +02:00
|
|
|
def send_form
|
|
|
|
conversation_id = create_conversation
|
|
|
|
|
|
|
|
if conversation_id.present?
|
|
|
|
add_tags(conversation_id)
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def add_tags(conversation_id)
|
2021-12-09 11:23:03 +01:00
|
|
|
@api.add_tags(conversation_id, tags)
|
|
|
|
end
|
|
|
|
|
|
|
|
def tags
|
|
|
|
(params[:tags].presence || []) + ['contact form']
|
2018-08-29 11:43:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_conversation
|
|
|
|
response = @api.create_conversation(
|
|
|
|
params[:email],
|
|
|
|
params[:subject],
|
|
|
|
params[:text],
|
2024-06-13 13:27:32 +02:00
|
|
|
params[:blob]
|
2018-08-29 11:43:00 +02:00
|
|
|
)
|
|
|
|
|
2018-11-28 15:19:12 +01:00
|
|
|
if response.success?
|
|
|
|
if params[:phone].present?
|
|
|
|
@api.add_phone_number(params[:email], params[:phone])
|
|
|
|
end
|
|
|
|
response.headers['Resource-ID']
|
2024-06-13 13:27:32 +02:00
|
|
|
else
|
|
|
|
raise StandardError, "Error while creating conversation: #{response.response_code} '#{response.body}'"
|
2018-11-28 15:19:12 +01:00
|
|
|
end
|
2018-08-29 11:43:00 +02:00
|
|
|
end
|
|
|
|
end
|