From c5915203fc541b7af55750c041df1666fc6be794 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Thu, 23 Nov 2023 17:30:36 +0530 Subject: [PATCH] add line image --- .../widgets/conversation/ReplyBox.vue | 3 ++- app/services/line/send_on_line_service.rb | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue index 3712a08e6..e18e1c0e2 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue @@ -392,7 +392,8 @@ export default { this.isAPIInbox || this.isAnEmailChannel || this.isASmsInbox || - this.isATelegramChannel + this.isATelegramChannel || + this.isALineChannel ); }, replyButtonLabel() { diff --git a/app/services/line/send_on_line_service.rb b/app/services/line/send_on_line_service.rb index a30de4ab4..217b0fa34 100644 --- a/app/services/line/send_on_line_service.rb +++ b/app/services/line/send_on_line_service.rb @@ -6,7 +6,14 @@ class Line::SendOnLineService < Base::SendOnChannelService end def perform_reply - response = channel.client.push_message(message.conversation.contact_inbox.source_id, [{ type: 'text', text: message.content }]) + byebug + payload = if message.attachment? + build_attachment_payload + else + [{ type: 'text', text: message.content }] + end + + response = channel.client.push_message(message.conversation.contact_inbox.source_id, payload) return if response.blank? parsed_json = JSON.parse(response.body) @@ -20,6 +27,16 @@ class Line::SendOnLineService < Base::SendOnChannelService end end + def build_attachment_payload + case message.attachment_type + when 'image' + [{ type: 'image', originalContentUrl: message.attachment_url, previewImageUrl: message.attachment_url }] + # Add more cases for other types of attachments like 'video', 'audio', etc. + else + [{ type: 'text', text: "Unsupported attachment type: #{message.attachment_type}" }] + end + end + # https://developers.line.biz/en/reference/messaging-api/#error-responses def external_error(error) # Message containing information about the error. See https://developers.line.biz/en/reference/messaging-api/#error-messages