Files
dpl/integrations/chatwoot/widget-show.html.erb
T

80 lines
4.2 KiB
ERB

<!DOCTYPE html>
<% native_hn_widget = @web_widget.website_url == 'http://hn.loc'
primary_origin = @web_widget.website_url
extra_origins = primary_origin == ENV['XB_WIDGET_PRIMARY_ORIGIN'] ? ENV.fetch('XB_WIDGET_EXTRA_ORIGINS', '').split(',').map(&:strip) : []
%>
<html>
<head>
<title><%= @global_config['INSTALLATION_NAME'] %></title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
<meta name="robots" content="noindex">
<script>
window.chatwootWebChannel = {
avatarUrl: <%= raw json_escape(@web_widget.inbox.avatar_url.to_json) %>,
hasAConnectedAgentBot: <%= raw json_escape(@web_widget.inbox.agent_bot&.name.to_json) %>,
locale: '<%= @web_widget.account.locale %>',
websiteName: <%= raw json_escape(@web_widget.inbox.name.to_json) %>,
websiteToken: '<%= @web_widget.website_token %>',
welcomeTagline: <%= @web_widget.welcome_tagline.to_json.html_safe %>,
welcomeTitle: <%= raw json_escape(@web_widget.welcome_title.to_json) %>,
widgetColor: '<%= @web_widget.widget_color %>',
portal: <%= @web_widget.inbox.portal.to_json.html_safe %>,
enabledFeatures: <%= @web_widget.selected_feature_flags.to_json.html_safe %>,
enabledLanguages: <%= available_locales_with_name.to_json.html_safe %>,
replyTime: '<%= @web_widget.reply_time %>',
preChatFormEnabled: <%= @web_widget.pre_chat_form_enabled %>,
preChatFormOptions: <%= @web_widget.pre_chat_form_options.to_json.html_safe %>,
workingHoursEnabled: <%= @web_widget.inbox.working_hours_enabled %>,
csatSurveyEnabled: <%= @web_widget.inbox.csat_survey_enabled %>,
workingHours: <%= @web_widget.inbox.working_hours.to_json.html_safe %>,
outOfOfficeMessage: <%= @web_widget.inbox.out_of_office_message.to_json.html_safe %>,
utcOffset: '<%= ActiveSupport::TimeZone[@web_widget.inbox.timezone].now.formatted_offset %>',
timezone: '<%= @web_widget.inbox.timezone %>',
allowMessagesAfterResolved: <%= @web_widget.inbox.allow_messages_after_resolved %>,
disableBranding: <%= !native_hn_widget || @web_widget.inbox.account.feature_enabled?('disable_branding') %>,
}
window.chatwootPubsubToken = '<%= @contact_inbox.pubsub_token %>'
window.authToken = '<%= @token %>'
window.globalConfig = <%= raw @global_config.to_json %>
<% unless native_hn_widget %>
// Fetch published help articles on each widget load instead of reusing
// Chatwoot's 24-hour article cache. Leave contact/conversation storage intact.
try {
const slug = window.chatwootWebChannel.portal?.slug;
if (slug) {
const prefix = `chatwoot_most_read_articles_${slug}_`;
Object.keys(window.localStorage).filter(key => key.startsWith(prefix))
.forEach(key => window.localStorage.removeItem(key));
}
const agentsKey = `chatwoot_available_agents_${window.chatwootWebChannel.websiteToken}`;
window.localStorage.removeItem(agentsKey);
window.localStorage.removeItem(`${agentsKey}:ts`);
} catch (_) { /* Storage may be unavailable in a restricted browser. */ }
<% end %>
</script>
<% unless native_hn_widget %>
<script>
window.xbParentOrigins = <%= raw json_escape(([primary_origin] + extra_origins).to_json) %>.flatMap(value => {
try { const url = new URL(value); return ['https:', 'http:'].includes(url.protocol) ? [url.origin] : []; }
catch { return []; }
});
</script>
<script defer src="/xb-offline.js?v=<%= File.mtime(Rails.root.join('public', 'xb-offline.js')).to_i %>"></script>
<% end %>
<%= vite_client_tag %>
<%= vite_javascript_tag 'widget' %>
<% unless native_hn_widget %>
<style>
/* Upstream Branding's disabled branch leaves an empty padded footer. */
#app .relative.flex.flex-col.h-full > .p-3:empty { display: none; }
/* Match the chat composer's existing 20px horizontal inset. */
#app footer:has(#chat-input) { margin-bottom: 20px; }
</style>
<% end %>
</head>
<body>
<div id="app" class="h-full"></div>
<%= yield %>
</body>
</html>