Skip to content

Commit e0b3cf5

Browse files
committed
Refactoring and fixing how default messages are returned to tipline users. (#2294)
Fixes: CV2-6346.
1 parent 75e2f8c commit e0b3cf5

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

app/models/concerns/smooch_menus.rb

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ def get_next_menu_item_number(current)
147147
counter
148148
end
149149

150+
def get_default_string(key, language)
151+
TIPLINE_STRINGS.dig(language, key) || TIPLINE_STRINGS.dig(language.gsub(/[-_].*$/, ''), key) || TIPLINE_STRINGS.dig('en', key) || ''
152+
end
153+
150154
def get_custom_string(key, language, truncate_at = 1024)
151155
# Truncation happens because WhatsApp has limitations:
152156
# - Section title: 24 characters
@@ -157,23 +161,7 @@ def get_custom_string(key, language, truncate_at = 1024)
157161
workflow = self.get_workflow(language) || {}
158162
custom_label = workflow.with_indifferent_access.dig(*key)
159163
key = key.join('_') if key.is_a?(Array)
160-
default_label = {
161-
# Default values for customizable strings
162-
smooch_message_smooch_bot_greetings: 'Welcome to our fact-checking bot. Use the main menu to navigate.',
163-
smooch_state_query_smooch_menu_message: 'Please enter the question, link, picture, or video that you want to be fact-checked.',
164-
ask_if_ready_state: 'Are you ready to submit?',
165-
add_more_details_state: 'Please add more content.',
166-
search_state: 'Thank you! Looking for fact-checks, it may take a minute.',
167-
search_no_results: 'No fact-checks have been found. Journalists on our team have been notified and you will receive an update in this thread if the information is fact-checked.',
168-
search_result_state: 'Are these fact-checks answering your question?',
169-
search_submit: 'Thank you for your feedback. Journalists on our team have been notified and you will receive an update in this thread if a new fact-check is published.',
170-
search_result_is_relevant: 'Thank you! Spread the word about this tipline to help us fight misinformation! *insert_entry_point_link*',
171-
newsletter_optin_optout: 'Subscribe now to get the most important facts delivered directly on WhatsApp, every week. {subscription_status}',
172-
smooch_state_subscription_smooch_menu_message: '', # FIXME: Backwards compatibility with v1, should be removed in the future.
173-
option_not_available: "I'm sorry, I didn't understand your message.",
174-
timeout: 'Thank you for reaching out to us! Type any key to start a new conversation.',
175-
smooch_message_smooch_bot_disabled: 'Our bot is currently inactive. Please visit *insert URL* to read the latest fact-checks.'
176-
}[key.to_sym] || ''
164+
default_label = self.get_default_string(key.to_s, language)
177165
label = custom_label.blank? ? default_label : custom_label
178166
label.to_s.truncate(truncate_at)
179167
end

app/models/concerns/smooch_team_bot_installation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def smooch_default_messages
123123
keys = ::Bot::Smooch::TIPLINE_CUSTOMIZABLE_MESSAGES
124124
self.team.get_languages.to_a.each do |language|
125125
messages[language] = {}
126-
keys.each { |key| messages[language][key.to_s] = TIPLINE_STRINGS.dig(language, key) || TIPLINE_STRINGS.dig(language.gsub(/[-_].*$/, ''), key) || TIPLINE_STRINGS.dig('en', key) }
126+
keys.each { |key| messages[language][key.to_s] = ::Bot::Smooch.get_default_string(key.to_s, language) }
127127
end
128128
messages
129129
end

0 commit comments

Comments
 (0)