Class IntentResult
What an intent handler hands back.
A result carries up to four independent things, and every consumer takes the parts it understands and ignores the rest:
- a value, which the Shortcuts app pipes into the next action
- a spoken line, which an assistant reads aloud
- a snippet, a small layout shown alongside the answer
- an open route, which continues the interaction inside the app
Nothing is mandatory. IntentResult.ok() is a complete, valid answer meaning
"done, nothing to report".
return IntentResult.value(orderId)
.withDialog("Your coffee is on the way")
.withSnippet(orderCard);
The snippet is a surface, not a Form
A snippet is rendered by the platform while your app may not be on screen, so
it uses the com.codename1.surfaces node catalog and obeys the same
dead-process rule: it serializes to data at the moment you return it. That is
also why there is no way to hand back a Form -- a live component tree has
nowhere to live once the handler returns.
-
Method Summary
Modifier and TypeMethodDescriptionstatic IntentResultA successful result identifying one of the app's nouns, so the platform can offer it as the input to a following action.static IntentResultA failed result.The line for an assistant to speak, or null.The entity produced, or null.The user-visible failure message, or null on success.The route to open, or null.The snippet layout, or null.getValue()The value carried onward, or null.booleanisFailed()True when the handler reported a failure.static IntentResultok()A successful result with nothing to report.static IntentResultA result that opens the app at a route rather than answering in place.static IntentResultA successful result whose only content is a line for the assistant to speak.toString()Returns a string representation of the object.static IntentResultA successful result carrying a value the platform can pipe onward.withDialog(String spoken) Adds the line an assistant speaks.withOpenUrl(String routeUrl) Adds a route to open after the result is presented.withSnippet(SurfaceNode node) Adds a small layout shown alongside the answer.
-
Method Details
-
ok
A successful result with nothing to report. -
value
A successful result carrying a value the platform can pipe onward.
Parameters
value: a String, Number, Boolean or Date
-
spoken
A successful result whose only content is a line for the assistant to speak. Shorthand for
ok().withDialog(spoken).Parameters
spoken: the line to speak
-
entity
A successful result identifying one of the app's nouns, so the platform can offer it as the input to a following action.
Parameters
e: the entity produced
-
opens
A result that opens the app at a route rather than answering in place.
The URL is resolved through the same
com.codename1.annotations.Routetable that handles deep links, so an intent and a link to the same screen stay in agreement by construction.Parameters
routeUrl: the route to navigate to, e.g./orders/42
-
failed
A failed result. The message is shown or spoken to the user, so write it for them rather than for a log.
Parameters
userVisibleMessage: what went wrong, in the user's terms
-
withDialog
Adds the line an assistant speaks.
Parameters
spoken: the line to speak
Returns
this result, for chaining
-
withSnippet
Adds a small layout shown alongside the answer.
Parameters
node: the surface node tree to render
Returns
this result, for chaining
-
withOpenUrl
Adds a route to open after the result is presented.
Parameters
routeUrl: the route to navigate to
Returns
this result, for chaining
-
isFailed
public boolean isFailed()True when the handler reported a failure. -
getErrorMessage
The user-visible failure message, or null on success. -
getValue
The value carried onward, or null. -
getDialog
The line for an assistant to speak, or null. -
getSnippet
The snippet layout, or null. -
getOpenUrl
The route to open, or null. -
getEntity
The entity produced, or null. -
toString
Description copied from class:ObjectReturns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
-