Skip to content

Commit

Permalink
Only deliver fact-check title and URL for Facebook Messenger tipline …
Browse files Browse the repository at this point in the history
…search results. (#1801)

Messenger changed the way it formats messages... now it breaks a single long message into smaller messages, so for long fact-checks, messages can be delivered out of order, which is super weird (like, a title in one message, the link in another message, etc.). This commit changes how tipline search results are delivered for Facebook Messenger: no fact-check summary, only title and URL.

Fixes CV2-4287.
  • Loading branch information
caiosba committed Feb 15, 2024
1 parent 6100930 commit 2b2eda8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions app/models/concerns/smooch_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def search(app_id, uid, language, message, team_id, workflow, provider = nil)
self.bundle_messages(uid, '', app_id, 'default_requests', nil, true)
self.send_final_message_to_user(uid, self.get_custom_string('search_no_results', language), workflow, language, 'no_results')
else
self.send_search_results_to_user(uid, results, team_id)
self.send_search_results_to_user(uid, results, team_id, platform)
sm.go_to_search_result
self.save_search_results_for_user(uid, results.map(&:id))
self.delay_for(1.second, { queue: 'smooch_priority' }).ask_for_feedback_when_all_search_results_are_received(app_id, language, workflow, uid, platform, 1)
Expand Down Expand Up @@ -217,7 +217,7 @@ def search_by_keywords_for_similar_published_fact_checks(words, after, team_ids,
results
end

def send_search_results_to_user(uid, results, team_id)
def send_search_results_to_user(uid, results, team_id, platform)
team = Team.find(team_id)
redis = Redis.new(REDIS_CONFIG)
language = self.get_user_language(uid)
Expand All @@ -230,7 +230,8 @@ def send_search_results_to_user(uid, results, team_id)
end
reports.reject{ |r| r.blank? }.each do |report|
response = nil
response = self.send_message_to_user(uid, report.report_design_text, {}, false, true, 'search_result') if report.report_design_field_value('use_text_message')
no_body = (platform == 'Facebook Messenger')
response = self.send_message_to_user(uid, report.report_design_text(nil, no_body), {}, false, true, 'search_result') if report.report_design_field_value('use_text_message')
response = self.send_message_to_user(uid, '', { 'type' => 'image', 'mediaUrl' => report.report_design_image_url }, false, true, 'search_result') if !report.report_design_field_value('use_text_message') && report.report_design_field_value('use_visual_card')
id = self.get_id_from_send_response(response)
redis.rpush("smooch:search:#{uid}", id) unless id.blank?
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/report_designer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ def report_design_text_footer(language)
footer.join("\n")
end

def report_design_text(language = nil)
def report_design_text(language = nil, hide_body = false)
if self.annotation_type == 'report_design'
team = self.annotated.team
text = []
title = self.report_design_field_value('title')
text << "*#{title.strip}*" unless title.blank?
text << self.report_design_field_value('text').to_s
text << self.report_design_field_value('text').to_s unless hide_body
url = self.report_design_field_value('published_article_url')
text << url unless url.blank?
text = text.collect do |part|
Expand Down

0 comments on commit 2b2eda8

Please sign in to comment.