Skip to content

Commit

Permalink
CV2-4853: fix sentry issue (#1940)
Browse files Browse the repository at this point in the history
* CV2-4853: fix sentry issue

* CV2-4853: add unit test

* fix CC issue

* Fix CC
  • Loading branch information
melsawy authored Jul 6, 2024
1 parent 8279c7c commit 5d16661
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/models/concerns/smooch_menus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ def send_message_to_user_with_main_menu_appended(uid, text, workflow, language,
rows: rows
}

# Set extra and fallback
extra, fallback = self.smooch_menus_set_extra_and_fallback(main, text, language)

self.send_message_to_user(uid, fallback.join("\n"), extra, false, true, event)
end

def smooch_menus_set_extra_and_fallback(main, text, language)
extra = {
override: {
whatsapp: {
Expand Down Expand Up @@ -114,7 +121,7 @@ def send_message_to_user_with_main_menu_appended(uid, text, workflow, language,
fallback = [text]
end

self.send_message_to_user(uid, fallback.join("\n"), extra, false, true, event)
return extra, fallback
end

def adjust_language_options(rows, language, number_of_options)
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/smooch_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def send_search_results_to_user(uid, results, team_id, platform)
end
reports.reject{ |r| r.blank? }.each do |report|
response = nil
no_body = (platform == 'Facebook Messenger')
no_body = (platform == 'Facebook Messenger' && !report.report_design_field_value('published_article_url').blank?)
response = self.send_message_to_user(uid, report.report_design_text(nil, no_body), {}, false, true, 'search_result') if report.report_design_field_value('use_text_message')
response = self.send_message_to_user(uid, '', { 'type' => 'image', 'mediaUrl' => report.report_design_image_url }, false, true, 'search_result') if !report.report_design_field_value('use_text_message') && report.report_design_field_value('use_visual_card')
id = self.get_id_from_send_response(response)
Expand Down
15 changes: 15 additions & 0 deletions test/models/bot/smooch_6_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,21 @@ def send_message_outside_24_hours_window(template, pm = nil)
CheckSearch.any_instance.unstub(:medias)
end

test "should send summary on messenger when URL is blank" do
pm = create_project_media(team: @team)
publish_report(pm, {}, nil, { language: 'en', use_visual_card: false })
CheckSearch.any_instance.stubs(:medias).returns([pm])
Sidekiq::Testing.inline! do
['hello', '1', '1', 'Foo bar', '1'].flatten.each { |message| send_message_to_smooch_bot(message, @uid, { 'source' => { 'type' => 'messenger' } }) }
assert_state 'search_result'
assert_difference 'TiplineRequest.count + ProjectMedia.count', 2 do
send_message_to_smooch_bot('1', @uid, { 'source' => { 'type' => 'messenger' } })
end
assert_state 'main'
end
CheckSearch.any_instance.unstub(:medias)
end

test "should submit query and get relevant text similarity search results on tipline bot v2" do
ProjectMedia.any_instance.stubs(:report_status).returns('published')
ProjectMedia.any_instance.stubs(:analysis_published_article_url).returns(random_url)
Expand Down

0 comments on commit 5d16661

Please sign in to comment.