Module: Livechat::Notifications

Defined in:
lib/livechat/notifications.rb

Overview

Fires the host hooks and the built-in emails after a message is saved. Email goes out only at the start of an unread stretch — the first message nobody has seen yet — so a burst of messages is one email, not ten. A failing hook must never break the chat, so hooks are rescued and logged.

Class Method Summary collapse

Class Method Details

.agent_message(message) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/livechat/notifications.rb', line 19

def agent_message(message)
  run_hook { Livechat.config.on_agent_message.call(message) }
  return unless Livechat.config.emails_enabled?
  return if message.conversation.visitor_email.blank?
  return unless first_unread?(message, message.conversation.messages.from_agent)

  Mailer.new_agent_reply(message).deliver_later
end

.visitor_message(message) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/livechat/notifications.rb', line 10

def visitor_message(message)
  run_hook { Livechat.config.on_visitor_message.call(message) }
  return unless Livechat.config.emails_enabled?
  return unless Livechat.config.agent_email_list.any?
  return unless first_unread?(message, message.conversation.messages.from_visitor)

  Mailer.new_visitor_message(message).deliver_later
end