Feature: Rich Message Types (#610)
Co-authored-by: Pranav Raj S <pranavrajs@gmail.com> Co-authored-by: Nithin David Thomas <webofnithin@gmail.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
class Api::V1::Accounts::ConversationsController < Api::BaseController
|
||||
before_action :conversation, except: [:index]
|
||||
before_action :contact_inbox, only: [:create]
|
||||
|
||||
def index
|
||||
result = conversation_finder.perform
|
||||
@@ -7,6 +8,10 @@ class Api::V1::Accounts::ConversationsController < Api::BaseController
|
||||
@conversations_count = result[:count]
|
||||
end
|
||||
|
||||
def create
|
||||
@conversation = ::Conversation.create!(conversation_params)
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def toggle_status
|
||||
@@ -29,6 +34,19 @@ class Api::V1::Accounts::ConversationsController < Api::BaseController
|
||||
@conversation ||= current_account.conversations.find_by(display_id: params[:id])
|
||||
end
|
||||
|
||||
def contact_inbox
|
||||
@contact_inbox ||= ::ContactInbox.find_by!(source_id: params[:source_id])
|
||||
end
|
||||
|
||||
def conversation_params
|
||||
{
|
||||
account_id: current_account.id,
|
||||
inbox_id: @contact_inbox.inbox_id,
|
||||
contact_id: @contact_inbox.contact_id,
|
||||
contact_inbox_id: @contact_inbox.id
|
||||
}
|
||||
end
|
||||
|
||||
def conversation_finder
|
||||
@conversation_finder ||= ConversationFinder.new(current_user, params)
|
||||
end
|
||||
|
||||
@@ -2,9 +2,9 @@ class Api::V1::Widget::BaseController < ApplicationController
|
||||
private
|
||||
|
||||
def conversation
|
||||
@conversation ||= @contact_inbox.conversations.find_by(
|
||||
@conversation ||= @contact_inbox.conversations.where(
|
||||
inbox_id: auth_token_params[:inbox_id]
|
||||
)
|
||||
).last
|
||||
end
|
||||
|
||||
def auth_token_params
|
||||
|
||||
16
app/controllers/api/v1/widget/events_controller.rb
Normal file
16
app/controllers/api/v1/widget/events_controller.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class Api::V1::Widget::EventsController < Api::V1::Widget::BaseController
|
||||
include Events::Types
|
||||
before_action :set_web_widget
|
||||
before_action :set_contact
|
||||
|
||||
def create
|
||||
Rails.configuration.dispatcher.dispatch(permitted_params[:name], Time.zone.now, contact_inbox: @contact_inbox)
|
||||
head :no_content
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def permitted_params
|
||||
params.permit(:name, :website_token)
|
||||
end
|
||||
end
|
||||
@@ -15,8 +15,12 @@ class Api::V1::Widget::MessagesController < Api::V1::Widget::BaseController
|
||||
end
|
||||
|
||||
def update
|
||||
@message.update!(input_submitted_email: contact_email)
|
||||
update_contact(contact_email)
|
||||
if @message.content_type == 'input_email'
|
||||
@message.update!(submitted_email: contact_email)
|
||||
update_contact(contact_email)
|
||||
else
|
||||
@message.update!(message_update_params[:message])
|
||||
end
|
||||
rescue StandardError => e
|
||||
render json: { error: @contact.errors, message: e.message }.to_json, status: 500
|
||||
end
|
||||
@@ -116,6 +120,10 @@ class Api::V1::Widget::MessagesController < Api::V1::Widget::BaseController
|
||||
contact_email.split('@')[0]
|
||||
end
|
||||
|
||||
def message_update_params
|
||||
params.permit(message: [submitted_values: [:name, :title, :value]])
|
||||
end
|
||||
|
||||
def permitted_params
|
||||
params.permit(:id, :before, :website_token, contact: [:email], message: [:content, :referer_url, :timestamp])
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user