Chat with admin (#3758)

Intégration de l'API Crisp
This commit is contained in:
Pierre de La Morinerie 2019-06-05 17:51:27 +02:00 committed by GitHub
commit e0d2a31880
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 59 additions and 2 deletions

View file

@ -96,6 +96,7 @@ class ApplicationController < ActionController::Base
if administrateur_signed_in?
gon.sendinblue = sendinblue_config
gon.crisp = crisp_config
end
end
@ -239,6 +240,21 @@ class ApplicationController < ActionController::Base
}
end
def crisp_config
crisp = Rails.application.secrets.crisp
{
key: crisp[:client_key],
enabled: crisp[:enabled],
administrateur: {
email: current_administrateur&.email,
DS_SIGN_IN_COUNT: current_administrateur&.sign_in_count,
DS_CREATED_AT: current_administrateur&.created_at,
DS_ID: current_administrateur&.id
}
}
end
def current_email
current_user&.email ||
current_gestionnaire&.email ||

View file

@ -1 +1,2 @@
import '../shared/track/sendinblue';
import '../shared/track/crisp';

View file

@ -0,0 +1,32 @@
const { key, enabled, administrateur } = gon.crisp || {};
if (enabled) {
window.$crisp = [];
window.CRISP_WEBSITE_ID = key;
const script = document.createElement('script');
const firstScript = document.getElementsByTagName('script')[0];
script.type = 'text/javascript';
script.id = 'crisp-js';
script.async = true;
script.src = 'https://client.crisp.chat/l.js';
firstScript.parentNode.insertBefore(script, firstScript);
window.$crisp.push(['set', 'user:email', [administrateur.email]]);
window.$crisp.push(['set', 'session:segments', [['administrateur']]]);
window.$crisp.push([
'set',
'session:data',
[
[
['DS_ID', administrateur.email],
['DS_SIGN_IN_COUNT', administrateur.DS_SIGN_IN_COUNT],
[
'URL_MANAGER',
'https://www.demarches-simplifiees.fr/manager/administrateurs/' +
administrateur.DS_ID
]
]
]
]);
}

View file

@ -14,7 +14,7 @@
= favicon_link_tag(image_url("favicons/32x32.png"), type: "image/png", sizes: "32x32")
= favicon_link_tag(image_url("favicons/96x96.png"), type: "image/png", sizes: "96x96")
- packs = ['application', 'track', administrateur_signed_in? ? 'sendinblue' : nil].compact
- packs = ['application', 'track', administrateur_signed_in? ? 'track-admin' : nil].compact
= javascript_packs_with_chunks_tag *packs, defer: true, 'data-turbolinks-track': 'reload'
= stylesheet_link_tag 'new_design/new_application', media: 'all', 'data-turbolinks-track': 'reload'
= stylesheet_link_tag 'new_design/print', media: 'print', 'data-turbolinks-track': 'reload'

View file

@ -12,7 +12,7 @@
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': "reload"
= stylesheet_link_tag 'print', media: 'print', 'data-turbolinks-track': "reload"
- packs = ['application-old', 'track', administrateur_signed_in? ? 'sendinblue' : nil].compact
- packs = ['application-old', 'track', administrateur_signed_in? ? 'track-admin' : nil].compact
= javascript_packs_with_chunks_tag *packs, defer: true, 'data-turbolinks-track': 'reload'
= javascript_include_tag 'application', defer: true, 'data-turbolinks-track': 'reload'
= csrf_meta_tags

View file

@ -46,6 +46,9 @@ MATOMO_ENABLED="disabled"
MATOMO_ID="73"
SENDINBLUE_ENABLED="disabled"
SENDINBLUE_CLIENT_KEY=""
CRISP_ENABLED="disabled"
CRISP_CLIENT_KEY=""
MAILTRAP_ENABLED="disabled"
MAILTRAP_USERNAME=""

View file

@ -61,6 +61,11 @@ defaults: &defaults
enabled: <%= ENV['SENTRY_ENABLED'] == 'enabled' %>
client_key: <%= ENV['SENTRY_DSN_JS'] %>
environment: <%= ENV['SENTRY_CURRENT_ENV'] %>
crisp:
enabled: <%= ENV['CRISP_ENABLED'] == 'enabled' %>
client_key: <%= ENV['CRISP_CLIENT_KEY'] %>
development:
<<: *defaults