Class: Twilio::REST::Conversations::V1::ServiceContext::ConversationContext::MessageContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb,
lib/twilio-ruby/rest/conversations/v1/service/conversation/message/delivery_receipt.rb

Defined Under Namespace

Classes: DeliveryReceiptContext, DeliveryReceiptInstance, DeliveryReceiptList, DeliveryReceiptPage

Instance Method Summary collapse

Constructor Details

#initialize(version, chat_service_sid, conversation_sid, sid) ⇒ MessageContext

Initialize the MessageContext

Parameters:

  • version (Version)

    Version that contains the resource

  • chat_service_sid (String)

    The SID of the Conversation Service the Participant resource is associated with.

  • conversation_sid (String)

    The unique ID of the Conversation for this message.

  • sid (String)

    A 34 character string that uniquely identifies this resource.


212
213
214
215
216
217
218
219
220
221
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 212

def initialize(version, chat_service_sid, conversation_sid, sid)
  super(version)

  # Path Solution
  @solution = {chat_service_sid: chat_service_sid, conversation_sid: conversation_sid, sid: sid, }
  @uri = "/Services/#{@solution[:chat_service_sid]}/Conversations/#{@solution[:conversation_sid]}/Messages/#{@solution[:sid]}"

  # Dependents
  @delivery_receipts = nil
end

Instance Method Details

#delete(x_twilio_webhook_enabled: :unset) ⇒ Boolean

Delete the MessageInstance

Parameters:

  • x_twilio_webhook_enabled (message.WebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:

  • (Boolean)

    true if delete succeeds, false otherwise


264
265
266
267
268
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 264

def delete(x_twilio_webhook_enabled: :unset)
  headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })

   @version.delete('DELETE', @uri, headers: headers)
end

#delivery_receipts(sid = :unset) ⇒ DeliveryReceiptList, DeliveryReceiptContext

Access the delivery_receipts

Returns:

Raises:

  • (ArgumentError)

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 289

def delivery_receipts(sid=:unset)
  raise ArgumentError, 'sid cannot be nil' if sid.nil?

  if sid != :unset
    return DeliveryReceiptContext.new(
        @version,
        @solution[:chat_service_sid],
        @solution[:conversation_sid],
        @solution[:sid],
        sid,
    )
  end

  unless @delivery_receipts
    @delivery_receipts = DeliveryReceiptList.new(
        @version,
        chat_service_sid: @solution[:chat_service_sid],
        conversation_sid: @solution[:conversation_sid],
        message_sid: @solution[:sid],
    )
  end

  @delivery_receipts
end

#fetchMessageInstance

Fetch the MessageInstance

Returns:


273
274
275
276
277
278
279
280
281
282
283
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 273

def fetch
  payload = @version.fetch('GET', @uri)

  MessageInstance.new(
      @version,
      payload,
      chat_service_sid: @solution[:chat_service_sid],
      conversation_sid: @solution[:conversation_sid],
      sid: @solution[:sid],
  )
end

#inspectObject

Provide a detailed, user friendly representation


323
324
325
326
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 323

def inspect
  context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
  "#<Twilio.Conversations.V1.MessageContext #{context}>"
end

#to_sObject

Provide a user friendly representation


316
317
318
319
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 316

def to_s
  context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
  "#<Twilio.Conversations.V1.MessageContext #{context}>"
end

#update(author: :unset, body: :unset, date_created: :unset, date_updated: :unset, attributes: :unset, x_twilio_webhook_enabled: :unset) ⇒ MessageInstance

Update the MessageInstance

Parameters:

  • author (String) (defaults to: :unset)

    The channel specific identifier of the message's author. Defaults to `system`.

  • body (String) (defaults to: :unset)

    The content of the message, can be up to 1,600 characters long.

  • date_created (Time) (defaults to: :unset)

    The date that this resource was created.

  • date_updated (Time) (defaults to: :unset)

    The date that this resource was last updated. `null` if the message has not been edited.

  • attributes (String) (defaults to: :unset)

    A string metadata field you can use to store any data you wish. The string value must contain structurally valid JSON if specified. Note that if the attributes are not set “{}” will be returned.

  • x_twilio_webhook_enabled (message.WebhookEnabledType) (defaults to: :unset)

    The X-Twilio-Webhook-Enabled HTTP request header

Returns:


238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/twilio-ruby/rest/conversations/v1/service/conversation/message.rb', line 238

def update(author: :unset, body: :unset, date_created: :unset, date_updated: :unset, attributes: :unset, x_twilio_webhook_enabled: :unset)
  data = Twilio::Values.of({
      'Author' => author,
      'Body' => body,
      'DateCreated' => Twilio.serialize_iso8601_datetime(date_created),
      'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated),
      'Attributes' => attributes,
  })
  headers = Twilio::Values.of({'X-Twilio-Webhook-Enabled' => x_twilio_webhook_enabled, })

  payload = @version.update('POST', @uri, data: data, headers: headers)

  MessageInstance.new(
      @version,
      payload,
      chat_service_sid: @solution[:chat_service_sid],
      conversation_sid: @solution[:conversation_sid],
      sid: @solution[:sid],
  )
end