diff --git a/app/controllers/api/v1/widget/conversations_controller.rb b/app/controllers/api/v1/widget/conversations_controller.rb index 2c72a0361..431ffe2d5 100644 --- a/app/controllers/api/v1/widget/conversations_controller.rb +++ b/app/controllers/api/v1/widget/conversations_controller.rb @@ -1,5 +1,6 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController include Events::Types + before_action :render_not_found_if_empty, only: [:toggle_typing, :toggle_status, :set_custom_attributes, :destroy_custom_attributes] def index @conversation = conversation @@ -41,8 +42,6 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController end def toggle_typing - head :ok && return if conversation.nil? - case permitted_params[:typing_status] when 'on' trigger_typing_event(CONVERSATION_TYPING_ON) @@ -54,8 +53,6 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController end def toggle_status - return head :not_found if conversation.nil? - return head :forbidden unless @web_widget.end_conversation? unless conversation.resolved? @@ -81,6 +78,10 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController Rails.configuration.dispatcher.dispatch(event, Time.zone.now, conversation: conversation, user: @contact) end + def render_not_found_if_empty + return head :not_found if conversation.nil? + end + def permitted_params params.permit(:id, :typing_status, :website_token, :email, contact: [:name, :email, :phone_number], message: [:content, :referer_url, :timestamp, :echo_id],