chore: Remove delete Instagram story implementation (#11097)

Currently, Instagram stories are downloaded and displayed as
attachments. We previously implemented story deletion by checking
individual messages via
https://github.com/chatwoot/chatwoot/pull/5300/files#diff-684a16c1b0b4c099fcdfeed95b1820e11fef629fe332ec7ce6a8c600331dd06dR110,
but this approach proved impractical and was removed. This PR removes
all unused code to avoid confusion. We will revisit the story deletion
feature when we implement `instagram_manage_insights`.
This commit is contained in:
Muhsin Keloth
2025-03-25 09:44:26 +05:30
committed by GitHub
parent 50efd28d16
commit 8826a7066c
3 changed files with 0 additions and 63 deletions

View File

@@ -63,22 +63,4 @@ class Channel::FacebookPage < ApplicationRecord
Rails.logger.debug { "Rescued: #{e.inspect}" }
true
end
# TODO: We will be removing this code after instagram_manage_insights is implemented
def fetch_instagram_story_link(message)
k = Koala::Facebook::API.new(page_access_token)
result = k.get_object(message.source_id, fields: %w[story]) || {}
story_link = result['story']['mention']['link']
# If the story is expired then it raises the ClientError and if the story is deleted with valid story-id it responses with nil
delete_instagram_story(message) if story_link.blank?
story_link
rescue Koala::Facebook::ClientError => e
Rails.logger.debug { "Instagram Story Expired: #{e.inspect}" }
delete_instagram_story(message)
end
def delete_instagram_story(message)
message.attachments.destroy_all
message.update(content: I18n.t('conversations.messages.instagram_deleted_story_content'), content_attributes: {})
end
end

View File

@@ -155,15 +155,6 @@ class Message < ApplicationRecord
}
end
# TODO: We will be removing this code after instagram_manage_insights is implemented
# Better logic is to listen to webhook and remove stories proactively rather than trying
# a fetch every time a message is returned
def validate_instagram_story
inbox.channel.fetch_instagram_story_link(self)
# we want to reload the message in case the story has expired and data got removed
reload
end
def merge_sender_attributes(data)
data[:sender] = sender.push_event_data if sender && !sender.is_a?(AgentBot)
data[:sender] = sender.push_event_data(inbox) if sender.is_a?(AgentBot)

View File

@@ -30,42 +30,6 @@ RSpec.describe Channel::FacebookPage do
channel.prompt_reauthorization!
end
end
context 'when fetch instagram story' do
let!(:account) { create(:account) }
let!(:instagram_channel) { create(:channel_instagram_fb_page, account: account, instagram_id: 'chatwoot-app-user-id-1') }
let!(:instagram_inbox) { create(:inbox, channel: instagram_channel, account: account, greeting_enabled: false) }
let(:fb_object) { double }
let(:message) { create(:message, inbox_id: instagram_inbox.id) }
let(:instagram_message) { create(:message, :instagram_story_mention, inbox_id: instagram_inbox.id) }
it '#fetch_instagram_story_link' do
allow(Koala::Facebook::API).to receive(:new).and_return(fb_object)
allow(fb_object).to receive(:get_object).and_return(
{ story:
{
mention: {
link: 'https://www.example.com/test.jpeg',
id: '17920786367196703'
}
},
from: {
username: 'Sender-id-1', id: 'Sender-id-1'
},
id: 'instagram-message-id-1234' }.with_indifferent_access
)
story_link = instagram_channel.fetch_instagram_story_link(message)
expect(story_link).to eq('https://www.example.com/test.jpeg')
end
it '#delete_instagram_story' do
expect(instagram_message.attachments.count).to eq(1)
instagram_channel.delete_instagram_story(instagram_message)
expect(instagram_message.attachments.count).to eq(0)
end
end
end
it 'has a valid name' do