Skip to content

Commit

Permalink
Fix for asking for search results feedback when a tipline has both Sm…
Browse files Browse the repository at this point in the history
…ooch and CAPI configured
  • Loading branch information
caiosba committed Feb 16, 2024
1 parent 70138db commit 248a78e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/concerns/smooch_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ def user_received_search_result(message)

def ask_for_feedback_when_all_search_results_are_received(app_id, language, workflow, uid, platform, provider, attempts)
RequestStore.store[:smooch_bot_platform] = platform
RequestStore.store[:smooch_bot_provider] = provider unless provider.blank?
redis = Redis.new(REDIS_CONFIG)
max = 20
if redis.llen("smooch:search:#{uid}") == 0 && CheckStateMachine.new(uid).state.value == 'search_result'
self.get_installation(self.installation_setting_id_keys, app_id) if self.config.blank?
RequestStore.store[:smooch_bot_provider] = provider unless provider.blank?
self.send_message_for_state(uid, workflow, 'search_result', language)
else
redis.del("smooch:search:#{uid}") if (attempts + 1) == max # Give up and just ask for feedback on the last iteration
Expand Down
6 changes: 3 additions & 3 deletions test/models/bot/smooch_6_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def send_message_outside_24_hours_window(template, pm = nil)
redis = Redis.new(REDIS_CONFIG)
redis.rpush("smooch:search:#{uid}", id)
assert_equal 1, redis.llen("smooch:search:#{uid}")
Bot::Smooch.ask_for_feedback_when_all_search_results_are_received(@app_id, 'en', {}, uid, 'WhatsApp', 1)
Bot::Smooch.ask_for_feedback_when_all_search_results_are_received(@app_id, 'en', {}, uid, 'WhatsApp', 'ZENDESK', 1)
Sidekiq::Testing.inline! do
payload = {
trigger: 'message:delivery:channel',
Expand All @@ -519,7 +519,7 @@ def send_message_outside_24_hours_window(template, pm = nil)
}
}.to_json
assert Bot::Smooch.run(payload)
Bot::Smooch.ask_for_feedback_when_all_search_results_are_received(@app_id, 'en', {}, uid, 'WhatsApp', 1)
Bot::Smooch.ask_for_feedback_when_all_search_results_are_received(@app_id, 'en', {}, uid, 'WhatsApp', 'ZENDESK', 1)
assert_equal 0, redis.llen("smooch:search:#{uid}")
end
end
Expand Down Expand Up @@ -680,7 +680,7 @@ def send_message_outside_24_hours_window(template, pm = nil)
redis.rpush("smooch:search:#{uid}", id)
assert_equal 1, redis.llen("smooch:search:#{uid}")
Sidekiq::Testing.inline! do
Bot::Smooch.ask_for_feedback_when_all_search_results_are_received(@app_id, 'en', {}, uid, 'WhatsApp', 1)
Bot::Smooch.ask_for_feedback_when_all_search_results_are_received(@app_id, 'en', {}, uid, 'WhatsApp', 'ZENDESK', 1)
end
assert_equal 0, redis.llen("smooch:search:#{uid}")
end
Expand Down

0 comments on commit 248a78e

Please sign in to comment.