diff --git a/app/controllers/api/v1/widget/base_controller.rb b/app/controllers/api/v1/widget/base_controller.rb index 229cf27e9..5b87e2d1a 100644 --- a/app/controllers/api/v1/widget/base_controller.rb +++ b/app/controllers/api/v1/widget/base_controller.rb @@ -79,6 +79,9 @@ class Api::V1::Widget::BaseController < ApplicationController sender: @contact, content: permitted_params[:message][:content], inbox_id: conversation.inbox_id, + content_attributes: { + in_reply_to: permitted_params[:message][:reply_to] + }, echo_id: permitted_params[:message][:echo_id], message_type: :incoming } diff --git a/app/controllers/api/v1/widget/messages_controller.rb b/app/controllers/api/v1/widget/messages_controller.rb index 306a5f46f..a51b4c2d6 100644 --- a/app/controllers/api/v1/widget/messages_controller.rb +++ b/app/controllers/api/v1/widget/messages_controller.rb @@ -64,7 +64,7 @@ class Api::V1::Widget::MessagesController < Api::V1::Widget::BaseController def permitted_params # timestamp parameter is used in create conversation method - params.permit(:id, :before, :after, :website_token, contact: [:name, :email], message: [:content, :referer_url, :timestamp, :echo_id]) + params.permit(:id, :before, :after, :website_token, contact: [:name, :email], message: [:content, :referer_url, :timestamp, :echo_id, :reply_to]) end def set_message diff --git a/app/javascript/dashboard/components/widgets/conversation/bubble/ReplyTo.vue b/app/javascript/dashboard/components/widgets/conversation/bubble/ReplyTo.vue index 7bc4d5156..754c79954 100644 --- a/app/javascript/dashboard/components/widgets/conversation/bubble/ReplyTo.vue +++ b/app/javascript/dashboard/components/widgets/conversation/bubble/ReplyTo.vue @@ -2,7 +2,7 @@
{ return API.post(urlData.url, urlData.params); }; -const sendMessageAPI = async content => { - const urlData = endPoints.sendMessage(content); +const sendMessageAPI = async (content, replyTo = null) => { + const urlData = endPoints.sendMessage(content, replyTo); return API.post(urlData.url, urlData.params); }; -const sendAttachmentAPI = async attachment => { - const urlData = endPoints.sendAttachment(attachment); +const sendAttachmentAPI = async (attachment, replyTo = null) => { + const urlData = endPoints.sendAttachment(attachment, replyTo); return API.post(urlData.url, urlData.params); }; diff --git a/app/javascript/widget/api/endPoints.js b/app/javascript/widget/api/endPoints.js index 646370c05..8ede38056 100755 --- a/app/javascript/widget/api/endPoints.js +++ b/app/javascript/widget/api/endPoints.js @@ -22,7 +22,7 @@ const createConversation = params => { }; }; -const sendMessage = content => { +const sendMessage = (content, replyTo) => { const referrerURL = window.referrerURL || ''; const search = buildSearchParamsWithLocale(window.location.search); return { @@ -30,6 +30,7 @@ const sendMessage = content => { params: { message: { content, + reply_to: replyTo, timestamp: new Date().toString(), referer_url: referrerURL, }, @@ -37,7 +38,7 @@ const sendMessage = content => { }; }; -const sendAttachment = ({ attachment }) => { +const sendAttachment = ({ attachment, replyTo = null }) => { const { referrerURL = '' } = window; const timestamp = new Date().toString(); const { file } = attachment; @@ -51,6 +52,7 @@ const sendAttachment = ({ attachment }) => { formData.append('message[referer_url]', referrerURL); formData.append('message[timestamp]', timestamp); + formData.append('message[reply_to]', replyTo); return { url: `/api/v1/widget/messages${window.location.search}`, params: formData, diff --git a/app/javascript/widget/components/AgentMessage.vue b/app/javascript/widget/components/AgentMessage.vue index 6b9609a6b..6020af3dc 100755 --- a/app/javascript/widget/components/AgentMessage.vue +++ b/app/javascript/widget/components/AgentMessage.vue @@ -1,7 +1,9 @@