voiceml 0.9.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +27 -16
  3. data/lib/voiceml/client.rb +76 -15
  4. data/lib/voiceml/errors.rb +15 -2
  5. data/lib/voiceml/hosts.rb +62 -0
  6. data/lib/voiceml/models/accounts.rb +47 -3
  7. data/lib/voiceml/models/applications.rb +6 -0
  8. data/lib/voiceml/models/assistants_v1.rb +40 -0
  9. data/lib/voiceml/models/calls.rb +4 -0
  10. data/lib/voiceml/models/common.rb +35 -4
  11. data/lib/voiceml/models/conferences.rb +8 -0
  12. data/lib/voiceml/models/conversations_v1.rb +131 -29
  13. data/lib/voiceml/models/diagnostics.rb +33 -12
  14. data/lib/voiceml/models/exports.rb +58 -0
  15. data/lib/voiceml/models/incoming_phone_numbers.rb +4 -0
  16. data/lib/voiceml/models/media.rb +4 -0
  17. data/lib/voiceml/models/messages.rb +29 -0
  18. data/lib/voiceml/models/messaging_v1.rb +73 -0
  19. data/lib/voiceml/models/monitor_v1.rb +54 -0
  20. data/lib/voiceml/models/notifications.rb +2 -0
  21. data/lib/voiceml/models/outgoing_caller_ids.rb +6 -0
  22. data/lib/voiceml/models/payments.rb +2 -0
  23. data/lib/voiceml/models/pricing.rb +265 -0
  24. data/lib/voiceml/models/queues.rb +8 -0
  25. data/lib/voiceml/models/recordings.rb +5 -1
  26. data/lib/voiceml/models/routes_v2.rb +6 -2
  27. data/lib/voiceml/models/sip.rb +34 -6
  28. data/lib/voiceml/models/sip_registrations.rb +49 -0
  29. data/lib/voiceml/models/siprec.rb +5 -17
  30. data/lib/voiceml/models/streams.rb +4 -16
  31. data/lib/voiceml/models/transcriptions.rb +35 -4
  32. data/lib/voiceml/models/usage_records.rb +48 -0
  33. data/lib/voiceml/models/user_defined_messages.rb +2 -0
  34. data/lib/voiceml/models/voice_v1.rb +29 -19
  35. data/lib/voiceml/request_validator.rb +125 -0
  36. data/lib/voiceml/resources/accounts.rb +75 -0
  37. data/lib/voiceml/resources/applications.rb +3 -1
  38. data/lib/voiceml/resources/assistants_v1.rb +53 -77
  39. data/lib/voiceml/resources/base.rb +138 -16
  40. data/lib/voiceml/resources/calls.rb +34 -49
  41. data/lib/voiceml/resources/conferences.rb +26 -5
  42. data/lib/voiceml/resources/conversations_v1.rb +147 -172
  43. data/lib/voiceml/resources/diagnostics.rb +20 -35
  44. data/lib/voiceml/resources/exports.rb +36 -0
  45. data/lib/voiceml/resources/incoming_phone_numbers.rb +53 -32
  46. data/lib/voiceml/resources/messages.rb +79 -15
  47. data/lib/voiceml/resources/messaging_v1.rb +121 -0
  48. data/lib/voiceml/resources/monitor_v1.rb +68 -0
  49. data/lib/voiceml/resources/notifications.rb +1 -1
  50. data/lib/voiceml/resources/outgoing_caller_ids.rb +77 -0
  51. data/lib/voiceml/resources/pricing.rb +148 -0
  52. data/lib/voiceml/resources/queues.rb +6 -5
  53. data/lib/voiceml/resources/recordings.rb +39 -5
  54. data/lib/voiceml/resources/routes_v2.rb +10 -4
  55. data/lib/voiceml/resources/sip.rb +30 -11
  56. data/lib/voiceml/resources/transcriptions.rb +40 -0
  57. data/lib/voiceml/resources/usage_records.rb +51 -0
  58. data/lib/voiceml/resources/voice_v1.rb +31 -38
  59. data/lib/voiceml/transport.rb +293 -206
  60. data/lib/voiceml/version.rb +1 -1
  61. data/lib/voiceml.rb +14 -15
  62. metadata +23 -6
@@ -18,21 +18,25 @@ module VoiceML
18
18
 
19
19
  # AssistantsV1Assistant — `aia_asst_...`. Used by list/create/update/delete responses.
20
20
  class AssistantsV1Assistant
21
+ include RawAttributes
21
22
  ATTRIBUTES = %w[
22
23
  account_sid customer_ai id model name owner url personality_prompt
23
24
  date_created date_updated
24
25
  ].freeze
25
26
  attr_reader(*ATTRIBUTES.map(&:to_sym))
26
27
  def initialize(attrs = {})
28
+ @raw_attributes = attrs
27
29
  ATTRIBUTES.each { |f| instance_variable_set("@#{f}", attrs.key?(f) ? attrs[f] : attrs[f.to_sym]) }
28
30
  end
29
31
  def self.from_hash(h); h.nil? ? nil : new(h); end
30
32
  end
31
33
 
32
34
  class AssistantsV1AssistantList
35
+ include RawAttributes
33
36
  include V1Pageable
34
37
  attr_reader :assistants
35
38
  def initialize(hash = {})
39
+ @raw_attributes = hash
36
40
  assign_meta_fields(hash)
37
41
  @assistants = (hash['assistants'] || []).map { |h| AssistantsV1Assistant.from_hash(h) }
38
42
  end
@@ -41,12 +45,14 @@ module VoiceML
41
45
  # AssistantsV1AssistantWithToolsAndKnowledge — fetch-one shape that includes the
42
46
  # attached tools and knowledge arrays inline.
43
47
  class AssistantsV1AssistantWithToolsAndKnowledge
48
+ include RawAttributes
44
49
  ATTRIBUTES = %w[
45
50
  account_sid customer_ai id model name owner url personality_prompt
46
51
  date_created date_updated tools knowledge
47
52
  ].freeze
48
53
  attr_reader(*ATTRIBUTES.map(&:to_sym))
49
54
  def initialize(attrs = {})
55
+ @raw_attributes = attrs
50
56
  ATTRIBUTES.each { |f| instance_variable_set("@#{f}", attrs.key?(f) ? attrs[f] : attrs[f.to_sym]) }
51
57
  end
52
58
  def self.from_hash(h); h.nil? ? nil : new(h); end
@@ -54,21 +60,25 @@ module VoiceML
54
60
 
55
61
  # AssistantsV1Tool — `aia_tool_...`.
56
62
  class AssistantsV1Tool
63
+ include RawAttributes
57
64
  ATTRIBUTES = %w[
58
65
  account_sid description enabled id meta name requires_auth type url
59
66
  date_created date_updated
60
67
  ].freeze
61
68
  attr_reader(*ATTRIBUTES.map(&:to_sym))
62
69
  def initialize(attrs = {})
70
+ @raw_attributes = attrs
63
71
  ATTRIBUTES.each { |f| instance_variable_set("@#{f}", attrs.key?(f) ? attrs[f] : attrs[f.to_sym]) }
64
72
  end
65
73
  def self.from_hash(h); h.nil? ? nil : new(h); end
66
74
  end
67
75
 
68
76
  class AssistantsV1ToolList
77
+ include RawAttributes
69
78
  include V1Pageable
70
79
  attr_reader :tools
71
80
  def initialize(hash = {})
81
+ @raw_attributes = hash
72
82
  assign_meta_fields(hash)
73
83
  @tools = (hash['tools'] || []).map { |h| AssistantsV1Tool.from_hash(h) }
74
84
  end
@@ -76,12 +86,14 @@ module VoiceML
76
86
 
77
87
  # AssistantsV1ToolWithPolicies — fetch-one shape that includes the policies array inline.
78
88
  class AssistantsV1ToolWithPolicies
89
+ include RawAttributes
79
90
  ATTRIBUTES = %w[
80
91
  account_sid description enabled id meta name requires_auth type url
81
92
  date_created date_updated policies
82
93
  ].freeze
83
94
  attr_reader(*ATTRIBUTES.map(&:to_sym))
84
95
  def initialize(attrs = {})
96
+ @raw_attributes = attrs
85
97
  ATTRIBUTES.each { |f| instance_variable_set("@#{f}", attrs.key?(f) ? attrs[f] : attrs[f.to_sym]) }
86
98
  end
87
99
  def self.from_hash(h); h.nil? ? nil : new(h); end
@@ -89,21 +101,25 @@ module VoiceML
89
101
 
90
102
  # AssistantsV1Knowledge — `aia_know_...`.
91
103
  class AssistantsV1Knowledge
104
+ include RawAttributes
92
105
  ATTRIBUTES = %w[
93
106
  account_sid description id knowledge_source_details name status type url
94
107
  embedding_model date_created date_updated
95
108
  ].freeze
96
109
  attr_reader(*ATTRIBUTES.map(&:to_sym))
97
110
  def initialize(attrs = {})
111
+ @raw_attributes = attrs
98
112
  ATTRIBUTES.each { |f| instance_variable_set("@#{f}", attrs.key?(f) ? attrs[f] : attrs[f.to_sym]) }
99
113
  end
100
114
  def self.from_hash(h); h.nil? ? nil : new(h); end
101
115
  end
102
116
 
103
117
  class AssistantsV1KnowledgeList
118
+ include RawAttributes
104
119
  include V1Pageable
105
120
  attr_reader :knowledge
106
121
  def initialize(hash = {})
122
+ @raw_attributes = hash
107
123
  assign_meta_fields(hash)
108
124
  @knowledge = (hash['knowledge'] || []).map { |h| AssistantsV1Knowledge.from_hash(h) }
109
125
  end
@@ -111,9 +127,11 @@ module VoiceML
111
127
 
112
128
  # AssistantsV1KnowledgeStatus — read-only ingestion status snapshot.
113
129
  class AssistantsV1KnowledgeStatus
130
+ include RawAttributes
114
131
  ATTRIBUTES = %w[account_sid status last_status date_updated].freeze
115
132
  attr_reader(*ATTRIBUTES.map(&:to_sym))
116
133
  def initialize(attrs = {})
134
+ @raw_attributes = attrs
117
135
  ATTRIBUTES.each { |f| instance_variable_set("@#{f}", attrs.key?(f) ? attrs[f] : attrs[f.to_sym]) }
118
136
  end
119
137
  def self.from_hash(h); h.nil? ? nil : new(h); end
@@ -121,18 +139,22 @@ module VoiceML
121
139
 
122
140
  # AssistantsV1KnowledgeChunk — single retrieved chunk of indexed Knowledge content.
123
141
  class AssistantsV1KnowledgeChunk
142
+ include RawAttributes
124
143
  ATTRIBUTES = %w[account_sid content metadata date_created date_updated].freeze
125
144
  attr_reader(*ATTRIBUTES.map(&:to_sym))
126
145
  def initialize(attrs = {})
146
+ @raw_attributes = attrs
127
147
  ATTRIBUTES.each { |f| instance_variable_set("@#{f}", attrs.key?(f) ? attrs[f] : attrs[f.to_sym]) }
128
148
  end
129
149
  def self.from_hash(h); h.nil? ? nil : new(h); end
130
150
  end
131
151
 
132
152
  class AssistantsV1KnowledgeChunkList
153
+ include RawAttributes
133
154
  include V1Pageable
134
155
  attr_reader :chunks
135
156
  def initialize(hash = {})
157
+ @raw_attributes = hash
136
158
  assign_meta_fields(hash)
137
159
  @chunks = (hash['chunks'] || []).map { |h| AssistantsV1KnowledgeChunk.from_hash(h) }
138
160
  end
@@ -140,20 +162,24 @@ module VoiceML
140
162
 
141
163
  # AssistantsV1Session — a chat session between an identity and an Assistant.
142
164
  class AssistantsV1Session
165
+ include RawAttributes
143
166
  ATTRIBUTES = %w[
144
167
  id account_sid assistant_id verified identity date_created date_updated
145
168
  ].freeze
146
169
  attr_reader(*ATTRIBUTES.map(&:to_sym))
147
170
  def initialize(attrs = {})
171
+ @raw_attributes = attrs
148
172
  ATTRIBUTES.each { |f| instance_variable_set("@#{f}", attrs.key?(f) ? attrs[f] : attrs[f.to_sym]) }
149
173
  end
150
174
  def self.from_hash(h); h.nil? ? nil : new(h); end
151
175
  end
152
176
 
153
177
  class AssistantsV1SessionList
178
+ include RawAttributes
154
179
  include V1Pageable
155
180
  attr_reader :sessions
156
181
  def initialize(hash = {})
182
+ @raw_attributes = hash
157
183
  assign_meta_fields(hash)
158
184
  @sessions = (hash['sessions'] || []).map { |h| AssistantsV1Session.from_hash(h) }
159
185
  end
@@ -161,21 +187,25 @@ module VoiceML
161
187
 
162
188
  # AssistantsV1Message — `aia_msg_...`. One message in an Assistant session.
163
189
  class AssistantsV1Message
190
+ include RawAttributes
164
191
  ATTRIBUTES = %w[
165
192
  id account_sid assistant_id session_id identity role content meta
166
193
  date_created date_updated
167
194
  ].freeze
168
195
  attr_reader(*ATTRIBUTES.map(&:to_sym))
169
196
  def initialize(attrs = {})
197
+ @raw_attributes = attrs
170
198
  ATTRIBUTES.each { |f| instance_variable_set("@#{f}", attrs.key?(f) ? attrs[f] : attrs[f.to_sym]) }
171
199
  end
172
200
  def self.from_hash(h); h.nil? ? nil : new(h); end
173
201
  end
174
202
 
175
203
  class AssistantsV1MessageList
204
+ include RawAttributes
176
205
  include V1Pageable
177
206
  attr_reader :messages
178
207
  def initialize(hash = {})
208
+ @raw_attributes = hash
179
209
  assign_meta_fields(hash)
180
210
  @messages = (hash['messages'] || []).map { |h| AssistantsV1Message.from_hash(h) }
181
211
  end
@@ -184,9 +214,11 @@ module VoiceML
184
214
  # AssistantsV1SendMessageResponse — POST /v1/Assistants/{id}/Messages return shape.
185
215
  # Distinct from AssistantsV1Message: carries the model's reply body + flag/abort signals.
186
216
  class AssistantsV1SendMessageResponse
217
+ include RawAttributes
187
218
  ATTRIBUTES = %w[status flagged aborted session_id account_sid body error].freeze
188
219
  attr_reader(*ATTRIBUTES.map(&:to_sym))
189
220
  def initialize(attrs = {})
221
+ @raw_attributes = attrs
190
222
  ATTRIBUTES.each { |f| instance_variable_set("@#{f}", attrs.key?(f) ? attrs[f] : attrs[f.to_sym]) }
191
223
  end
192
224
  def self.from_hash(h); h.nil? ? nil : new(h); end
@@ -194,21 +226,25 @@ module VoiceML
194
226
 
195
227
  # AssistantsV1Feedback — `aia_fdbk_...`. Numeric score + text feedback on a message.
196
228
  class AssistantsV1Feedback
229
+ include RawAttributes
197
230
  ATTRIBUTES = %w[
198
231
  assistant_id id account_sid user_sid message_id score session_id text
199
232
  date_created date_updated
200
233
  ].freeze
201
234
  attr_reader(*ATTRIBUTES.map(&:to_sym))
202
235
  def initialize(attrs = {})
236
+ @raw_attributes = attrs
203
237
  ATTRIBUTES.each { |f| instance_variable_set("@#{f}", attrs.key?(f) ? attrs[f] : attrs[f.to_sym]) }
204
238
  end
205
239
  def self.from_hash(h); h.nil? ? nil : new(h); end
206
240
  end
207
241
 
208
242
  class AssistantsV1FeedbackList
243
+ include RawAttributes
209
244
  include V1Pageable
210
245
  attr_reader :feedbacks
211
246
  def initialize(hash = {})
247
+ @raw_attributes = hash
212
248
  assign_meta_fields(hash)
213
249
  @feedbacks = (hash['feedbacks'] || []).map { |h| AssistantsV1Feedback.from_hash(h) }
214
250
  end
@@ -217,21 +253,25 @@ module VoiceML
217
253
  # AssistantsV1Policy — `aia_plcy_...`. Read-only — listed under /v1/Policies (filterable
218
254
  # by ToolId/KnowledgeId) and embedded inline on Tool fetch responses.
219
255
  class AssistantsV1Policy
256
+ include RawAttributes
220
257
  ATTRIBUTES = %w[
221
258
  id name description account_sid user_sid type policy_details
222
259
  date_created date_updated
223
260
  ].freeze
224
261
  attr_reader(*ATTRIBUTES.map(&:to_sym))
225
262
  def initialize(attrs = {})
263
+ @raw_attributes = attrs
226
264
  ATTRIBUTES.each { |f| instance_variable_set("@#{f}", attrs.key?(f) ? attrs[f] : attrs[f.to_sym]) }
227
265
  end
228
266
  def self.from_hash(h); h.nil? ? nil : new(h); end
229
267
  end
230
268
 
231
269
  class AssistantsV1PolicyList
270
+ include RawAttributes
232
271
  include V1Pageable
233
272
  attr_reader :policies
234
273
  def initialize(hash = {})
274
+ @raw_attributes = hash
235
275
  assign_meta_fields(hash)
236
276
  @policies = (hash['policies'] || []).map { |h| AssistantsV1Policy.from_hash(h) }
237
277
  end
@@ -6,6 +6,7 @@ module VoiceML
6
6
  # A Twilio-compatible Call resource. Returned by `client.calls.create`, `client.calls.get`,
7
7
  # `client.calls.update`, and listed in `CallList#calls`.
8
8
  class Call
9
+ include RawAttributes
9
10
  ATTRIBUTES = %w[
10
11
  sid account_sid api_version to to_formatted from from_formatted
11
12
  parent_call_sid caller_name forwarded_from status direction
@@ -17,6 +18,7 @@ module VoiceML
17
18
  attr_reader(*ATTRIBUTES.map(&:to_sym))
18
19
 
19
20
  def initialize(attrs = {})
21
+ @raw_attributes = attrs
20
22
  ATTRIBUTES.each do |field|
21
23
  value = attrs.key?(field) ? attrs[field] : attrs[field.to_sym]
22
24
  instance_variable_set("@#{field}", value)
@@ -32,11 +34,13 @@ module VoiceML
32
34
 
33
35
  # Paginated `GET /Calls` response.
34
36
  class CallList
37
+ include RawAttributes
35
38
  include Pageable
36
39
 
37
40
  attr_reader :calls
38
41
 
39
42
  def initialize(hash = {})
43
+ @raw_attributes = hash
40
44
  assign_page_fields(hash)
41
45
  @calls = (hash['calls'] || []).map { |c| Call.from_hash(c) }
42
46
  end
@@ -2,12 +2,12 @@
2
2
 
3
3
  module VoiceML
4
4
  # Twilio-compatible pagination envelope fields. Mix into list-response classes to expose
5
- # `page`, `page_size`, `total`, `next_page_uri`, `previous_page_uri`, `first_page_uri`,
6
- # `uri`, `num_pages`, `start`, `end`. The list items themselves are declared on each
7
- # concrete subclass (`calls`, `conferences`, etc).
5
+ # `page`, `page_size`, `start`, `end`, `first_page_uri`, `next_page_uri`, `previous_page_uri`,
6
+ # `uri`. The list items themselves are declared on each concrete subclass (`calls`,
7
+ # `conferences`, etc).
8
8
  module Pageable
9
9
  PAGE_FIELDS = %w[
10
- page page_size num_pages total start end
10
+ page page_size start end
11
11
  first_page_uri next_page_uri previous_page_uri uri
12
12
  ].freeze
13
13
 
@@ -22,6 +22,37 @@ module VoiceML
22
22
  end
23
23
  end
24
24
 
25
+ # Shared `meta` envelope for `/v1/*` list responses.
26
+ module V1Pageable
27
+ META_FIELDS = %w[first_page_url next_page_url previous_page_url url page page_size key].freeze
28
+
29
+ META_FIELDS.each { |f| attr_reader f.to_sym }
30
+
31
+ def assign_meta_fields(hash)
32
+ meta = hash['meta'] || {}
33
+ META_FIELDS.each { |f| instance_variable_set("@#{f}", meta[f]) }
34
+ end
35
+ end
36
+
37
+ # Mixed into every response model: keeps the raw wire hash readable via
38
+ # `#to_h` / `#[]` so fields the SDK does not model yet (or newly added
39
+ # server-side) stay accessible without an SDK release. Unknown fields are
40
+ # ignored by the typed readers.
41
+ module RawAttributes
42
+ # The raw response hash this model was decoded from.
43
+ def to_h
44
+ @raw_attributes ||= {}
45
+ end
46
+
47
+ # Read one field from the raw response hash, by either its wire (string)
48
+ # or symbol name. Returns `nil` for absent fields; `false` round-trips.
49
+ def [](key)
50
+ raw = to_h
51
+ string_key = key.to_s
52
+ raw.key?(string_key) ? raw[string_key] : raw[key.to_sym]
53
+ end
54
+ end
55
+
25
56
  # Twilio-compatible error body. Surface only — the transport raises a VoiceML::ApiError
26
57
  # subclass with this payload attached as `error.body`.
27
58
  class ErrorBody
@@ -5,6 +5,7 @@ require_relative 'common'
5
5
  module VoiceML
6
6
  # A Twilio-compatible Conference resource.
7
7
  class Conference
8
+ include RawAttributes
8
9
  ATTRIBUTES = %w[
9
10
  sid account_sid friendly_name status region api_version uri
10
11
  date_created date_updated reason_conference_ended
@@ -14,6 +15,7 @@ module VoiceML
14
15
  attr_reader(*ATTRIBUTES.map(&:to_sym))
15
16
 
16
17
  def initialize(attrs = {})
18
+ @raw_attributes = attrs
17
19
  ATTRIBUTES.each do |field|
18
20
  value = attrs.key?(field) ? attrs[field] : attrs[field.to_sym]
19
21
  instance_variable_set("@#{field}", value)
@@ -29,11 +31,13 @@ module VoiceML
29
31
 
30
32
  # Paginated `GET /Conferences` response.
31
33
  class ConferenceList
34
+ include RawAttributes
32
35
  include Pageable
33
36
 
34
37
  attr_reader :conferences
35
38
 
36
39
  def initialize(hash = {})
40
+ @raw_attributes = hash
37
41
  assign_page_fields(hash)
38
42
  @conferences = (hash['conferences'] || []).map { |c| Conference.from_hash(c) }
39
43
  end
@@ -45,6 +49,7 @@ module VoiceML
45
49
 
46
50
  # A participant in a live conference.
47
51
  class Participant
52
+ include RawAttributes
48
53
  ATTRIBUTES = %w[
49
54
  call_sid conference_sid account_sid muted hold coaching call_sid_to_coach queue_time
50
55
  start_conference_on_enter end_conference_on_exit status label
@@ -54,6 +59,7 @@ module VoiceML
54
59
  attr_reader(*ATTRIBUTES.map(&:to_sym))
55
60
 
56
61
  def initialize(attrs = {})
62
+ @raw_attributes = attrs
57
63
  ATTRIBUTES.each do |field|
58
64
  value = attrs.key?(field) ? attrs[field] : attrs[field.to_sym]
59
65
  instance_variable_set("@#{field}", value)
@@ -69,11 +75,13 @@ module VoiceML
69
75
 
70
76
  # Paginated `GET /Conferences/{Sid}/Participants` response.
71
77
  class ParticipantList
78
+ include RawAttributes
72
79
  include Pageable
73
80
 
74
81
  attr_reader :participants
75
82
 
76
83
  def initialize(hash = {})
84
+ @raw_attributes = hash
77
85
  assign_page_fields(hash)
78
86
  @participants = (hash['participants'] || []).map { |p| Participant.from_hash(p) }
79
87
  end