Skip to content

Commit

Permalink
Tipline submission shortcuts
Browse files Browse the repository at this point in the history
When a tipline user sends a long text message or a file, jump right away into the "are you ready to submit" state.

Reference: CV2-2326.
  • Loading branch information
caiosba authored Oct 1, 2023
1 parent 35fd636 commit 721e5c4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion app/models/bot/smooch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@ def self.process_menu_option_value(value, option, message, language, workflow, a
end
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_shortcut', 3, :integer))
end

def self.process_menu_option(message, state, app_id)
uid = message['authorId']
sm = CheckStateMachine.new(uid)
Expand Down Expand Up @@ -577,8 +581,15 @@ def self.process_menu_option(message, state, app_id)
return true
end
end
# Lastly, check if it's a submission shortcut
if self.is_a_shortcut_for_submission?(sm.state, message)
self.bundle_message(message)
sm.go_to_ask_if_ready
self.send_message_for_state(uid, workflow, 'ask_if_ready', language)
return true
end
self.bundle_message(message)
return false
false
end

def self.user_received_report(message)
Expand Down
1 change: 1 addition & 0 deletions config/config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ development: &default
image_cluster_similarity_threshold: 0.9
text_cluster_similarity_threshold: 0.9
similarity_media_file_url_host: ''
min_number_of_words_for_tipline_shortcut: 3

# Localization
#
Expand Down
12 changes: 11 additions & 1 deletion test/models/bot/smooch_6_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ def send_message_outside_24_hours_window(template, pm = nil)
nlu.disable!
reload_tipline_settings
send_message 'Can I subscribe to the newsletter?'
assert_state 'main'
assert_state 'ask_if_ready'

# Delete two keywords, so expect two calls to Alegre
Bot::Alegre.expects(:request_api).with{ |x, y, _z| x == 'delete' && y == '/text/similarity/' }.twice
Expand Down Expand Up @@ -844,4 +844,14 @@ def send_message_outside_24_hours_window(template, pm = nil)
r.remove_keyword('who are you')
end
end

test 'should have shortcuts for submission' do
send_message 'This is message is so long that it is considered a media'
assert_state 'ask_if_ready'
end

test 'should not have shortcuts for submission' do
send_message 'Hello'
assert_state 'main'
end
end

0 comments on commit 721e5c4

Please sign in to comment.