From d94108bf3fc20454236250e84dda1d1c4a988857 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Fri, 27 Oct 2023 13:35:02 +0530 Subject: [PATCH] feat: show ReplyTo in widget UI (#8094) Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: Muhsin Keloth --- .../api/v1/widget/base_controller.rb | 3 + .../api/v1/widget/messages_controller.rb | 2 +- .../widgets/conversation/bubble/ReplyTo.vue | 2 +- .../shared/components/FluentIcon/icons.json | 1 + app/javascript/widget/api/conversation.js | 8 +- app/javascript/widget/api/endPoints.js | 6 +- .../widget/components/AgentMessage.vue | 91 ++++++++++++------ .../widget/components/ChatFooter.vue | 44 ++++++++- .../widget/components/ChatInputWrap.vue | 4 +- .../widget/components/ChatMessage.vue | 22 ++++- .../widget/components/DragWrapper.vue | 55 +++++++++++ .../widget/components/FooterReplyTo.vue | 41 ++++++++ .../widget/components/MessageReplyButton.vue | 17 ++++ .../widget/components/ReplyToChip.vue | 51 ++++++++++ .../widget/components/UserMessage.vue | 93 +++++++++++++------ .../store/modules/conversation/actions.js | 10 +- .../store/modules/conversation/helpers.js | 3 +- .../specs/conversation/actions.spec.js | 12 ++- .../specs/conversation/helpers.spec.js | 9 ++ app/javascript/widget/views/Messages.vue | 4 +- .../v1/widget/messages/create.json.jbuilder | 1 + .../api/v1/widget/messages_controller_spec.rb | 29 ++++++ 22 files changed, 426 insertions(+), 82 deletions(-) create mode 100644 app/javascript/widget/components/DragWrapper.vue create mode 100644 app/javascript/widget/components/FooterReplyTo.vue create mode 100644 app/javascript/widget/components/MessageReplyButton.vue create mode 100644 app/javascript/widget/components/ReplyToChip.vue 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 @@