mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-03 04:27:53 +00:00
feat: allow instagram reply_to [CW-2609] (#8248)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -76,6 +76,10 @@ class Messages::Instagram::MessageBuilder < Messages::Messenger::MessageBuilder
|
|||||||
message[:reply_to][:story] if message[:reply_to].present? && message[:reply_to][:story].present?
|
message[:reply_to][:story] if message[:reply_to].present? && message[:reply_to][:story].present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def message_reply_attributes
|
||||||
|
message[:reply_to][:mid] if message[:reply_to].present? && message[:reply_to][:mid].present?
|
||||||
|
end
|
||||||
|
|
||||||
def build_message
|
def build_message
|
||||||
return if @outgoing_echo && already_sent_from_chatwoot?
|
return if @outgoing_echo && already_sent_from_chatwoot?
|
||||||
return if message_content.blank? && all_unsupported_files?
|
return if message_content.blank? && all_unsupported_files?
|
||||||
@@ -118,7 +122,10 @@ class Messages::Instagram::MessageBuilder < Messages::Messenger::MessageBuilder
|
|||||||
message_type: message_type,
|
message_type: message_type,
|
||||||
source_id: message_identifier,
|
source_id: message_identifier,
|
||||||
content: message_content,
|
content: message_content,
|
||||||
sender: @outgoing_echo ? nil : contact
|
sender: @outgoing_echo ? nil : contact,
|
||||||
|
content_attributes: {
|
||||||
|
in_reply_to_external_id: message_reply_attributes
|
||||||
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
/>
|
/>
|
||||||
<instagram-story-reply v-if="storyUrl" :story-url="storyUrl" />
|
<instagram-story-reply v-if="storyUrl" :story-url="storyUrl" />
|
||||||
<bubble-reply-to
|
<bubble-reply-to
|
||||||
v-if="inReplyToMessageId && inboxSupportsReplyTo"
|
v-if="inReplyToMessageId && inboxSupportsReplyTo.incoming"
|
||||||
:message="inReplyTo"
|
:message="inReplyTo"
|
||||||
:message-type="data.message_type"
|
:message-type="data.message_type"
|
||||||
:parent-has-attachments="hasAttachments"
|
:parent-has-attachments="hasAttachments"
|
||||||
@@ -184,8 +184,8 @@ export default {
|
|||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
inboxSupportsReplyTo: {
|
inboxSupportsReplyTo: {
|
||||||
type: Boolean,
|
type: Object,
|
||||||
default: false,
|
default: () => ({}),
|
||||||
},
|
},
|
||||||
inReplyTo: {
|
inReplyTo: {
|
||||||
type: Object,
|
type: Object,
|
||||||
@@ -281,7 +281,7 @@ export default {
|
|||||||
copy: this.hasText,
|
copy: this.hasText,
|
||||||
delete: this.hasText || this.hasAttachments,
|
delete: this.hasText || this.hasAttachments,
|
||||||
cannedResponse: this.isOutgoing && this.hasText,
|
cannedResponse: this.isOutgoing && this.hasText,
|
||||||
replyTo: !this.data.private && this.inboxSupportsReplyTo,
|
replyTo: !this.data.private && this.inboxSupportsReplyTo.outgoing,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
contentAttributes() {
|
contentAttributes() {
|
||||||
|
|||||||
@@ -285,13 +285,18 @@ export default {
|
|||||||
return this.currentChat.unread_count || 0;
|
return this.currentChat.unread_count || 0;
|
||||||
},
|
},
|
||||||
inboxSupportsReplyTo() {
|
inboxSupportsReplyTo() {
|
||||||
return (
|
if (
|
||||||
this.inboxHasFeature(INBOX_FEATURES.REPLY_TO_OUTGOING) &&
|
!this.isFeatureEnabledonAccount(
|
||||||
this.isFeatureEnabledonAccount(
|
|
||||||
this.accountId,
|
this.accountId,
|
||||||
FEATURE_FLAGS.MESSAGE_REPLY_TO
|
FEATURE_FLAGS.MESSAGE_REPLY_TO
|
||||||
)
|
)
|
||||||
);
|
) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
incoming: this.inboxHasFeature(INBOX_FEATURES.REPLY_TO),
|
||||||
|
outgoing: this.inboxHasFeature(INBOX_FEATURES.REPLY_TO_OUTGOING),
|
||||||
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ describe Messages::Instagram::MessageBuilder do
|
|||||||
let!(:dm_params) { build(:instagram_message_create_event).with_indifferent_access }
|
let!(:dm_params) { build(:instagram_message_create_event).with_indifferent_access }
|
||||||
let!(:story_mention_params) { build(:instagram_story_mention_event).with_indifferent_access }
|
let!(:story_mention_params) { build(:instagram_story_mention_event).with_indifferent_access }
|
||||||
let!(:instagram_story_reply_event) { build(:instagram_story_reply_event).with_indifferent_access }
|
let!(:instagram_story_reply_event) { build(:instagram_story_reply_event).with_indifferent_access }
|
||||||
|
let!(:instagram_message_reply_event) { build(:instagram_message_reply_event).with_indifferent_access }
|
||||||
let(:fb_object) { double }
|
let(:fb_object) { double }
|
||||||
let(:contact) { create(:contact, id: 'Sender-id-1', name: 'Jane Dae') }
|
let(:contact) { create(:contact, id: 'Sender-id-1', name: 'Jane Dae') }
|
||||||
let(:contact_inbox) { create(:contact_inbox, contact_id: contact.id, inbox_id: instagram_inbox.id, source_id: 'Sender-id-1') }
|
let(:contact_inbox) { create(:contact_inbox, contact_id: contact.id, inbox_id: instagram_inbox.id, source_id: 'Sender-id-1') }
|
||||||
@@ -101,6 +102,34 @@ describe Messages::Instagram::MessageBuilder do
|
|||||||
expect(message.content_attributes[:story_url]).to eq('https://chatwoot-assets.local/sample.png')
|
expect(message.content_attributes[:story_url]).to eq('https://chatwoot-assets.local/sample.png')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'creates message with for reply with mid' do
|
||||||
|
allow(Koala::Facebook::API).to receive(:new).and_return(fb_object)
|
||||||
|
allow(fb_object).to receive(:get_object).and_return(
|
||||||
|
{
|
||||||
|
name: 'Jane',
|
||||||
|
id: 'Sender-id-1',
|
||||||
|
account_id: instagram_inbox.account_id,
|
||||||
|
profile_pic: 'https://chatwoot-assets.local/sample.png'
|
||||||
|
}.with_indifferent_access
|
||||||
|
)
|
||||||
|
# create first message to ensure reply to is valid
|
||||||
|
first_message = dm_params[:entry][0]['messaging'][0]
|
||||||
|
contact_inbox
|
||||||
|
described_class.new(first_message, instagram_inbox).perform
|
||||||
|
|
||||||
|
# create the second message with the reply to mid set
|
||||||
|
messaging = instagram_message_reply_event[:entry][0]['messaging'][0]
|
||||||
|
contact_inbox
|
||||||
|
|
||||||
|
described_class.new(messaging, instagram_inbox).perform
|
||||||
|
first_message = instagram_channel.inbox.messages.first
|
||||||
|
message = instagram_channel.inbox.messages.last
|
||||||
|
|
||||||
|
expect(message.content).to eq('This is message with replyto mid')
|
||||||
|
expect(message.content_attributes[:in_reply_to_external_id]).to eq(first_message.source_id)
|
||||||
|
expect(message.content_attributes[:in_reply_to]).to eq(first_message.id)
|
||||||
|
end
|
||||||
|
|
||||||
it 'raises exception on deleted story' do
|
it 'raises exception on deleted story' do
|
||||||
allow(Koala::Facebook::API).to receive(:new).and_return(fb_object)
|
allow(Koala::Facebook::API).to receive(:new).and_return(fb_object)
|
||||||
allow(fb_object).to receive(:get_object).and_raise(Koala::Facebook::ClientError.new(
|
allow(fb_object).to receive(:get_object).and_raise(Koala::Facebook::ClientError.new(
|
||||||
|
|||||||
@@ -86,6 +86,36 @@ FactoryBot.define do
|
|||||||
initialize_with { attributes }
|
initialize_with { attributes }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :instagram_message_reply_event, class: Hash do
|
||||||
|
entry do
|
||||||
|
[
|
||||||
|
{
|
||||||
|
'id': 'instagram-message-id-123',
|
||||||
|
'time': '2021-09-08T06:35:04+0000',
|
||||||
|
'messaging': [
|
||||||
|
{
|
||||||
|
'sender': {
|
||||||
|
'id': 'Sender-id-1'
|
||||||
|
},
|
||||||
|
'recipient': {
|
||||||
|
'id': 'chatwoot-app-user-id-1'
|
||||||
|
},
|
||||||
|
'timestamp': '2021-09-08T06:34:04+0000',
|
||||||
|
'message': {
|
||||||
|
'mid': 'message-id-2',
|
||||||
|
'text': 'This is message with replyto mid',
|
||||||
|
'reply_to': {
|
||||||
|
'mid': 'message-id-1'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
initialize_with { attributes }
|
||||||
|
end
|
||||||
|
|
||||||
factory :instagram_test_text_event, class: Hash do
|
factory :instagram_test_text_event, class: Hash do
|
||||||
entry do
|
entry do
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user