Module: Livechat
- Defined in:
- lib/livechat.rb,
lib/livechat/seeds.rb,
lib/livechat/engine.rb,
lib/livechat/widget.rb,
lib/livechat/version.rb,
lib/livechat/channels.rb,
lib/livechat/configuration.rb,
lib/livechat/notifications.rb,
lib/livechat/widget_helper.rb,
app/mailers/livechat/mailer.rb,
app/models/livechat/message.rb,
lib/livechat/attachment_policy.rb,
app/models/livechat/conversation.rb,
app/helpers/livechat/inbox_helper.rb,
app/models/livechat/application_record.rb,
lib/generators/livechat/migration_helpers.rb,
app/controllers/livechat/visitor_controller.rb,
app/controllers/livechat/widgets_controller.rb,
app/controllers/livechat/messages_controller.rb,
app/controllers/livechat/dashboard_controller.rb,
app/controllers/livechat/application_controller.rb,
app/controllers/livechat/attachments_controller.rb,
app/controllers/concerns/livechat/request_context.rb,
app/controllers/livechat/conversations_controller.rb,
lib/generators/livechat/install/install_generator.rb
Overview
Loaded from the engine only when Action Cable is present (see engine.rb), so a host without a cable never pays for it and never trips Zeitwerk eager-load on a missing ActionCable constant.
Defined Under Namespace
Modules: AttachmentPolicy, Generators, InboxHelper, Notifications, RequestContext, Seeds, Widget, WidgetHelper Classes: ApplicationController, ApplicationRecord, AttachmentsController, Configuration, Conversation, ConversationsController, DashboardController, Engine, Mailer, Message, MessagesController, StreamChannel, VisitorController, WidgetsController
Constant Summary collapse
- VERSION =
'1.0.0'
Class Method Summary collapse
-
.action_cable_enabled? ⇒ Boolean
Realtime push is opt-in and needs Action Cable loaded.
- .agent?(request) ⇒ Boolean
- .app_name ⇒ Object
-
.attachments_enabled? ⇒ Boolean
File attachments are on only when the host has Active Storage AND hasn't switched them off.
-
.base_controller ⇒ Object
Can this request work the inbox? Checked by every inbox action.
- .config ⇒ Object
- .configure {|config| ... } ⇒ Object
-
.display_name_for(agent_label) ⇒ Object
The public face of an agent message.
-
.enabled?(request) ⇒ Boolean
Can this request see the widget and write messages? Checked on the server for every widget endpoint and by the helper before rendering.
- .sign_stream(name) ⇒ Object
-
.stream_verifier ⇒ Object
Signs the Action Cable stream names handed to clients, so a subscriber can only listen to a conversation the server already let it see — the widget receives its stream token through the gated /conversation endpoint, never guessing one.
- .verify_stream(token) ⇒ Object
Class Method Details
.action_cable_enabled? ⇒ Boolean
Realtime push is opt-in and needs Action Cable loaded. Off by default: the widget and inbox poll, and only speed up when a host turns this on.
54 55 56 |
# File 'lib/livechat.rb', line 54 def action_cable_enabled? config.action_cable && defined?(ActionCable) ? true : false end |
.agent?(request) ⇒ Boolean
41 42 43 |
# File 'lib/livechat.rb', line 41 def agent?(request) !!config..call(request) end |
.app_name ⇒ Object
76 77 78 |
# File 'lib/livechat.rb', line 76 def app_name config.app_name.presence || rails_app_name end |
.attachments_enabled? ⇒ Boolean
File attachments are on only when the host has Active Storage AND hasn't switched them off. Guards every attachment path so the widget degrades to text-only rather than erroring where Active Storage is absent.
48 49 50 |
# File 'lib/livechat.rb', line 48 def config.attach_files && Message. end |
.base_controller ⇒ Object
Can this request work the inbox? Checked by every inbox action. The class Livechat::DashboardController inherits from. Resolved on every call rather than memoized, so a host that reassigns base_controller_class in a reloadable initializer is not pinned to a stale, unloaded constant.
37 38 39 |
# File 'lib/livechat.rb', line 37 def base_controller config.base_controller_class.to_s.constantize end |
.config ⇒ Object
19 20 21 |
# File 'lib/livechat.rb', line 19 def config @config ||= Configuration.new end |
.configure {|config| ... } ⇒ Object
23 24 25 |
# File 'lib/livechat.rb', line 23 def configure yield config end |
.display_name_for(agent_label) ⇒ Object
The public face of an agent message. Blank display names fall back to a localized "Support", so visitors always see a sender.
82 83 84 85 |
# File 'lib/livechat.rb', line 82 def display_name_for(agent_label) name = config.agent_display_name.call(agent_label).presence name || I18n.t(:team, scope: :livechat, default: 'Support') end |
.enabled?(request) ⇒ Boolean
Can this request see the widget and write messages? Checked on the server for every widget endpoint and by the helper before rendering.
29 30 31 |
# File 'lib/livechat.rb', line 29 def enabled?(request) !!config.enabled.call(request) end |
.sign_stream(name) ⇒ Object
66 67 68 |
# File 'lib/livechat.rb', line 66 def sign_stream(name) stream_verifier.generate(name.to_s) end |
.stream_verifier ⇒ Object
Signs the Action Cable stream names handed to clients, so a subscriber can only listen to a conversation the server already let it see — the widget receives its stream token through the gated /conversation endpoint, never guessing one. Same idea as Turbo's signed streams.
62 63 64 |
# File 'lib/livechat.rb', line 62 def stream_verifier @stream_verifier ||= Rails.application.('livechat/stream') end |
.verify_stream(token) ⇒ Object
70 71 72 73 74 |
# File 'lib/livechat.rb', line 70 def verify_stream(token) stream_verifier.verify(token.to_s) rescue StandardError nil end |