Skip to content

Commit

Permalink
first attempt to include URLs as shortcuts triggering submission
Browse files Browse the repository at this point in the history
  • Loading branch information
computermacgyver committed Aug 28, 2024
1 parent 32bd426 commit 2bebbf0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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 =~ message['text'].to_s # URL in message?
)
end

def self.process_menu_option(message, state, app_id)
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.unstubs(:is_v2?)
end
end

0 comments on commit 2bebbf0

Please sign in to comment.