Class: Livechat::Configuration
- Inherits:
-
Object
- Object
- Livechat::Configuration
- Defined in:
- lib/livechat/configuration.rb
Overview
Host-tunable settings. Everything has a safe default, so a fresh install works with zero configuration; the hooks below let an app decide who can chat, who answers, and how everyone is named.
Instance Attribute Summary collapse
-
#accent_color ⇒ Object
Brand color for the widget (launcher, header, visitor bubbles, send button) as a hex value, e.g.
-
#agent_display_name ⇒ Object
What visitors see as the sender of an agent message.
-
#agent_emails ⇒ Object
Email addresses to notify when a visitor writes and nobody has read it — an array, or a callable returning one.
-
#agent_label ⇒ Object
Turn a resolved user into the attribution stored on an agent's message.
-
#app_name ⇒ Object
Shown in the widget header and in notification emails.
-
#authorize_agent ⇒ Object
Per-request gate for the inbox.
-
#current_user ⇒ Object
Resolve the current user (optional).
-
#enabled ⇒ Object
Per-request gate for the widget and its endpoints.
-
#greeting ⇒ Object
Widget copy.
-
#launcher_label ⇒ Object
Widget copy.
-
#mailer_from ⇒ Object
From-address for the built-in notification emails.
-
#mount_path ⇒ Object
Where the engine is mounted.
-
#on_agent_message ⇒ Object
Called with each saved Livechat::Message — wire up Slack, Noticed, push… Runs inline after save; keep it fast or hand off to a job.
-
#on_visitor_message ⇒ Object
Called with each saved Livechat::Message — wire up Slack, Noticed, push… Runs inline after save; keep it fast or hand off to a job.
-
#rate_limit ⇒ Object
Per-IP throttle for the public endpoints, as keyword arguments for Rails' rate limiter (Rails 7.2+; ignored on 7.1).
-
#reply_time_text ⇒ Object
Widget copy.
-
#show_launcher ⇒ Object
The floating launcher bubble.
-
#visitor_label ⇒ Object
Turn a resolved user into the visitor name shown in the inbox.
Instance Method Summary collapse
- #agent_email_list ⇒ Object
- #emails_enabled? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #widget_endpoint ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/livechat/configuration.rb', line 72 def initialize @app_name = nil @enabled = ->(_request) { true } @authorize_agent = ->(_request) { Rails.env.development? } @current_user = ->(_request) {} @visitor_label = ->(user) { user.try(:name).presence || user.try(:email).presence || user.to_s } @agent_label = ->(user) { user.try(:name).presence || user.try(:email).presence || user.to_s } @agent_display_name = ->(label) { label } @greeting = nil @reply_time_text = nil @launcher_label = nil @accent_color = nil @show_launcher = true @agent_emails = nil @mailer_from = nil @on_visitor_message = ->() {} @on_agent_message = ->() {} @rate_limit = { to: 30, within: 60 } @mount_path = '/livechat' end |
Instance Attribute Details
#accent_color ⇒ Object
Brand color for the widget (launcher, header, visitor bubbles, send button) as a hex value, e.g. "#7c3aed". The widget picks black or white text automatically for contrast. nil keeps the built-in blue.
46 47 48 |
# File 'lib/livechat/configuration.rb', line 46 def accent_color @accent_color end |
#agent_display_name ⇒ Object
What visitors see as the sender of an agent message. Receives the stored agent_label; return it unchanged (default), a first name, or a constant like "Support team" to keep agents anonymous.
37 38 39 |
# File 'lib/livechat/configuration.rb', line 37 def agent_display_name @agent_display_name end |
#agent_emails ⇒ Object
Email addresses to notify when a visitor writes and nobody has read it — an array, or a callable returning one. nil disables the built-in email.
54 55 56 |
# File 'lib/livechat/configuration.rb', line 54 def agent_emails @agent_emails end |
#agent_label ⇒ Object
Turn a resolved user into the attribution stored on an agent's message. Every reply carries this, so a thread with several teammates stays legible.
32 33 34 |
# File 'lib/livechat/configuration.rb', line 32 def agent_label @agent_label end |
#app_name ⇒ Object
Shown in the widget header and in notification emails. nil resolves to the Rails application name.
10 11 12 |
# File 'lib/livechat/configuration.rb', line 10 def app_name @app_name end |
#authorize_agent ⇒ Object
Per-request gate for the inbox. Defaults to development only — override
it before deploying, e.g. with an admin check. Independent of enabled,
so your team can answer from production even where the widget is off.
19 20 21 |
# File 'lib/livechat/configuration.rb', line 19 def @authorize_agent end |
#current_user ⇒ Object
Resolve the current user (optional). Return an object responding to #id, or nil. Receives the request. Signed-in users keep one conversation across devices; guests are tracked with a cookie.
24 25 26 |
# File 'lib/livechat/configuration.rb', line 24 def current_user @current_user end |
#enabled ⇒ Object
Per-request gate for the widget and its endpoints. Return false to hide the widget and reject writes for this request.
14 15 16 |
# File 'lib/livechat/configuration.rb', line 14 def enabled @enabled end |
#greeting ⇒ Object
Widget copy. nil uses the localized defaults. reply_time_text is the honest line under the greeting — "We usually reply within a few hours."
41 42 43 |
# File 'lib/livechat/configuration.rb', line 41 def greeting @greeting end |
#launcher_label ⇒ Object
Widget copy. nil uses the localized defaults. reply_time_text is the honest line under the greeting — "We usually reply within a few hours."
41 42 43 |
# File 'lib/livechat/configuration.rb', line 41 def launcher_label @launcher_label end |
#mailer_from ⇒ Object
From-address for the built-in notification emails. Required for any email to be sent.
58 59 60 |
# File 'lib/livechat/configuration.rb', line 58 def mailer_from @mailer_from end |
#mount_path ⇒ Object
Where the engine is mounted. The widget calls paths under it, so keep
this in sync with the mount line in your routes.
70 71 72 |
# File 'lib/livechat/configuration.rb', line 70 def mount_path @mount_path end |
#on_agent_message ⇒ Object
Called with each saved Livechat::Message — wire up Slack, Noticed, push… Runs inline after save; keep it fast or hand off to a job.
62 63 64 |
# File 'lib/livechat/configuration.rb', line 62 def @on_agent_message end |
#on_visitor_message ⇒ Object
Called with each saved Livechat::Message — wire up Slack, Noticed, push… Runs inline after save; keep it fast or hand off to a job.
62 63 64 |
# File 'lib/livechat/configuration.rb', line 62 def @on_visitor_message end |
#rate_limit ⇒ Object
Per-IP throttle for the public endpoints, as keyword arguments for Rails' rate limiter (Rails 7.2+; ignored on 7.1). nil disables it.
66 67 68 |
# File 'lib/livechat/configuration.rb', line 66 def rate_limit @rate_limit end |
#reply_time_text ⇒ Object
Widget copy. nil uses the localized defaults. reply_time_text is the honest line under the greeting — "We usually reply within a few hours."
41 42 43 |
# File 'lib/livechat/configuration.rb', line 41 def reply_time_text @reply_time_text end |
#show_launcher ⇒ Object
The floating launcher bubble. Set false to open the widget only from
your own elements carrying data-livechat-open.
50 51 52 |
# File 'lib/livechat/configuration.rb', line 50 def show_launcher @show_launcher end |
#visitor_label ⇒ Object
Turn a resolved user into the visitor name shown in the inbox.
27 28 29 |
# File 'lib/livechat/configuration.rb', line 27 def visitor_label @visitor_label end |
Instance Method Details
#agent_email_list ⇒ Object
95 96 97 98 99 |
# File 'lib/livechat/configuration.rb', line 95 def agent_email_list list = agent_emails list = list.call if list.respond_to?(:call) Array(list).compact_blank end |
#emails_enabled? ⇒ Boolean
101 |
# File 'lib/livechat/configuration.rb', line 101 def emails_enabled? = mailer_from.present? |
#widget_endpoint ⇒ Object
93 |
# File 'lib/livechat/configuration.rb', line 93 def = "#{mount_path.chomp('/')}/widget" |