Skip to content

Commit

Permalink
CV2-5148: include URLs as shortcuts triggering tipline submission (#2011
Browse files Browse the repository at this point in the history
)
  • Loading branch information
computermacgyver authored Aug 28, 2024
1 parent 32bd426 commit da88e28
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
7 changes: 6 additions & 1 deletion app/models/bot/smooch.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'digest'
require 'uri'

class Bot::Smooch < BotUser
class MessageDeliveryError < StandardError; end
Expand Down Expand Up @@ -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.match(message['text'].to_s).nil? # URL in message?
)
end

def self.process_menu_option(message, state, app_id)
Expand Down
6 changes: 3 additions & 3 deletions test/models/bot/smooch_6_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -664,12 +664,12 @@ def send_message_outside_24_hours_window(template, pm = nil)
test "should not duplicate messages when saving" do
@team.set_languages ['en']
@team.save!
url = 'http://localhost'
send_message url, '1', url, '1'
message_text = 'not_a_url' #Not a URL, not media, and not longer than 'min_number_of_words_for_tipline_submit_shortcut'
send_message message_text, '1', message_text, '1'
assert_state 'search'
Sidekiq::Worker.drain_all
tr = TiplineRequest.last
assert_equal 2, tr.smooch_data['text'].split("\n#{Bot::Smooch::MESSAGE_BOUNDARY}").select{ |x| x.chomp.strip == url }.size
assert_equal 2, tr.smooch_data['text'].split("\n#{Bot::Smooch::MESSAGE_BOUNDARY}").select{ |x| x.chomp.strip == message_text }.size
end

test "should get search results in different languages" do
Expand Down
19 changes: 19 additions & 0 deletions test/models/bot/smooch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.unstub(:is_v2?)
end
end

0 comments on commit da88e28

Please sign in to comment.