Class: Livechat::MessagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/livechat/messages_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/livechat/messages_controller.rb', line 7

def create
  conversation = Conversation.find(params[:conversation_id])
  message = conversation.post_agent_message!(
    body: params[:body].to_s.strip,
    agent_id: current_agent_id,
    agent_label: current_agent_label,
    files: params[:files]
  )
  Notifications.agent_message(message)

  redirect_to conversation_path(conversation, anchor: "message-#{message.id}")
rescue ActiveRecord::RecordInvalid => e
  redirect_to conversation_path(conversation), alert: e.record.errors.full_messages.first
end