diff --git a/app/javascript/dashboard/components/widgets/conversation/bubble/Text.vue b/app/javascript/dashboard/components/widgets/conversation/bubble/Text.vue
index 1a8c44a6f..2ffa700cb 100644
--- a/app/javascript/dashboard/components/widgets/conversation/bubble/Text.vue
+++ b/app/javascript/dashboard/components/widgets/conversation/bubble/Text.vue
@@ -1,7 +1,7 @@
-
+
-
+
@@ -213,6 +223,10 @@ export default {
.has-attachment {
padding: 0;
overflow: hidden;
+
+ &.has-text {
+ margin-top: $space-smaller;
+ }
}
.agent-message-wrap {
diff --git a/app/javascript/widget/views/Unread.vue b/app/javascript/widget/views/Unread.vue
index fcedad401..70e9c26b3 100644
--- a/app/javascript/widget/views/Unread.vue
+++ b/app/javascript/widget/views/Unread.vue
@@ -15,7 +15,7 @@
v-for="message in unreadMessages"
:key="message.id"
:message-id="message.id"
- :message="message.content"
+ :message="getMessageContent(message)"
/>
@@ -88,6 +88,16 @@ export default {
});
}
},
+ getMessageContent(message) {
+ const { attachments, content } = message;
+ const hasAttachments = attachments && attachments.length;
+
+ if (content) return content;
+
+ if (hasAttachments) return `📑`;
+
+ return '';
+ },
},
};
diff --git a/app/services/facebook/send_on_facebook_service.rb b/app/services/facebook/send_on_facebook_service.rb
index fdb6d1069..b8102c6fa 100644
--- a/app/services/facebook/send_on_facebook_service.rb
+++ b/app/services/facebook/send_on_facebook_service.rb
@@ -6,13 +6,18 @@ class Facebook::SendOnFacebookService < Base::SendOnChannelService
end
def perform_reply
- result = FacebookBot::Bot.deliver(delivery_params, access_token: message.channel_token)
- message.update!(source_id: JSON.parse(result)['message_id'])
+ send_message_to_facebook fb_text_message_params if message.content.present?
+ send_message_to_facebook fb_attachment_message_params if message.attachments.present?
rescue Facebook::Messenger::FacebookError => e
Rails.logger.info e
channel.authorization_error!
end
+ def send_message_to_facebook(delivery_params)
+ result = FacebookBot::Bot.deliver(delivery_params, access_token: message.channel_token)
+ message.update!(source_id: JSON.parse(result)['message_id'])
+ end
+
def fb_text_message_params
{
recipient: { id: contact.get_source_id(inbox.id) },
@@ -49,29 +54,6 @@ class Facebook::SendOnFacebookService < Base::SendOnChannelService
end
end
- def delivery_params
- if twenty_four_hour_window_over?
- fb_message_params.merge(tag: 'ISSUE_RESOLUTION')
- else
- fb_message_params
- end
- end
-
- def twenty_four_hour_window_over?
- return false unless after_24_hours?
- return false if last_incoming_and_outgoing_message_after_one_day?
-
- true
- end
-
- def last_incoming_and_outgoing_message_after_one_day?
- last_incoming_message && sent_first_outgoing_message_after_24_hours?
- end
-
- def after_24_hours?
- (Time.current - last_incoming_message.created_at) / 3600 >= 24
- end
-
def sent_first_outgoing_message_after_24_hours?
# we can send max 1 message after 24 hour window
conversation.messages.outgoing.where('id > ?', last_incoming_message.id).count == 1
diff --git a/spec/services/facebook/send_on_facebook_service_spec.rb b/spec/services/facebook/send_on_facebook_service_spec.rb
index a972a8973..e84319a26 100644
--- a/spec/services/facebook/send_on_facebook_service_spec.rb
+++ b/spec/services/facebook/send_on_facebook_service_spec.rb
@@ -58,7 +58,21 @@ describe Facebook::SendOnFacebookService do
attachment.file.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png')
message.save!
::Facebook::SendOnFacebookService.new(message: message).perform
- expect(bot).to have_received(:deliver)
+ expect(bot).to have_received(:deliver).with({
+ recipient: { id: contact_inbox.source_id },
+ message: { text: message.content }
+ }, { access_token: facebook_channel.page_access_token })
+ expect(bot).to have_received(:deliver).with({
+ recipient: { id: contact_inbox.source_id },
+ message: {
+ attachment: {
+ type: 'image',
+ payload: {
+ url: attachment.file_url
+ }
+ }
+ }
+ }, { access_token: facebook_channel.page_access_token })
end
end
end