Class: Twilio::REST::Autopilot::V1::AssistantContext::TaskContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/autopilot/v1/assistant/task.rb,
lib/twilio-ruby/rest/autopilot/v1/assistant/task/field.rb,
lib/twilio-ruby/rest/autopilot/v1/assistant/task/sample.rb,
lib/twilio-ruby/rest/autopilot/v1/assistant/task/task_actions.rb,
lib/twilio-ruby/rest/autopilot/v1/assistant/task/task_statistics.rb

Overview

PLEASE NOTE that this class contains preview products that are subject to change. Use them with caution. If you currently do not have developer preview access, please contact [email protected].

Defined Under Namespace

Classes: FieldContext, FieldInstance, FieldList, FieldPage, SampleContext, SampleInstance, SampleList, SamplePage, TaskActionsContext, TaskActionsInstance, TaskActionsList, TaskActionsPage, TaskStatisticsContext, TaskStatisticsInstance, TaskStatisticsList, TaskStatisticsPage

Instance Method Summary collapse

Constructor Details

#initialize(version, assistant_sid, sid) ⇒ TaskContext

Initialize the TaskContext

Parameters:

  • version (Version)

    Version that contains the resource

  • assistant_sid (String)

    The SID of the [Assistant](www.twilio.com/docs/autopilot/api/assistant) that is the parent of the resource to fetch.

  • sid (String)

    The Twilio-provided string that uniquely identifies the Task resource to fetch.



195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/twilio-ruby/rest/autopilot/v1/assistant/task.rb', line 195

def initialize(version, assistant_sid, sid)
  super(version)

  # Path Solution
  @solution = {assistant_sid: assistant_sid, sid: sid, }
  @uri = "/Assistants/#{@solution[:assistant_sid]}/Tasks/#{@solution[:sid]}"

  # Dependents
  @fields = nil
  @samples = nil
  @task_actions = nil
  @statistics = nil
end

Instance Method Details

#deleteBoolean

Deletes the TaskInstance

Returns:

  • (Boolean)

    true if delete succeeds, true otherwise



257
258
259
# File 'lib/twilio-ruby/rest/autopilot/v1/assistant/task.rb', line 257

def delete
  @version.delete('delete', @uri)
end

#fetchTaskInstance

Fetch a TaskInstance

Returns:



212
213
214
215
216
217
218
219
220
221
222
# File 'lib/twilio-ruby/rest/autopilot/v1/assistant/task.rb', line 212

def fetch
  params = Twilio::Values.of({})

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

  TaskInstance.new(@version, payload, assistant_sid: @solution[:assistant_sid], sid: @solution[:sid], )
end

#fields(sid = :unset) ⇒ FieldList, FieldContext

Access the fields

Returns:

Raises:

  • (ArgumentError)


265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/twilio-ruby/rest/autopilot/v1/assistant/task.rb', line 265

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

  if sid != :unset
    return FieldContext.new(@version, @solution[:assistant_sid], @solution[:sid], sid, )
  end

  unless @fields
    @fields = FieldList.new(
        @version,
        assistant_sid: @solution[:assistant_sid],
        task_sid: @solution[:sid],
    )
  end

  @fields
end

#inspectObject

Provide a detailed, user friendly representation



330
331
332
333
# File 'lib/twilio-ruby/rest/autopilot/v1/assistant/task.rb', line 330

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

#samples(sid = :unset) ⇒ SampleList, SampleContext

Access the samples

Returns:

Raises:

  • (ArgumentError)


287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/twilio-ruby/rest/autopilot/v1/assistant/task.rb', line 287

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

  if sid != :unset
    return SampleContext.new(@version, @solution[:assistant_sid], @solution[:sid], sid, )
  end

  unless @samples
    @samples = SampleList.new(
        @version,
        assistant_sid: @solution[:assistant_sid],
        task_sid: @solution[:sid],
    )
  end

  @samples
end

#statisticsTaskStatisticsList, TaskStatisticsContext

Access the statistics



317
318
319
# File 'lib/twilio-ruby/rest/autopilot/v1/assistant/task.rb', line 317

def statistics
  TaskStatisticsContext.new(@version, @solution[:assistant_sid], @solution[:sid], )
end

#task_actionsTaskActionsList, TaskActionsContext

Access the task_actions



309
310
311
# File 'lib/twilio-ruby/rest/autopilot/v1/assistant/task.rb', line 309

def task_actions
  TaskActionsContext.new(@version, @solution[:assistant_sid], @solution[:sid], )
end

#to_sObject

Provide a user friendly representation



323
324
325
326
# File 'lib/twilio-ruby/rest/autopilot/v1/assistant/task.rb', line 323

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

#update(friendly_name: :unset, unique_name: :unset, actions: :unset, actions_url: :unset) ⇒ TaskInstance

Update the TaskInstance

Parameters:

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

    A descriptive string that you create to describe the resource. It is not unique and can be up to 255 characters long.

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

    An application-defined string that uniquely identifies the resource. This value must be 64 characters or less in length and be unique. It can be used as an alternative to the ‘sid` in the URL path to address the resource.

  • actions (Hash) (defaults to: :unset)

    The JSON string that specifies the [actions](www.twilio.com/docs/autopilot/actions) that instruct the Assistant on how to perform the task.

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

    The URL from which the Assistant can fetch actions.

Returns:



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/twilio-ruby/rest/autopilot/v1/assistant/task.rb', line 237

def update(friendly_name: :unset, unique_name: :unset, actions: :unset, actions_url: :unset)
  data = Twilio::Values.of({
      'FriendlyName' => friendly_name,
      'UniqueName' => unique_name,
      'Actions' => Twilio.serialize_object(actions),
      'ActionsUrl' => actions_url,
  })

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

  TaskInstance.new(@version, payload, assistant_sid: @solution[:assistant_sid], sid: @solution[:sid], )
end