Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CV2-5148: Use more inclusive detection of URLs in message text #2013

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/models/bot/smooch.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'digest'
require 'uri'

class Bot::Smooch < BotUser
class MessageDeliveryError < StandardError; end
Expand Down Expand Up @@ -546,7 +545,7 @@ 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) ||
!URI.regexp.match(message['text'].to_s).nil? # URL in message?
!Twitter::TwitterText::Extractor.extract_urls(message['text'].to_s).blank? # URL in message?
)
end

Expand Down
4 changes: 4 additions & 0 deletions test/models/bot/smooch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,10 @@ def teardown
message = {"text"=>"abc", "mediaUrl"=>"not blank"}
assert_equal(true, Bot::Smooch.is_a_shortcut_for_submission?(state,message), "Missed media shortcut")

# Should be a submission shortcut
message = {"text"=>"abc example.com"}
assert_equal(true, Bot::Smooch.is_a_shortcut_for_submission?(state,message), "Missed non-qualified URL shortcut")

Bot::Smooch.unstub(:is_v2?)
end
end
Loading