Class: InstagramConnect::MessagesController

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

Overview

Composes an outbound reply in a thread and hands it to the send job.

Instance Method Summary collapse

Instance Method Details

#createObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/instagram_connect/messages_controller.rb', line 4

def create
  conversation = Conversation.find(params[:conversation_id])

  if params[:body].to_s.strip.empty?
    return redirect_to conversation_path(conversation), alert: "Message can't be blank."
  end

  message = conversation.messages.create!(
    direction: "outbound", status: "pending", kind: "dm", source: "manual",
    body: params[:body], sent_by_id: instagram_connect_user_id
  )
  SendMessageJob.perform_later(message.id)
  redirect_to conversation_path(conversation), notice: "Reply queued."
end