twilio-ruby 5.39.1 → 5.40.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGES.md +101 -1
  4. data/CONTRIBUTING.md +2 -2
  5. data/ISSUE_TEMPLATE.md +5 -1
  6. data/Makefile +1 -1
  7. data/PULL_REQUEST_TEMPLATE.md +1 -1
  8. data/README.md +4 -3
  9. data/lib/twilio-ruby/framework/version.rb +2 -7
  10. data/lib/twilio-ruby/rest/api/v2010/account/application.rb +6 -4
  11. data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/local.rb +3 -3
  12. data/lib/twilio-ruby/rest/api/v2010/account/call/payment.rb +79 -60
  13. data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/local.rb +14 -0
  14. data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/mobile.rb +14 -0
  15. data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/toll_free.rb +14 -0
  16. data/lib/twilio-ruby/rest/client.rb +7 -0
  17. data/lib/twilio-ruby/rest/conversations.rb +52 -0
  18. data/lib/twilio-ruby/rest/conversations/v1.rb +88 -1
  19. data/lib/twilio-ruby/rest/conversations/v1/configuration.rb +258 -0
  20. data/lib/twilio-ruby/rest/conversations/v1/conversation.rb +15 -4
  21. data/lib/twilio-ruby/rest/conversations/v1/conversation/message/delivery_receipt.rb +19 -10
  22. data/lib/twilio-ruby/rest/conversations/v1/conversation/participant.rb +12 -2
  23. data/lib/twilio-ruby/rest/conversations/v1/credential.rb +427 -0
  24. data/lib/twilio-ruby/rest/conversations/v1/notification.rb +310 -0
  25. data/lib/twilio-ruby/rest/conversations/v1/role.rb +372 -0
  26. data/lib/twilio-ruby/rest/conversations/v1/service.rb +442 -0
  27. data/lib/twilio-ruby/rest/conversations/v1/service/binding.rb +385 -0
  28. data/lib/twilio-ruby/rest/conversations/v1/service/configuration.rb +259 -0
  29. data/lib/twilio-ruby/rest/conversations/v1/service/conversation.rb +586 -0
  30. data/lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb +546 -0
  31. data/lib/twilio-ruby/rest/conversations/v1/service/conversation/message/delivery_receipt.rb +388 -0
  32. data/lib/twilio-ruby/rest/conversations/v1/service/conversation/participant.rb +513 -0
  33. data/lib/twilio-ruby/rest/conversations/v1/service/conversation/webhook.rb +454 -0
  34. data/lib/twilio-ruby/rest/conversations/v1/service/role.rb +393 -0
  35. data/lib/twilio-ruby/rest/conversations/v1/service/user.rb +419 -0
  36. data/lib/twilio-ruby/rest/conversations/v1/user.rb +398 -0
  37. data/lib/twilio-ruby/rest/events.rb +63 -0
  38. data/lib/twilio-ruby/rest/events/v1.rb +74 -0
  39. data/lib/twilio-ruby/rest/events/v1/event_type.rb +291 -0
  40. data/lib/twilio-ruby/rest/events/v1/sink.rb +380 -0
  41. data/lib/twilio-ruby/rest/events/v1/sink/sink_test.rb +115 -0
  42. data/lib/twilio-ruby/rest/events/v1/sink/sink_validate.rb +119 -0
  43. data/lib/twilio-ruby/rest/events/v1/subscription.rb +363 -0
  44. data/lib/twilio-ruby/rest/events/v1/subscription/subscribed_event.rb +322 -0
  45. data/lib/twilio-ruby/rest/messaging.rb +6 -0
  46. data/lib/twilio-ruby/rest/messaging/v1.rb +7 -0
  47. data/lib/twilio-ruby/rest/messaging/v1/deactivation.rb +164 -0
  48. data/lib/twilio-ruby/rest/numbers/v2/regulatory_compliance.rb +3 -3
  49. data/lib/twilio-ruby/rest/numbers/v2/regulatory_compliance/end_user.rb +16 -2
  50. data/lib/twilio-ruby/rest/numbers/v2/regulatory_compliance/supporting_document.rb +18 -4
  51. data/lib/twilio-ruby/rest/proxy/v1/service/session.rb +45 -4
  52. data/lib/twilio-ruby/rest/proxy/v1/service/session/participant.rb +14 -1
  53. data/lib/twilio-ruby/rest/serverless/v1/service.rb +13 -13
  54. data/lib/twilio-ruby/rest/serverless/v1/service/asset.rb +6 -6
  55. data/lib/twilio-ruby/rest/serverless/v1/service/asset/asset_version.rb +5 -5
  56. data/lib/twilio-ruby/rest/serverless/v1/service/build.rb +8 -8
  57. data/lib/twilio-ruby/rest/serverless/v1/service/environment.rb +6 -8
  58. data/lib/twilio-ruby/rest/serverless/v1/service/environment/deployment.rb +8 -8
  59. data/lib/twilio-ruby/rest/serverless/v1/service/environment/variable.rb +14 -14
  60. data/lib/twilio-ruby/rest/serverless/v1/service/function.rb +4 -4
  61. data/lib/twilio-ruby/rest/serverless/v1/service/function/function_version.rb +7 -7
  62. data/lib/twilio-ruby/rest/serverless/v1/service/function/function_version/function_version_content.rb +1 -1
  63. data/lib/twilio-ruby/rest/supersim/v1/fleet.rb +12 -11
  64. data/lib/twilio-ruby/rest/supersim/v1/sim.rb +39 -9
  65. data/lib/twilio-ruby/rest/supersim/v1/usage_record.rb +75 -9
  66. data/lib/twilio-ruby/rest/taskrouter/v1/workspace/activity.rb +2 -1
  67. data/lib/twilio-ruby/rest/trunking/v1/trunk.rb +25 -3
  68. data/lib/twilio-ruby/rest/verify/v2/service.rb +21 -9
  69. data/lib/twilio-ruby/rest/verify/v2/service/entity/challenge.rb +10 -2
  70. data/lib/twilio-ruby/rest/verify/v2/service/verification.rb +4 -1
  71. data/lib/twilio-ruby/rest/video/v1/room/room_participant/room_participant_subscribe_rule.rb +0 -6
  72. data/lib/twilio-ruby/rest/wireless/v1/sim/data_session.rb +5 -19
  73. data/lib/twilio-ruby/version.rb +1 -1
  74. data/spec/framework/version_spec.rb +42 -0
  75. data/spec/holodeck/holodeck.rb +3 -3
  76. data/spec/integration/api/v2010/account/incoming_phone_number/local_spec.rb +35 -36
  77. data/spec/integration/api/v2010/account/incoming_phone_number/mobile_spec.rb +39 -40
  78. data/spec/integration/api/v2010/account/incoming_phone_number/toll_free_spec.rb +35 -36
  79. data/spec/integration/api/v2010/account/incoming_phone_number_spec.rb +25 -23
  80. data/spec/integration/api/v2010/account/message_spec.rb +37 -0
  81. data/spec/integration/bulkexports/v1/export/day_spec.rb +5 -5
  82. data/spec/integration/bulkexports/v1/export_configuration_spec.rb +4 -4
  83. data/spec/integration/bulkexports/v1/export_spec.rb +3 -3
  84. data/spec/integration/conversations/v1/configuration_spec.rb +85 -0
  85. data/spec/integration/conversations/v1/conversation/message/delivery_receipt_spec.rb +4 -0
  86. data/spec/integration/conversations/v1/conversation/message_spec.rb +38 -0
  87. data/spec/integration/conversations/v1/conversation/participant_spec.rb +60 -4
  88. data/spec/integration/conversations/v1/conversation_spec.rb +35 -0
  89. data/spec/integration/conversations/v1/credential_spec.rb +219 -0
  90. data/spec/integration/conversations/v1/notification_spec.rb +107 -0
  91. data/spec/integration/conversations/v1/role_spec.rb +249 -0
  92. data/spec/integration/conversations/v1/service/binding_spec.rb +166 -0
  93. data/spec/integration/conversations/v1/service/configuration_spec.rb +87 -0
  94. data/spec/integration/conversations/v1/service/conversation/message/delivery_receipt_spec.rb +144 -0
  95. data/spec/integration/conversations/v1/service/conversation/message_spec.rb +429 -0
  96. data/spec/integration/conversations/v1/service/conversation/participant_spec.rb +407 -0
  97. data/spec/integration/conversations/v1/service/conversation/webhook_spec.rb +299 -0
  98. data/spec/integration/conversations/v1/service/conversation_spec.rb +289 -0
  99. data/spec/integration/conversations/v1/service/role_spec.rb +260 -0
  100. data/spec/integration/conversations/v1/service/user_spec.rb +230 -0
  101. data/spec/integration/conversations/v1/service_spec.rb +174 -0
  102. data/spec/integration/conversations/v1/user_spec.rb +220 -0
  103. data/spec/integration/events/v1/event_type_spec.rb +133 -0
  104. data/spec/integration/events/v1/sink/sink_test_spec.rb +42 -0
  105. data/spec/integration/events/v1/sink/sink_validate_spec.rb +44 -0
  106. data/spec/integration/events/v1/sink_spec.rb +217 -0
  107. data/spec/integration/events/v1/subscription/subscribed_event_spec.rb +212 -0
  108. data/spec/integration/events/v1/subscription_spec.rb +205 -0
  109. data/spec/integration/messaging/v1/deactivation_spec.rb +40 -0
  110. data/spec/integration/numbers/v2/regulatory_compliance/end_user_spec.rb +27 -0
  111. data/spec/integration/numbers/v2/regulatory_compliance/supporting_document_spec.rb +27 -0
  112. data/spec/integration/studio/v1/flow/execution/execution_step_spec.rb +1 -0
  113. data/spec/integration/studio/v2/flow/execution/execution_step_spec.rb +1 -0
  114. data/spec/integration/supersim/v1/sim_spec.rb +23 -0
  115. data/spec/integration/supersim/v1/usage_record_spec.rb +463 -18
  116. data/spec/integration/trunking/v1/trunk_spec.rb +4 -0
  117. data/spec/integration/verify/v2/service/access_token_spec.rb +1 -1
  118. data/spec/integration/verify/v2/service/entity/challenge_spec.rb +8 -8
  119. data/spec/integration/video/v1/room_spec.rb +37 -0
  120. data/spec/integration/wireless/v1/sim/data_session_spec.rb +2 -2
  121. data/spec/spec_helper.rb +1 -1
  122. metadata +70 -2
@@ -0,0 +1,546 @@
1
+ ##
2
+ # This code was generated by
3
+ # \ / _ _ _| _ _
4
+ # | (_)\/(_)(_|\/| |(/_ v1.0.0
5
+ # / /
6
+ #
7
+ # frozen_string_literal: true
8
+
9
+ module Twilio
10
+ module REST
11
+ class Conversations < Domain
12
+ class V1 < Version
13
+ class ServiceContext < InstanceContext
14
+ class ConversationContext < InstanceContext
15
+ ##
16
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
17
+ class MessageList < ListResource
18
+ ##
19
+ # Initialize the MessageList
20
+ # @param [Version] version Version that contains the resource
21
+ # @param [String] chat_service_sid The SID of the [Chat
22
+ # Service](https://www.twilio.com/docs/chat/rest/service-resource) the Participant
23
+ # resource is associated with.
24
+ # @param [String] conversation_sid The unique id of the
25
+ # [Conversation](https://www.twilio.com/docs/conversations/api/conversation-resource) for this message.
26
+ # @return [MessageList] MessageList
27
+ def initialize(version, chat_service_sid: nil, conversation_sid: nil)
28
+ super(version)
29
+
30
+ # Path Solution
31
+ @solution = {chat_service_sid: chat_service_sid, conversation_sid: conversation_sid}
32
+ @uri = "/Services/#{@solution[:chat_service_sid]}/Conversations/#{@solution[:conversation_sid]}/Messages"
33
+ end
34
+
35
+ ##
36
+ # Create the MessageInstance
37
+ # @param [String] author The channel specific identifier of the message's author.
38
+ # Defaults to `system`.
39
+ # @param [String] body The content of the message, can be up to 1,600 characters
40
+ # long.
41
+ # @param [Time] date_created The date that this resource was created.
42
+ # @param [Time] date_updated The date that this resource was last updated. `null`
43
+ # if the message has not been edited.
44
+ # @param [String] attributes A string metadata field you can use to store any data
45
+ # you wish. The string value must contain structurally valid JSON if specified.
46
+ # **Note** that if the attributes are not set "{}" will be returned.
47
+ # @param [String] media_sid The Media Sid to be attached to the new Message.
48
+ # @param [message.WebhookEnabledType] x_twilio_webhook_enabled The
49
+ # X-Twilio-Webhook-Enabled HTTP request header
50
+ # @return [MessageInstance] Created MessageInstance
51
+ def create(author: :unset, body: :unset, date_created: :unset, date_updated: :unset, attributes: :unset, media_sid: :unset, x_twilio_webhook_enabled: :unset)
52
+ data = Twilio::Values.of({
53
+ 'Author' => author,
54
+ 'Body' => body,
55
+ 'DateCreated' => Twilio.serialize_iso8601_datetime(date_created),
56
+ 'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated),
57
+ 'Attributes' => attributes,
58
+ 'MediaSid' => media_sid,
59
+ })
60
+ headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })
61
+
62
+ payload = @version.create('POST', @uri, data: data, headers: headers)
63
+
64
+ MessageInstance.new(
65
+ @version,
66
+ payload,
67
+ chat_service_sid: @solution[:chat_service_sid],
68
+ conversation_sid: @solution[:conversation_sid],
69
+ )
70
+ end
71
+
72
+ ##
73
+ # Lists MessageInstance records from the API as a list.
74
+ # Unlike stream(), this operation is eager and will load `limit` records into
75
+ # memory before returning.
76
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
77
+ # guarantees to never return more than limit. Default is no limit
78
+ # @param [Integer] page_size Number of records to fetch per request, when
79
+ # not set will use the default value of 50 records. If no page_size is defined
80
+ # but a limit is defined, stream() will attempt to read the limit with the most
81
+ # efficient page size, i.e. min(limit, 1000)
82
+ # @return [Array] Array of up to limit results
83
+ def list(limit: nil, page_size: nil)
84
+ self.stream(limit: limit, page_size: page_size).entries
85
+ end
86
+
87
+ ##
88
+ # Streams MessageInstance records from the API as an Enumerable.
89
+ # This operation lazily loads records as efficiently as possible until the limit
90
+ # is reached.
91
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
92
+ # guarantees to never return more than limit. Default is no limit.
93
+ # @param [Integer] page_size Number of records to fetch per request, when
94
+ # not set will use the default value of 50 records. If no page_size is defined
95
+ # but a limit is defined, stream() will attempt to read the limit with the most
96
+ # efficient page size, i.e. min(limit, 1000)
97
+ # @return [Enumerable] Enumerable that will yield up to limit results
98
+ def stream(limit: nil, page_size: nil)
99
+ limits = @version.read_limits(limit, page_size)
100
+
101
+ page = self.page(page_size: limits[:page_size], )
102
+
103
+ @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
104
+ end
105
+
106
+ ##
107
+ # When passed a block, yields MessageInstance records from the API.
108
+ # This operation lazily loads records as efficiently as possible until the limit
109
+ # is reached.
110
+ def each
111
+ limits = @version.read_limits
112
+
113
+ page = self.page(page_size: limits[:page_size], )
114
+
115
+ @version.stream(page,
116
+ limit: limits[:limit],
117
+ page_limit: limits[:page_limit]).each {|x| yield x}
118
+ end
119
+
120
+ ##
121
+ # Retrieve a single page of MessageInstance records from the API.
122
+ # Request is executed immediately.
123
+ # @param [String] page_token PageToken provided by the API
124
+ # @param [Integer] page_number Page Number, this value is simply for client state
125
+ # @param [Integer] page_size Number of records to return, defaults to 50
126
+ # @return [Page] Page of MessageInstance
127
+ def page(page_token: :unset, page_number: :unset, page_size: :unset)
128
+ params = Twilio::Values.of({
129
+ 'PageToken' => page_token,
130
+ 'Page' => page_number,
131
+ 'PageSize' => page_size,
132
+ })
133
+
134
+ response = @version.page('GET', @uri, params: params)
135
+
136
+ MessagePage.new(@version, response, @solution)
137
+ end
138
+
139
+ ##
140
+ # Retrieve a single page of MessageInstance records from the API.
141
+ # Request is executed immediately.
142
+ # @param [String] target_url API-generated URL for the requested results page
143
+ # @return [Page] Page of MessageInstance
144
+ def get_page(target_url)
145
+ response = @version.domain.request(
146
+ 'GET',
147
+ target_url
148
+ )
149
+ MessagePage.new(@version, response, @solution)
150
+ end
151
+
152
+ ##
153
+ # Provide a user friendly representation
154
+ def to_s
155
+ '#<Twilio.Conversations.V1.MessageList>'
156
+ end
157
+ end
158
+
159
+ ##
160
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
161
+ class MessagePage < Page
162
+ ##
163
+ # Initialize the MessagePage
164
+ # @param [Version] version Version that contains the resource
165
+ # @param [Response] response Response from the API
166
+ # @param [Hash] solution Path solution for the resource
167
+ # @return [MessagePage] MessagePage
168
+ def initialize(version, response, solution)
169
+ super(version, response)
170
+
171
+ # Path Solution
172
+ @solution = solution
173
+ end
174
+
175
+ ##
176
+ # Build an instance of MessageInstance
177
+ # @param [Hash] payload Payload response from the API
178
+ # @return [MessageInstance] MessageInstance
179
+ def get_instance(payload)
180
+ MessageInstance.new(
181
+ @version,
182
+ payload,
183
+ chat_service_sid: @solution[:chat_service_sid],
184
+ conversation_sid: @solution[:conversation_sid],
185
+ )
186
+ end
187
+
188
+ ##
189
+ # Provide a user friendly representation
190
+ def to_s
191
+ '<Twilio.Conversations.V1.MessagePage>'
192
+ end
193
+ end
194
+
195
+ ##
196
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
197
+ class MessageContext < InstanceContext
198
+ ##
199
+ # Initialize the MessageContext
200
+ # @param [Version] version Version that contains the resource
201
+ # @param [String] chat_service_sid The SID of the [Chat
202
+ # Service](https://www.twilio.com/docs/chat/rest/service-resource) the Participant
203
+ # resource is associated with.
204
+ # @param [String] conversation_sid The unique id of the
205
+ # [Conversation](https://www.twilio.com/docs/conversations/api/conversation-resource) for this message.
206
+ # @param [String] sid A 34 character string that uniquely identifies this
207
+ # resource.
208
+ # @return [MessageContext] MessageContext
209
+ def initialize(version, chat_service_sid, conversation_sid, sid)
210
+ super(version)
211
+
212
+ # Path Solution
213
+ @solution = {chat_service_sid: chat_service_sid, conversation_sid: conversation_sid, sid: sid, }
214
+ @uri = "/Services/#{@solution[:chat_service_sid]}/Conversations/#{@solution[:conversation_sid]}/Messages/#{@solution[:sid]}"
215
+
216
+ # Dependents
217
+ @delivery_receipts = nil
218
+ end
219
+
220
+ ##
221
+ # Update the MessageInstance
222
+ # @param [String] author The channel specific identifier of the message's author.
223
+ # Defaults to `system`.
224
+ # @param [String] body The content of the message, can be up to 1,600 characters
225
+ # long.
226
+ # @param [Time] date_created The date that this resource was created.
227
+ # @param [Time] date_updated The date that this resource was last updated. `null`
228
+ # if the message has not been edited.
229
+ # @param [String] attributes A string metadata field you can use to store any data
230
+ # you wish. The string value must contain structurally valid JSON if specified.
231
+ # **Note** that if the attributes are not set "{}" will be returned.
232
+ # @param [message.WebhookEnabledType] x_twilio_webhook_enabled The
233
+ # X-Twilio-Webhook-Enabled HTTP request header
234
+ # @return [MessageInstance] Updated MessageInstance
235
+ def update(author: :unset, body: :unset, date_created: :unset, date_updated: :unset, attributes: :unset, x_twilio_webhook_enabled: :unset)
236
+ data = Twilio::Values.of({
237
+ 'Author' => author,
238
+ 'Body' => body,
239
+ 'DateCreated' => Twilio.serialize_iso8601_datetime(date_created),
240
+ 'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated),
241
+ 'Attributes' => attributes,
242
+ })
243
+ headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })
244
+
245
+ payload = @version.update('POST', @uri, data: data, headers: headers)
246
+
247
+ MessageInstance.new(
248
+ @version,
249
+ payload,
250
+ chat_service_sid: @solution[:chat_service_sid],
251
+ conversation_sid: @solution[:conversation_sid],
252
+ sid: @solution[:sid],
253
+ )
254
+ end
255
+
256
+ ##
257
+ # Delete the MessageInstance
258
+ # @param [message.WebhookEnabledType] x_twilio_webhook_enabled The
259
+ # X-Twilio-Webhook-Enabled HTTP request header
260
+ # @return [Boolean] true if delete succeeds, false otherwise
261
+ def delete(x_twilio_webhook_enabled: :unset)
262
+ headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })
263
+
264
+ @version.delete('DELETE', @uri, headers: headers)
265
+ end
266
+
267
+ ##
268
+ # Fetch the MessageInstance
269
+ # @return [MessageInstance] Fetched MessageInstance
270
+ def fetch
271
+ payload = @version.fetch('GET', @uri)
272
+
273
+ MessageInstance.new(
274
+ @version,
275
+ payload,
276
+ chat_service_sid: @solution[:chat_service_sid],
277
+ conversation_sid: @solution[:conversation_sid],
278
+ sid: @solution[:sid],
279
+ )
280
+ end
281
+
282
+ ##
283
+ # Access the delivery_receipts
284
+ # @return [DeliveryReceiptList]
285
+ # @return [DeliveryReceiptContext] if sid was passed.
286
+ def delivery_receipts(sid=:unset)
287
+ raise ArgumentError, 'sid cannot be nil' if sid.nil?
288
+
289
+ if sid != :unset
290
+ return DeliveryReceiptContext.new(
291
+ @version,
292
+ @solution[:chat_service_sid],
293
+ @solution[:conversation_sid],
294
+ @solution[:sid],
295
+ sid,
296
+ )
297
+ end
298
+
299
+ unless @delivery_receipts
300
+ @delivery_receipts = DeliveryReceiptList.new(
301
+ @version,
302
+ chat_service_sid: @solution[:chat_service_sid],
303
+ conversation_sid: @solution[:conversation_sid],
304
+ message_sid: @solution[:sid],
305
+ )
306
+ end
307
+
308
+ @delivery_receipts
309
+ end
310
+
311
+ ##
312
+ # Provide a user friendly representation
313
+ def to_s
314
+ context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
315
+ "#<Twilio.Conversations.V1.MessageContext #{context}>"
316
+ end
317
+
318
+ ##
319
+ # Provide a detailed, user friendly representation
320
+ def inspect
321
+ context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
322
+ "#<Twilio.Conversations.V1.MessageContext #{context}>"
323
+ end
324
+ end
325
+
326
+ ##
327
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
328
+ class MessageInstance < InstanceResource
329
+ ##
330
+ # Initialize the MessageInstance
331
+ # @param [Version] version Version that contains the resource
332
+ # @param [Hash] payload payload that contains response from Twilio
333
+ # @param [String] chat_service_sid The SID of the [Chat
334
+ # Service](https://www.twilio.com/docs/chat/rest/service-resource) the Participant
335
+ # resource is associated with.
336
+ # @param [String] conversation_sid The unique id of the
337
+ # [Conversation](https://www.twilio.com/docs/conversations/api/conversation-resource) for this message.
338
+ # @param [String] sid A 34 character string that uniquely identifies this
339
+ # resource.
340
+ # @return [MessageInstance] MessageInstance
341
+ def initialize(version, payload, chat_service_sid: nil, conversation_sid: nil, sid: nil)
342
+ super(version)
343
+
344
+ # Marshaled Properties
345
+ @properties = {
346
+ 'account_sid' => payload['account_sid'],
347
+ 'chat_service_sid' => payload['chat_service_sid'],
348
+ 'conversation_sid' => payload['conversation_sid'],
349
+ 'sid' => payload['sid'],
350
+ 'index' => payload['index'].to_i,
351
+ 'author' => payload['author'],
352
+ 'body' => payload['body'],
353
+ 'media' => payload['media'],
354
+ 'attributes' => payload['attributes'],
355
+ 'participant_sid' => payload['participant_sid'],
356
+ 'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']),
357
+ 'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']),
358
+ 'delivery' => payload['delivery'],
359
+ 'url' => payload['url'],
360
+ 'links' => payload['links'],
361
+ }
362
+
363
+ # Context
364
+ @instance_context = nil
365
+ @params = {
366
+ 'chat_service_sid' => chat_service_sid,
367
+ 'conversation_sid' => conversation_sid,
368
+ 'sid' => sid || @properties['sid'],
369
+ }
370
+ end
371
+
372
+ ##
373
+ # Generate an instance context for the instance, the context is capable of
374
+ # performing various actions. All instance actions are proxied to the context
375
+ # @return [MessageContext] MessageContext for this MessageInstance
376
+ def context
377
+ unless @instance_context
378
+ @instance_context = MessageContext.new(
379
+ @version,
380
+ @params['chat_service_sid'],
381
+ @params['conversation_sid'],
382
+ @params['sid'],
383
+ )
384
+ end
385
+ @instance_context
386
+ end
387
+
388
+ ##
389
+ # @return [String] The unique id of the Account responsible for this message.
390
+ def account_sid
391
+ @properties['account_sid']
392
+ end
393
+
394
+ ##
395
+ # @return [String] The SID of the Chat Service that the resource is associated with.
396
+ def chat_service_sid
397
+ @properties['chat_service_sid']
398
+ end
399
+
400
+ ##
401
+ # @return [String] The unique id of the Conversation for this message.
402
+ def conversation_sid
403
+ @properties['conversation_sid']
404
+ end
405
+
406
+ ##
407
+ # @return [String] A 34 character string that uniquely identifies this resource.
408
+ def sid
409
+ @properties['sid']
410
+ end
411
+
412
+ ##
413
+ # @return [String] The index of the message within the Conversation.
414
+ def index
415
+ @properties['index']
416
+ end
417
+
418
+ ##
419
+ # @return [String] The channel specific identifier of the message's author.
420
+ def author
421
+ @properties['author']
422
+ end
423
+
424
+ ##
425
+ # @return [String] The content of the message.
426
+ def body
427
+ @properties['body']
428
+ end
429
+
430
+ ##
431
+ # @return [Hash] An array of objects that describe the Message's media if attached, otherwise, null.
432
+ def media
433
+ @properties['media']
434
+ end
435
+
436
+ ##
437
+ # @return [String] A string metadata field you can use to store any data you wish.
438
+ def attributes
439
+ @properties['attributes']
440
+ end
441
+
442
+ ##
443
+ # @return [String] The unique id of messages's author participant.
444
+ def participant_sid
445
+ @properties['participant_sid']
446
+ end
447
+
448
+ ##
449
+ # @return [Time] The date that this resource was created.
450
+ def date_created
451
+ @properties['date_created']
452
+ end
453
+
454
+ ##
455
+ # @return [Time] The date that this resource was last updated.
456
+ def date_updated
457
+ @properties['date_updated']
458
+ end
459
+
460
+ ##
461
+ # @return [Hash] An object that contains the summary of delivery statuses for the message to non-chat participants.
462
+ def delivery
463
+ @properties['delivery']
464
+ end
465
+
466
+ ##
467
+ # @return [String] An absolute URL for this message.
468
+ def url
469
+ @properties['url']
470
+ end
471
+
472
+ ##
473
+ # @return [String] Absolute URLs to access the Receipts of this Message.
474
+ def links
475
+ @properties['links']
476
+ end
477
+
478
+ ##
479
+ # Update the MessageInstance
480
+ # @param [String] author The channel specific identifier of the message's author.
481
+ # Defaults to `system`.
482
+ # @param [String] body The content of the message, can be up to 1,600 characters
483
+ # long.
484
+ # @param [Time] date_created The date that this resource was created.
485
+ # @param [Time] date_updated The date that this resource was last updated. `null`
486
+ # if the message has not been edited.
487
+ # @param [String] attributes A string metadata field you can use to store any data
488
+ # you wish. The string value must contain structurally valid JSON if specified.
489
+ # **Note** that if the attributes are not set "{}" will be returned.
490
+ # @param [message.WebhookEnabledType] x_twilio_webhook_enabled The
491
+ # X-Twilio-Webhook-Enabled HTTP request header
492
+ # @return [MessageInstance] Updated MessageInstance
493
+ def update(author: :unset, body: :unset, date_created: :unset, date_updated: :unset, attributes: :unset, x_twilio_webhook_enabled: :unset)
494
+ context.update(
495
+ author: author,
496
+ body: body,
497
+ date_created: date_created,
498
+ date_updated: date_updated,
499
+ attributes: attributes,
500
+ x_twilio_webhook_enabled: x_twilio_webhook_enabled,
501
+ )
502
+ end
503
+
504
+ ##
505
+ # Delete the MessageInstance
506
+ # @param [message.WebhookEnabledType] x_twilio_webhook_enabled The
507
+ # X-Twilio-Webhook-Enabled HTTP request header
508
+ # @return [Boolean] true if delete succeeds, false otherwise
509
+ def delete(x_twilio_webhook_enabled: :unset)
510
+ context.delete(x_twilio_webhook_enabled: x_twilio_webhook_enabled, )
511
+ end
512
+
513
+ ##
514
+ # Fetch the MessageInstance
515
+ # @return [MessageInstance] Fetched MessageInstance
516
+ def fetch
517
+ context.fetch
518
+ end
519
+
520
+ ##
521
+ # Access the delivery_receipts
522
+ # @return [delivery_receipts] delivery_receipts
523
+ def delivery_receipts
524
+ context.delivery_receipts
525
+ end
526
+
527
+ ##
528
+ # Provide a user friendly representation
529
+ def to_s
530
+ values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
531
+ "<Twilio.Conversations.V1.MessageInstance #{values}>"
532
+ end
533
+
534
+ ##
535
+ # Provide a detailed, user friendly representation
536
+ def inspect
537
+ values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
538
+ "<Twilio.Conversations.V1.MessageInstance #{values}>"
539
+ end
540
+ end
541
+ end
542
+ end
543
+ end
544
+ end
545
+ end
546
+ end