メニュー

Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Building Tasks with Autopilot Actions

Actions are how you program the Tasks that your Autopilot virtual assistant performs. Actions will be executed once a user invokes a Task during the dialogue. A user can land on a task by being routed by the natural language router or by being redirected from another task.

Actions can be any of the following:

  • say - instructs Autopilot what to speak or text back to the end user.
  • collect - instructs Autopilot to collect data from the user in a conversational form.
  • listen -instructs Autopilot listen for user input, perform the natural language analysis and route to the corresponding task.
  • redirect - instructs Autopilot to redirect the Dialogue to the specified task.
  • handoff - hands off the session to a TwiML voice URL or TaskRouter queue.
  • remember - instructs Autopilot to store a key-value pair.
  • show - instructs Autopilot to render back visual content to devices with screens.

Every time a Task is invoked, Autopilot will execute the Actions for that Task. Actions are defined in a JSON array where each action is an object in the array. The array is then executed sequentially.

Autopilot Actions workflow

Actions allow you to write one conversational app that works across different channels: Twilio Programmable Voice, Twilio Programmable SMS, Alexa, Google Assistant, or Slack.

Action Execution

Actions are executed sequentially in the context of a Dialogue and a Task until there are no more Actions or a transitional action is found.

Say, Show and Remember are executed sequentially. Once any of these actions are executed the Autopilot continues to the next one.

Redirect, Collect and handoff are transitional actions that change the flow of the dialogue, therefore any task defined after any of these actions in the same JSON document will not be executed.

Allowed Sequences

The following sequences are allowed in the same JSON document

  • Say, Show, or Remember (in any order)
    • Executes the Say/Show/Remember actions then dialogue will end.
  • Say, Show or Remember (in any order) then Redirect
    • Executes the Say/Show/Remember actions then redirect to the specified task or URL.
  • Say, Show or Remember (in any order) then Collect
    • Executes the Say/Show/Remember actions then starts executing the Collect data collection task.
  • Say, Show or Remember (in any order) then Handoff
    • Executes the Say/Show/Remember actions then hands off to a human.

Invalid Sequences

  • Redirect, Handoff, or Collect then Say, Show or Remember
    • The Say/Show/Remember actions will never execute as the dialogue is redirected to another task or URL by the Redirect action.
  • Redirect or Collect then Handoff
    • The Handoff will never execute as the dialogue is redirected to another task or URL by the Redirect action.
  • Collect -> Redirect
    • The Redirect will never execute as the dialogue is redirected to another task or URL by the Collect on_complete Redirect.

Task Context

All Autopilot Actions are executed within the context of a task. This context changes when:

  • A "redirect":"task://another-task" is used to redirect to another task.
  • A Collect is used to do data collection and on complete executes a Redirect action to another Task
  • A Listen action is executed and the user is routed to a different task.

The context of the task does not change when:

  • A "redirect":"https://myapp.com/actions" is used to fetch more actions or build conditional logic. These are executed within the context of the same task.

Dialogue termination

A Dialogue is terminated when one of the following happens

  • There are no more Actions to execute in the JSON and there are no transitional Actions (Redirect, Collect, or Handoff).
  • When a call is hung up by the user, the dialogue is terminated
  • In messaging channels, if the user does not respond within 4 hours, the dialogue times out and is terminated.
  • A Handoff action is used, the assistant hands off the session and ends the dialogue.

Actions JSON Schema

All the actions are defined in the following JSON Schema:

https://carnelian-neanderthal-8008.twil.io/assets/ActionsSchema.json

Follow this link to see the schema in full.

Example Actions JSON

{
	"actions": [
		{
			"say": "Hi there! I'm Jaimie your new Assistant. How can I help you"
		},
		{
			"listen": true
		}
	]
}

Create and Update Actions via the API

Leverage the Task Action Resource to create and update your assistant's task actions via the API.

Rate this page:

ヘルプが必要ですか?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.