3
3
4
4
module Vonage
5
5
class Voice ::Actions ::Record
6
- attr_accessor :format , :split , :channels , :endOnSilence , :endOnKey , :timeOut , :beepStart , :eventUrl , :eventMethod
6
+ attr_accessor :format , :split , :channels , :endOnSilence , :endOnKey , :timeOut , :beepStart , :eventUrl , :eventMethod , :transcription
7
7
8
8
def initialize ( attributes = { } )
9
9
@format = attributes . fetch ( :format , nil )
@@ -15,6 +15,7 @@ def initialize(attributes = {})
15
15
@beepStart = attributes . fetch ( :beepStart , nil )
16
16
@eventUrl = attributes . fetch ( :eventUrl , nil )
17
17
@eventMethod = attributes . fetch ( :eventMethod , nil )
18
+ @transcription = attributes . fetch ( :transcription , nil )
18
19
19
20
after_initialize!
20
21
end
@@ -55,6 +56,10 @@ def after_initialize!
55
56
if self . eventMethod
56
57
validate_event_method
57
58
end
59
+
60
+ if self . transcription
61
+ validate_transcription
62
+ end
58
63
end
59
64
60
65
def validate_format
@@ -90,17 +95,59 @@ def validate_beep_start
90
95
end
91
96
92
97
def validate_event_url
93
- uri = URI . parse ( self . eventUrl )
98
+ unless self . eventUrl . is_a? ( Array ) && self . eventUrl . length == 1 && self . eventUrl [ 0 ] . is_a? ( String )
99
+ raise ClientError . new ( "Expected 'eventUrl' parameter to be an Array containing a single string item" )
100
+ end
94
101
95
- raise ClientError . new ( "Invalid 'eventUrl' value, must be a valid URL" ) unless uri . kind_of? ( URI ::HTTP ) || uri . kind_of? ( URI ::HTTPS )
102
+ uri = URI . parse ( self . eventUrl [ 0 ] )
103
+
104
+ raise ClientError . new ( "Invalid 'eventUrl' value, array must contain a valid URL" ) unless uri . kind_of? ( URI ::HTTP ) || uri . kind_of? ( URI ::HTTPS )
96
105
97
106
self . eventUrl
98
107
end
99
108
100
109
def validate_event_method
101
110
valid_methods = [ 'GET' , 'POST' ]
102
111
103
- raise ClientError . new ( "Invalid 'eventMethod' value. must be either: 'GET' or 'POST'" ) unless valid_methods . include? ( self . eventMethod . upcase )
112
+ raise ClientError . new ( "Invalid 'eventMethod' value. Must be either: 'GET' or 'POST'" ) unless valid_methods . include? ( self . eventMethod . upcase )
113
+ end
114
+
115
+ def validate_transcription
116
+ raise ClientError . new ( "Expected 'transcription' parameter to be a Hash" ) unless self . transcription . is_a? ( Hash )
117
+
118
+ if self . transcription [ :language ]
119
+ raise ClientError . new ( "Invalid 'language' value, must be a String" ) unless self . transcription [ :language ] . is_a? ( String )
120
+ end
121
+
122
+ if self . transcription [ :eventUrl ]
123
+ event_url = self . transcription [ :eventUrl ]
124
+
125
+ unless event_url . is_a? ( Array ) && event_url . length == 1 && event_url [ 0 ] . is_a? ( String )
126
+ raise ClientError . new ( "Expected 'eventUrl' parameter to be an Array containing a single string item" )
127
+ end
128
+
129
+ uri = URI . parse ( event_url [ 0 ] )
130
+
131
+ raise ClientError . new ( "Invalid 'eventUrl' value, array must contain a valid URL" ) unless uri . kind_of? ( URI ::HTTP ) || uri . kind_of? ( URI ::HTTPS )
132
+ end
133
+
134
+ if self . transcription [ :eventMethod ]
135
+ event_method = self . transcription [ :eventMethod ]
136
+ raise ClientError . new ( "Invalid 'eventMethod' value, must be either: 'GET' or 'POST'" ) unless [ 'GET' , 'POST' ] . include? ( event_method . upcase )
137
+ end
138
+
139
+ if self . transcription [ :sentimentAnalysis ]
140
+ sentiment_analysis = self . transcription [ :sentimentAnalysis ]
141
+ raise ClientError . new ( "Invalid 'sentimentAnalysis' value, must be a Boolean" ) unless sentiment_analysis == true || sentiment_analysis == false
142
+ end
143
+
144
+ # if self.dtmf[:maxDigits]
145
+ # raise ClientError.new("Expected 'maxDigits' to not be more than 22") if self.dtmf[:maxDigits] > 22
146
+ # end
147
+
148
+ # if self.dtmf[:submitOnHash]
149
+ # raise ClientError.new("Invalid 'submitOnHash' value, must be a Boolean") unless self.dtmf[:submitOnHash] == true || self.dtmf[:submitOnHash] == false
150
+ # end
104
151
end
105
152
106
153
def action
@@ -123,6 +170,7 @@ def create_record!(builder)
123
170
ncco [ 0 ] . merge! ( beepStart : builder . beepStart ) if builder . beepStart
124
171
ncco [ 0 ] . merge! ( eventUrl : builder . eventUrl ) if builder . eventUrl
125
172
ncco [ 0 ] . merge! ( eventMethod : builder . eventMethod ) if builder . eventMethod
173
+ ncco [ 0 ] . merge! ( transcription : builder . transcription ) if builder . transcription
126
174
127
175
ncco
128
176
end
0 commit comments