fix: Automatically remove expired story mention (#5300)

When a user mentions the connected Instagram page in a story, the story's content is downloaded in Chatwoot, then if the user deletes the story, the content persists in the platform.

fixes: #5258
This commit is contained in:
Tejaswini Chile
2022-12-08 18:25:24 +05:30
committed by GitHub
parent 431e2931c4
commit 7dc790a7e0
13 changed files with 111 additions and 15 deletions

View File

@@ -63,4 +63,21 @@ 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
delete_instagram_story(message)
end
def delete_instagram_story(message)
message.update(content: I18n.t('conversations.messages.instagram_deleted_story_content'), content_attributes: {})
message.attachments.destroy_all
end
end