diff --git a/app/models/concerns/smooch_resend.rb b/app/models/concerns/smooch_resend.rb index 253756542b..883ed49cd1 100644 --- a/app/models/concerns/smooch_resend.rb +++ b/app/models/concerns/smooch_resend.rb @@ -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'] diff --git a/test/models/bot/smooch_4_test.rb b/test/models/bot/smooch_4_test.rb index 5ed99aa1e7..f8df58f903 100644 --- a/test/models/bot/smooch_4_test.rb +++ b/test/models/bot/smooch_4_test.rb @@ -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: '') + 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