From 2bebbf0dd3f987c93a14e48d78d60114d6e50a57 Mon Sep 17 00:00:00 2001 From: computermacgyver Date: Wed, 28 Aug 2024 12:02:00 +0900 Subject: [PATCH] first attempt to include URLs as shortcuts triggering submission --- app/models/bot/smooch.rb | 7 ++++++- test/models/bot/smooch_test.rb | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/models/bot/smooch.rb b/app/models/bot/smooch.rb index 9177a69039..288f1036e9 100644 --- a/app/models/bot/smooch.rb +++ b/app/models/bot/smooch.rb @@ -1,4 +1,5 @@ require 'digest' +require 'uri' class Bot::Smooch < BotUser class MessageDeliveryError < StandardError; end @@ -542,7 +543,11 @@ def self.process_menu_option_value(value, option, message, language, workflow, a end def self.is_a_shortcut_for_submission?(state, message) - self.is_v2? && (state == 'main' || state == 'waiting_for_message') && (!message['mediaUrl'].blank? || ::Bot::Alegre.get_number_of_words(message['text'].to_s) > CheckConfig.get('min_number_of_words_for_tipline_submit_shortcut', 10, :integer)) + self.is_v2? && (state == 'main' || state == 'waiting_for_message') && ( + !message['mediaUrl'].blank? || + ::Bot::Alegre.get_number_of_words(message['text'].to_s) > CheckConfig.get('min_number_of_words_for_tipline_submit_shortcut', 10, :integer) || + URI.regexp =~ message['text'].to_s # URL in message? + ) end def self.process_menu_option(message, state, app_id) diff --git a/test/models/bot/smooch_test.rb b/test/models/bot/smooch_test.rb index 8724731980..e5f86b83a4 100644 --- a/test/models/bot/smooch_test.rb +++ b/test/models/bot/smooch_test.rb @@ -789,4 +789,23 @@ def teardown tr = pm.tipline_requests.last assert_equal 'en', tr.smooch_user_request_language end + + test "should submit message for factchecking" do + Bot::Smooch.stubs(:is_v2?).returns{true} + state='main' + + # Should not be a submission shortcut + message = {"text": "abc"} + assert_equal(false, Bot::Smooch::is_a_shortcut_for_submission(state,message), "Unexpected shortcut" + + # Should be a submission shortcut + message = {"text": "abc http://example.com"} + assert_equal(true, Bot::Smooch::is_a_shortcut_for_submission(state,message), "Missed URL shortcut" + + # Should be a submission shortcut + message = {"text": "abc", "mediaUrl": "not blank"} + assert_equal(true, Bot::Smooch::is_a_shortcut_for_submission(state,message), "Missed media shortcut" + + Bot::Smooch.unstubs(:is_v2?) + end end