Feature: Support file type messages on widget and dashboard (#659)
- Adds support for file upload Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com> Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
committed by
GitHub
parent
0afa5c297f
commit
7fcd2d0e85
@@ -10,12 +10,8 @@ class Api::V1::Widget::MessagesController < Api::V1::Widget::BaseController
|
||||
|
||||
def create
|
||||
@message = conversation.messages.new(message_params)
|
||||
build_attachment
|
||||
@message.save!
|
||||
if params[:message][:attachment].present?
|
||||
@message.attachment = Attachment.new(account_id: @message.account_id)
|
||||
@message.attachment.file.attach(params[:message][:attachment][:file])
|
||||
end
|
||||
render json: @message
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -28,6 +24,16 @@ class Api::V1::Widget::MessagesController < Api::V1::Widget::BaseController
|
||||
|
||||
private
|
||||
|
||||
def build_attachment
|
||||
return if params[:message][:attachment].blank?
|
||||
|
||||
@message.attachment = Attachment.new(
|
||||
account_id: @message.account_id,
|
||||
file_type: helpers.file_type(params[:message][:attachment][:file]&.content_type)
|
||||
)
|
||||
@message.attachment.file.attach(params[:message][:attachment][:file])
|
||||
end
|
||||
|
||||
def set_conversation
|
||||
@conversation = ::Conversation.create!(conversation_params) if conversation.nil?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user