Module: Five9Tools::PromptUtils
- Included in:
- Admin::Client
- Defined in:
- lib/five9tools/prompt_utils.rb
Defined Under Namespace
Classes: Error, UploadFailureError
Class Method Summary
collapse
Class Method Details
.delete_prompt_language(file_name, language_code_id) ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/five9tools/prompt_utils.rb', line 111
def delete_prompt_language(file_name, language_code_id)
lang_code_id = Five9Tools::LanguageUtils::five9ify(language_code_id)
message = {
:promptName => file_name,
:language => lang_code_id,
}
begin
puts "Attempting to delete prompt language #{lang_code_id} for prompt #{file_name}".yellow
self.call(:delete_language_prompt, :message => message)
rescue => exception
puts "There was no need to delete the prompt", exception
end
end
|
.get_lang_code_id_from_file_name(file_name) ⇒ Object
10
11
12
13
|
# File 'lib/five9tools/prompt_utils.rb', line 10
def get_lang_code_id_from_file_name(file_name)
f_base_name = File.basename(file_name)
f_base_name.split("____").first
end
|
.get_multilingual_prompts(paths_to_prompt_files) ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/five9tools/prompt_utils.rb', line 41
def get_multilingual_prompts(paths_to_prompt_files)
paths_to_prompt_files.filter_map do |f|
f_basename = File.basename(f)
lang_code = get_lang_code_id_from_file_name(f_basename)
five9_accepted = Five9Tools::LanguageUtils::five9ify(lang_code)
if is_multilingual_prompt?(f_basename) && !five9_accepted.downcase.include?("en")
f
end
end
end
|
.get_prompts ⇒ Object
125
126
127
|
# File 'lib/five9tools/prompt_utils.rb', line 125
def get_prompts
self.call(:get_prompts)
end
|
.is_multilingual_prompt?(f) ⇒ Boolean
74
75
76
77
|
# File 'lib/five9tools/prompt_utils.rb', line 74
def is_multilingual_prompt?(f)
sp = f.split("____").first
if Five9Tools::LanguageUtils::ALL_LOCALES.include?(sp) then return true else return false end
end
|
.modify_prompt(file_name, options = {}) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/five9tools/prompt_utils.rb', line 79
def modify_prompt(file_name, options = {})
destination_prompt_name = if options[:destination_prompt_name] then options[:destination_prompt_name] else file_name end
file_name_no_ext = destination_prompt_name.sub(/\.#{destination_prompt_name.split(".").last}/, "").split("/").last.split("____").last
base64_file = Five9Tools::Helpers::to_base64(file_name)
lang_code_id = if options[:language_code_id] then Five9Tools::LanguageUtils::five9ify(options[:language_code_id]) else "" end
message = {
:prompt => {
:description => file_name_no_ext,
:name => file_name_no_ext,
:languages => lang_code_id,
},
:wav_file => base64_file,
}
safely_modify_prompt(message).to_s.yellow.bold
end
|
.safely_modify_prompt(message) ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/five9tools/prompt_utils.rb', line 95
def safely_modify_prompt(message)
begin
puts "Attempting to add prompt #{message[:prompt][:name]} to the system".yellow
self.call(:modify_prompt_wav_inline, :message => message)
rescue => exception
puts "#{exception} \n\n Replacing wav language".cyan
begin
self.call(:delete_language_prompt, :message => { :promptName => message[:prompt][:name], :language => message[:prompt][:languages] })
self.call(:add_prompt_wav_inline, :message => message)
rescue => exception
puts exception
raise UploadFailureError
end
end
end
|
.safely_upload_prompt(message) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/five9tools/prompt_utils.rb', line 58
def safely_upload_prompt(message)
begin
puts "Attempting to add prompt #{message[:prompt][:name]} to the system".yellow
self.call(:add_prompt_wav_inline, :message => message)
rescue => exception
puts "#{exception} \n\n Replacing wav instead".cyan
begin
self.call(:delete_prompt, :message => { :promptName => message[:prompt][:name] })
self.call(:add_prompt_wav_inline, :message => message)
rescue => exception
puts exception
raise UploadFailureError
end
end
end
|
.upload_multilingual_prompt(file_name) ⇒ Object
52
53
54
55
56
|
# File 'lib/five9tools/prompt_utils.rb', line 52
def upload_multilingual_prompt(file_name)
language = get_lang_code_id_from_file_name(file_name)
puts "uploading #{file_name} with language #{language}"
modify_prompt(file_name, language)
end
|
.upload_prompt(file_name, options = {}) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/five9tools/prompt_utils.rb', line 25
def upload_prompt(file_name, options = {})
destination_prompt_name = if options[:destination_prompt_name] then options[:destination_prompt_name] else file_name end
file_name_no_ext = destination_prompt_name.sub(/\.#{destination_prompt_name.split(".").last}/, "").split("/").last.split("____").last base64_file = Five9Tools::Helpers::to_base64(file_name)
lang_code_id = if options[:language_code_id] then Five9Tools::LanguageUtils::five9ify(options[:language_code_id]) else "" end
message = {
:prompt => {
:description => file_name_no_ext,
:name => file_name_no_ext,
:languages => lang_code_id,
},
:wav_file => base64_file,
}
puts "PROMPT UPLOAD DATA", message
safely_upload_prompt(message).to_s.yellow.bold
end
|
.upload_prompts_in_dir(directory_name) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/five9tools/prompt_utils.rb', line 15
def upload_prompts_in_dir(directory_name)
files = Five9Tools::Helpers::get_files_recursively(directory_name)
multilingual_files = get_multilingual_prompts(files)
puts "MULTILINGUAL FILES DETECTED", multilingual_files
english_files = files - multilingual_files
english_result = english_files.map { |f| upload_prompt(f) }
multilingual_result = multilingual_files.map { |f| upload_multilingual_prompt(f) }
[english_result, multilingual_result]
end
|