Module: Livechat
- Defined in:
- lib/livechat.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,
app/mailers/livechat/mailer.rb,
app/models/livechat/message.rb,
app/models/livechat/conversation.rb,
app/helpers/livechat/inbox_helper.rb,
app/helpers/livechat/widget_helper.rb,
app/models/livechat/application_record.rb,
app/controllers/livechat/visitor_controller.rb,
app/controllers/livechat/widgets_controller.rb,
app/controllers/livechat/messages_controller.rb,
app/controllers/livechat/application_controller.rb,
app/controllers/livechat/attachments_controller.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: Generators, InboxHelper, Notifications, Widget, WidgetHelper Classes: ApplicationController, ApplicationRecord, AttachmentsController, Configuration, Conversation, ConversationsController, Engine, Mailer, Message, MessagesController, StreamChannel, VisitorController, WidgetsController
Constant Summary collapse
- VERSION =
'0.4.2'
Class Method Summary collapse
-
.action_cable_enabled? ⇒ Boolean
Realtime push is opt-in and needs Action Cable loaded.
-
.agent?(request) ⇒ Boolean
Can this request work the inbox? Checked by every inbox action.
- .app_name ⇒ Object
-
.attachments_enabled? ⇒ Boolean
File attachments are on only when the host has Active Storage AND hasn't switched them off.
- .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.
44 45 46 |
# File 'lib/livechat.rb', line 44 def action_cable_enabled? config.action_cable && defined?(ActionCable) ? true : false end |
.agent?(request) ⇒ Boolean
Can this request work the inbox? Checked by every inbox action.
31 32 33 |
# File 'lib/livechat.rb', line 31 def agent?(request) !!config..call(request) end |
.app_name ⇒ Object
66 67 68 |
# File 'lib/livechat.rb', line 66 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.
38 39 40 |
# File 'lib/livechat.rb', line 38 def config.attach_files && Message. end |
.config ⇒ Object
16 17 18 |
# File 'lib/livechat.rb', line 16 def config @config ||= Configuration.new end |
.configure {|config| ... } ⇒ Object
20 21 22 |
# File 'lib/livechat.rb', line 20 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.
72 73 74 75 |
# File 'lib/livechat.rb', line 72 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.
26 27 28 |
# File 'lib/livechat.rb', line 26 def enabled?(request) !!config.enabled.call(request) end |
.sign_stream(name) ⇒ Object
56 57 58 |
# File 'lib/livechat.rb', line 56 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.
52 53 54 |
# File 'lib/livechat.rb', line 52 def stream_verifier @stream_verifier ||= Rails.application.('livechat/stream') end |
.verify_stream(token) ⇒ Object
60 61 62 63 64 |
# File 'lib/livechat.rb', line 60 def verify_stream(token) stream_verifier.verify(token.to_s) rescue StandardError nil end |