Module: Livechat::WidgetHelper

Defined in:
app/helpers/livechat/widget_helper.rb

Overview

Included into the host's ActionView. Drop <%= livechat_tag %> before

in your layout; it renders nothing unless chat is enabled for the request. The widget shows a floating launcher (unless show_launcher is off) and also opens from any element carrying `data-livechat-open`, or from `window.Livechat.open()`.

Instance Method Summary collapse

Instance Method Details

#livechat_button(label = nil, message: nil, **options) ⇒ Object

A plain, unstyled



23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/livechat/widget_helper.rb', line 23

def livechat_button(label = nil, message: nil, **options)
  return unless Livechat.enabled?(request)

  label ||= options.delete(:label)
  label ||= I18n.t(:launcher, scope: :livechat, default: 'Chat with us')
  data = (options.delete(:data) { {} } || {}).merge(livechat_open: '')
  data[:livechat_message] = message if message.present?

  tag.button(label, type: 'button', data: data, **options)
end

#livechat_tagObject



10
11
12
13
14
15
16
17
18
# File 'app/helpers/livechat/widget_helper.rb', line 10

def livechat_tag
  return unless Livechat.enabled?(request)

  Widget.snippet(
    locale: I18n.locale,
    authenticated: livechat_visitor.present?,
    nonce: (content_security_policy_nonce if respond_to?(:content_security_policy_nonce))
  ).html_safe
end