Class: Twilio::REST::Conversations::V2::ActionInstance

Inherits:
InstanceResource show all
Defined in:
lib/twilio-ruby/rest/conversations/v2/action.rb

Instance Method Summary collapse

Constructor Details

#initialize(version, payload, conversation_id: nil, action_id: nil) ⇒ ActionInstance

Initialize the ActionInstance

Parameters:

  • version (Version) —

    Version that contains the resource

  • payload (Hash) —

    payload that contains response from Twilio

  • account_sid (String) —

    The SID of the Account that created this Action resource.

  • sid (String) —

    The SID of the Call resource to fetch.



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/twilio-ruby/rest/conversations/v2/action.rb', line 341

def initialize(version, payload , conversation_id: nil, action_id: nil)
    
    apiV1Version = ApiV1Version.new version.domain, version
    super(apiV1Version)
    
    # Marshaled Properties
    @properties = { 
        'id' => payload['id'],
        'type' => payload['type'],
        'status' => payload['status'],
        'conversation_id' => payload['conversation_id'],
        'related' => payload['related'],
        'created_at' => Twilio.deserialize_iso8601_datetime(payload['created_at']),
        'updated_at' => Twilio.deserialize_iso8601_datetime(payload['updated_at']),
        'completed_at' => Twilio.deserialize_iso8601_datetime(payload['completed_at']),
        'failure_reason' => payload['failure_reason'],
    }

    # Context
    @instance_context = nil
    @params = { 'conversation_id' => conversation_id  || @properties['conversation_id']  ,'action_id' => action_id  || @properties['action_id']  , }
end

Instance Method Details

#completed_at ⇒ Time

Returns Timestamp when the action reached a terminal status.

Returns:

  • (Time) —

    Timestamp when the action reached a terminal status.



419
420
421
# File 'lib/twilio-ruby/rest/conversations/v2/action.rb', line 419

def completed_at
    @properties['completed_at']
end

#context ⇒ ActionContext

Generate an instance context for the instance, the context is capable of performing various actions. All instance actions are proxied to the context

Returns:



368
369
370
371
372
373
# File 'lib/twilio-ruby/rest/conversations/v2/action.rb', line 368

def context
    unless @instance_context
        @instance_context = ActionContext.new(@version , @params['conversation_id'], @params['action_id'])
    end
    @instance_context
end

#conversation_id ⇒ String

Returns The conversation this action belongs to.

Returns:

  • (String) —

    The conversation this action belongs to.



395
396
397
# File 'lib/twilio-ruby/rest/conversations/v2/action.rb', line 395

def conversation_id
    @properties['conversation_id']
end

#created_at ⇒ Time

Returns Timestamp when the action was created.

Returns:

  • (Time) —

    Timestamp when the action was created.



407
408
409
# File 'lib/twilio-ruby/rest/conversations/v2/action.rb', line 407

def created_at
    @properties['created_at']
end

#failure_reason ⇒ String

Returns Human-readable failure reason. Null unless status is FAILED.

Returns:

  • (String) —

    Human-readable failure reason. Null unless status is FAILED.



425
426
427
# File 'lib/twilio-ruby/rest/conversations/v2/action.rb', line 425

def failure_reason
    @properties['failure_reason']
end

#fetch ⇒ ActionInstance

Fetch the ActionInstance

Returns:



432
433
434
435
# File 'lib/twilio-ruby/rest/conversations/v2/action.rb', line 432

def fetch

    context.fetch
end

#id ⇒ String

Returns Unique identifier for this Action.

Returns:

  • (String) —

    Unique identifier for this Action.



377
378
379
# File 'lib/twilio-ruby/rest/conversations/v2/action.rb', line 377

def id
    @properties['id']
end

#inspect ⇒ Object

Provide a detailed, user friendly representation



446
447
448
449
# File 'lib/twilio-ruby/rest/conversations/v2/action.rb', line 446

def inspect
    values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
    "<Twilio.Conversations.V2.ActionInstance #{values}>"
end

Returns Named identifiers from downstream. For SEND_MESSAGE: - messageSid: The downstream message SID (present when PENDING or COMPLETED) - communicationId: The Communication ID (present when COMPLETED) For START_FLOW: - executionSid: The Studio Flow execution SID (present when COMPLETED).

Returns:

  • (Hash<String, String>) —

    Named identifiers from downstream. For SEND_MESSAGE: - messageSid: The downstream message SID (present when PENDING or COMPLETED) - communicationId: The Communication ID (present when COMPLETED) For START_FLOW: - executionSid: The Studio Flow execution SID (present when COMPLETED)



401
402
403
# File 'lib/twilio-ruby/rest/conversations/v2/action.rb', line 401

def related
    @properties['related']
end

#status ⇒ ConversationsV2ActionStatus

Returns:

  • (ConversationsV2ActionStatus)


389
390
391
# File 'lib/twilio-ruby/rest/conversations/v2/action.rb', line 389

def status
    @properties['status']
end

#to_s ⇒ Object

Provide a user friendly representation



439
440
441
442
# File 'lib/twilio-ruby/rest/conversations/v2/action.rb', line 439

def to_s
    values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
    "<Twilio.Conversations.V2.ActionInstance #{values}>"
end

#type ⇒ String

Returns The type of action: action-send-message or action-start-flow.

Returns:

  • (String) —

    The type of action: action-send-message or action-start-flow.



383
384
385
# File 'lib/twilio-ruby/rest/conversations/v2/action.rb', line 383

def type
    @properties['type']
end

#updated_at ⇒ Time

Returns Timestamp when the action was last updated.

Returns:

  • (Time) —

    Timestamp when the action was last updated.



413
414
415
# File 'lib/twilio-ruby/rest/conversations/v2/action.rb', line 413

def updated_at
    @properties['updated_at']
end