Skip to content

Commit

Permalink
Implementing support to re-sending Facebook Messenger newsletters aft…
Browse files Browse the repository at this point in the history
…er 24-hours window. (#1935)

On a Facebook Messenger tipline, if the newsletter is sent to a user who hasn't interacted with the tipline in the last 24 hours, the message is not sent unless it contains a tag (it's like templates for WhatsApp). This commit adds support to that.

Fixes: CV2-4787.
  • Loading branch information
caiosba authored Jun 26, 2024
1 parent 95c4af9 commit cfae478
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/concerns/smooch_resend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ def resend_facebook_messenger_message_after_window(message, original)

return self.resend_facebook_messenger_report_after_window(message, original) if original&.dig('fallback_template') =~ /report/

# A newsletter
if original&.dig('fallback_template') == 'newsletter'
newsletter = TiplineNewsletter.where(language: original['language'], team_id: self.config['team_id'].to_i).last
newsletter_content = newsletter.build_content
self.send_message_to_user(uid, newsletter_content, self.message_tags_payload(newsletter_content))
return true
end

# A status message
if original&.dig('fallback_template') == 'fact_check_status'
text = original['message']
Expand Down
22 changes: 22 additions & 0 deletions test/models/bot/smooch_4_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -695,4 +695,26 @@ def teardown
end
end
end

test "should resend newsletter after Facebook Messenger 24-hours window" do
WebMock.stub_request(:get, 'http://test.com/feed.rss').to_return(body: '<rss></rss>')
msgid = random_string
response = OpenStruct.new({ body: OpenStruct.new(message: OpenStruct.new({ id: msgid })) })
Bot::Smooch.save_smooch_response(response, nil, random_string, 'newsletter', 'en', { message: random_string })
message = {
app: {
'_id': @app_id
},
appUser: {
'_id': random_string,
},
message: {
'_id': msgid
},
destination: {
type: 'messenger'
}
}.to_json
assert Bot::Smooch.resend_message_after_window(message)
end
end

0 comments on commit cfae478

Please sign in to comment.