public final class IntentResult

  1. Object
  2. 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.

Methods

public static IntentResult ok()A successful result with nothing to report.
public static IntentResult value(Object value)A successful result carrying a value the platform can pipe onward.
public static IntentResult spoken(String spoken)A successful result whose only content is a line for the assistant to speak.
public static IntentResult entity(AppEntity e)A successful result identifying one of the app’s nouns, so the platform can offer it as the input to a following action.
public static IntentResult opens(String routeUrl)A result that opens the app at a route rather than answering in place.
public static IntentResult failed(String userVisibleMessage)A failed result.
public IntentResult withDialog(String spoken)Adds the line an assistant speaks.
public IntentResult withSnippet(SurfaceNode node)Adds a small layout shown alongside the answer.
public IntentResult withOpenUrl(String routeUrl)Adds a route to open after the result is presented.
public boolean isFailed()True when the handler reported a failure.
public String getErrorMessage()The user-visible failure message, or null on success.
public Object getValue()The value carried onward, or null.
public String getDialog()The line for an assistant to speak, or null.
public SurfaceNode getSnippet()The snippet layout, or null.
public String getOpenUrl()The route to open, or null.
public AppEntity getEntity()The entity produced, or null.
public String toString()Returns a string representation of the object.

Inherited methods

Method details

ok

public static IntentResult ok()
A successful result with nothing to report.

value

public static IntentResult value(Object value)
A successful result carrying a value the platform can pipe onward.

Parameters

value Object
a String, Number, Boolean or Date

spoken

public static IntentResult spoken(String spoken)
A successful result whose only content is a line for the assistant to speak. Shorthand for ok().withDialog(spoken).

Parameters

spoken String
the line to speak

entity

public static IntentResult entity(AppEntity e)
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 AppEntity
the entity produced

opens

public static IntentResult opens(String routeUrl)

A result that opens the app at a route rather than answering in place.

The URL is resolved through the same com.codename1.annotations.Route table that handles deep links, so an intent and a link to the same screen stay in agreement by construction.

Parameters

routeUrl String
the route to navigate to, e.g. /orders/42

failed

public static IntentResult failed(String userVisibleMessage)
A failed result. The message is shown or spoken to the user, so write it for them rather than for a log.

Parameters

userVisibleMessage String
what went wrong, in the user’s terms

withDialog

public IntentResult withDialog(String spoken)
Adds the line an assistant speaks.

Parameters

spoken String
the line to speak

Returns

this result, for chaining

withSnippet

public IntentResult withSnippet(SurfaceNode node)
Adds a small layout shown alongside the answer.

Parameters

node SurfaceNode
the surface node tree to render

Returns

this result, for chaining

withOpenUrl

public IntentResult withOpenUrl(String routeUrl)
Adds a route to open after the result is presented.

Parameters

routeUrl String
the route to navigate to

Returns

this result, for chaining

isFailed

public boolean isFailed()
True when the handler reported a failure.

getErrorMessage

public String getErrorMessage()
The user-visible failure message, or null on success.

getValue

public Object getValue()
The value carried onward, or null.

getDialog

public String getDialog()
The line for an assistant to speak, or null.

getSnippet

public SurfaceNode getSnippet()
The snippet layout, or null.

getOpenUrl

public String getOpenUrl()
The route to open, or null.

getEntity

public AppEntity getEntity()
The entity produced, or null.

toString

public String toString()
Returns 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())