fix: Dig params in widget contact end point (#4516)
This commit is contained in:
@@ -71,7 +71,7 @@ class Api::V1::Widget::BaseController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def contact_email
|
def contact_email
|
||||||
permitted_params[:contact][:email].downcase if permitted_params[:contact].present?
|
permitted_params.dig(:contact, :email)&.downcase
|
||||||
end
|
end
|
||||||
|
|
||||||
def contact_name
|
def contact_name
|
||||||
@@ -79,7 +79,7 @@ class Api::V1::Widget::BaseController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def contact_phone_number
|
def contact_phone_number
|
||||||
params[:contact][:phone_number]
|
permitted_params.dig(:contact, :phone_number)
|
||||||
end
|
end
|
||||||
|
|
||||||
def browser_params
|
def browser_params
|
||||||
|
|||||||
@@ -69,7 +69,8 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def permitted_params
|
def permitted_params
|
||||||
params.permit(:id, :typing_status, :website_token, :email, contact: [:name, :email], message: [:content, :referer_url, :timestamp, :echo_id],
|
params.permit(:id, :typing_status, :website_token, :email, contact: [:name, :email, :phone_number],
|
||||||
|
message: [:content, :referer_url, :timestamp, :echo_id],
|
||||||
custom_attributes: {})
|
custom_attributes: {})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class MessageTemplates::HookExecutionService
|
|||||||
|
|
||||||
# TODO: we should be able to reduce this logic once we have a toggle for email collect messages
|
# TODO: we should be able to reduce this logic once we have a toggle for email collect messages
|
||||||
def should_send_email_collect?
|
def should_send_email_collect?
|
||||||
!contact_has_email? && inbox.web_widget? && !inbox.channel.pre_chat_form_enabled? && !email_collect_was_sent?
|
!contact_has_email? && inbox.web_widget? && !email_collect_was_sent?
|
||||||
end
|
end
|
||||||
|
|
||||||
def contact_has_email?
|
def contact_has_email?
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do
|
|||||||
headers: { 'X-Auth-Token' => token },
|
headers: { 'X-Auth-Token' => token },
|
||||||
as: :json
|
as: :json
|
||||||
|
|
||||||
expect(response).to have_http_status(:internal_server_error)
|
expect(response).to have_http_status(:success)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -62,20 +62,6 @@ describe ::MessageTemplates::HookExecutionService do
|
|||||||
expect(email_collect_service).to have_received(:perform)
|
expect(email_collect_service).to have_received(:perform)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'doesnot calls ::MessageTemplates::Template::EmailCollect when prechat form is enabled' do
|
|
||||||
contact = create(:contact, email: nil)
|
|
||||||
conversation = create(:conversation, contact: contact)
|
|
||||||
|
|
||||||
# ensure prechat form is enabled
|
|
||||||
conversation.inbox.channel.update(pre_chat_form_enabled: true)
|
|
||||||
allow(::MessageTemplates::Template::EmailCollect).to receive(:new).and_return(true)
|
|
||||||
|
|
||||||
# described class gets called in message after commit
|
|
||||||
message = create(:message, conversation: conversation)
|
|
||||||
|
|
||||||
expect(::MessageTemplates::Template::EmailCollect).not_to have_received(:new).with(conversation: message.conversation)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'doesnot calls ::MessageTemplates::Template::EmailCollect on campaign conversations' do
|
it 'doesnot calls ::MessageTemplates::Template::EmailCollect on campaign conversations' do
|
||||||
contact = create(:contact, email: nil)
|
contact = create(:contact, email: nil)
|
||||||
conversation = create(:conversation, contact: contact, campaign: create(:campaign))
|
conversation = create(:conversation, contact: contact, campaign: create(:campaign))
|
||||||
|
|||||||
Reference in New Issue
Block a user