# Class IntentResult

java.lang.Object
com.codename1.intents.IntentResult

public final class IntentResult extends Object

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 Type
  Method
  Description
  `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.
  `static IntentResult`
  `failed(String userVisibleMessage)`
  A failed result.
  `String`
  `getDialog()`
  The line for an assistant to speak, or null.
  `AppEntity`
  `getEntity()`
  The entity produced, or null.
  `String`
  `getErrorMessage()`
  The user-visible failure message, or null on success.
  `String`
  `getOpenUrl()`
  The route to open, or null.
  `SurfaceNode`
  `getSnippet()`
  The snippet layout, or null.
  `Object`
  `getValue()`
  The value carried onward, or null.
  `boolean`
  `isFailed()`
  True when the handler reported a failure.
  `static IntentResult`
  `ok()`
  A successful result with nothing to report.
  `static IntentResult`
  `opens(String routeUrl)`
  A result that opens the app at a route rather than answering in place.
  `static IntentResult`
  `spoken(String spoken)`
  A successful result whose only content is a line for the assistant to speak.
  `String`
  `toString()`
  Returns a string representation of the object.
  `static IntentResult`
  `value(Object value)`
  A successful result carrying a value the platform can pipe onward.
  `IntentResult`
  `withDialog(String spoken)`
  Adds the line an assistant speaks.
  `IntentResult`
  `withOpenUrl(String routeUrl)`
  Adds a route to open after the result is presented.
  `IntentResult`
  `withSnippet(SurfaceNode node)`
  Adds a small layout shown alongside the answer.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## 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`: 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`: 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`: 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`: 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`: what went wrong, in the user's terms

  - ### withDialog

    public IntentResult withDialog(String spoken)

    Adds the line an assistant speaks.

    ###### Parameters

    - `spoken`: 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`: 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`: 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()
    Description copied from class: `Object`
    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())
    Overrides:
      `toString` in class `Object`