Skip to content

Commit

Permalink
CV2-5148: Use more inclusive detection of URLs in tipline messages fo…
Browse files Browse the repository at this point in the history
…r submission shortcut

URI.regexp.match... only matched fully-qualified urls
(i.e., urls need to include http://, https://, or another protocol)
Twitter::TwitterText::Extractor.extract_urls recognizes urls without
the protocol. This is consistent with how WhatsApp and other platforms
parse URLs and more in line with user expectations.

Co-authored-by: computermacgyver <computermacgyver>
  • Loading branch information
computermacgyver authored Aug 29, 2024
1 parent 0598a50 commit 9a30cf1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
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

0 comments on commit 9a30cf1

Please sign in to comment.