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.
-
#action_cable ⇒ Object
Push new messages over Action Cable instead of waiting for the next poll.
-
#action_cable_url ⇒ Object
Where the host mounts Action Cable.
-
#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.
-
#allowed_attachment_types ⇒ Object
Cap on attachments per message, on the size of each file (bytes), and an optional content-type allowlist (nil accepts any type).
-
#app_name ⇒ Object
Shown in the widget header and in notification emails.
-
#attach_files ⇒ Object
Let visitors and agents attach files to messages.
-
#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.
-
#max_attachment_size ⇒ Object
Cap on attachments per message, on the size of each file (bytes), and an optional content-type allowlist (nil accepts any type).
-
#max_attachments ⇒ Object
Cap on attachments per message, on the size of each file (bytes), and an optional content-type allowlist (nil accepts any type).
-
#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.
-
#storage_service ⇒ Object
Named Active Storage service for chat attachments.
-
#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.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/livechat/configuration.rb', line 99 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' @attach_files = true @storage_service = nil @max_attachments = 5 @max_attachment_size = 10 * 1024 * 1024 @allowed_attachment_types = nil @action_cable = false @action_cable_url = '/cable' 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 |
#action_cable ⇒ Object
Push new messages over Action Cable instead of waiting for the next
poll. Opt-in and off by default: polling stays the transport, so a
host that never mounts a cable keeps working; when on (and Action Cable
is present) a new message nudges the widget and the inbox to refresh at
once. Requires /cable mounted in the host's routes.
89 90 91 |
# File 'lib/livechat/configuration.rb', line 89 def action_cable @action_cable end |
#action_cable_url ⇒ Object
Where the host mounts Action Cable. Only consulted when action_cable is
on. Keep in sync with the mount ActionCable... => "/cable" in routes.
93 94 95 |
# File 'lib/livechat/configuration.rb', line 93 def action_cable_url @action_cable_url 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 |
#allowed_attachment_types ⇒ Object
Cap on attachments per message, on the size of each file (bytes), and an optional content-type allowlist (nil accepts any type). Enforced on the server; a rejected upload comes back as a validation error.
82 83 84 |
# File 'lib/livechat/configuration.rb', line 82 def @allowed_attachment_types 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 |
#attach_files ⇒ Object
Let visitors and agents attach files to messages. Requires Active Storage in the host app (rails active_storage:install); silently ignored when it isn't present, so the widget keeps working. Set false to turn attachments off even where Active Storage exists.
72 73 74 |
# File 'lib/livechat/configuration.rb', line 72 def attach_files @attach_files 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 |
#max_attachment_size ⇒ Object
Cap on attachments per message, on the size of each file (bytes), and an optional content-type allowlist (nil accepts any type). Enforced on the server; a rejected upload comes back as a validation error.
82 83 84 |
# File 'lib/livechat/configuration.rb', line 82 def @max_attachment_size end |
#max_attachments ⇒ Object
Cap on attachments per message, on the size of each file (bytes), and an optional content-type allowlist (nil accepts any type). Enforced on the server; a rejected upload comes back as a validation error.
82 83 84 |
# File 'lib/livechat/configuration.rb', line 82 def @max_attachments 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.
97 98 99 |
# File 'lib/livechat/configuration.rb', line 97 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 |
#storage_service ⇒ Object
Named Active Storage service for chat attachments. nil uses the host app's default service; set this to route files to a dedicated bucket, folder, or provider-specific service entry.
77 78 79 |
# File 'lib/livechat/configuration.rb', line 77 def storage_service @storage_service 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
129 130 131 132 133 |
# File 'lib/livechat/configuration.rb', line 129 def agent_email_list list = agent_emails list = list.call if list.respond_to?(:call) Array(list).compact_blank end |
#emails_enabled? ⇒ Boolean
135 |
# File 'lib/livechat/configuration.rb', line 135 def emails_enabled? = mailer_from.present? |
#widget_endpoint ⇒ Object
127 |
# File 'lib/livechat/configuration.rb', line 127 def = "#{mount_path.chomp('/')}/widget" |