diff --git a/app/models/bot/smooch.rb b/app/models/bot/smooch.rb index 7f98916df1..803e631e91 100644 --- a/app/models/bot/smooch.rb +++ b/app/models/bot/smooch.rb @@ -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) @@ -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) diff --git a/config/config.yml.example b/config/config.yml.example index 73aabf012e..2c6ff6cb39 100644 --- a/config/config.yml.example +++ b/config/config.yml.example @@ -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 # diff --git a/test/models/bot/smooch_6_test.rb b/test/models/bot/smooch_6_test.rb index d9be1df6cb..ff608d617c 100644 --- a/test/models/bot/smooch_6_test.rb +++ b/test/models/bot/smooch_6_test.rb @@ -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 @@ -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