# Navigation

## The `onNavigation` callback

When the Assistant detects that the user is trying to navigate to various parts of the app,  it invokes the callback associated with the Navigation user journey. The callback looks like this:

{% tabs %}
{% tab title="Android Native" %}

```
NavigationAppState onNavigation(NavigationInfo navigationInfo, NavigationUserJourney userJourney);
```

{% endtab %}

{% tab title="React Native" %}

```
onNavigation: async (navigationInfo, navigationUserJourney)
```

{% endtab %}

{% tab title="Web" %}

```
onNavigation: async (navigationInfo, navigationUserJourney)
```

{% endtab %}

{% tab title="Android (Deprecated)" %}

```java
NavigationUserJourney.AppState onNavigation(NavigationInfo navigationInfo, NavigationUserJourney userJourney);
```

{% endtab %}
{% endtabs %}

When this callback is invoked, the app is expected to:&#x20;

1. Use the `NavigationInfo` parameter to examine the target of the user's navigation
2. Open the corresponding page/`Activity` using the target field&#x20;
3. Finally, return the `AppState` and `Condition` that the app transitioned into.&#x20;

For  example, for a given `onNavigation` callback invocation, if the user asked for viewing the cart and if the app can navigate to that page successfully, it sets the success condition and returns the NAVIGATION app state.

{% tabs %}
{% tab title="Android Native" %}

```
public NavigationAppState onNavigation(NavigationInfo navigationInfo, NavigationUserJourney userJourney) {
   switch (navigationInfo.getTarget()) {
      case "cart": 
         // Go to cart page
         // ...
         return NavigationCompleteAppState(SUCCESS);    
   }
}
```

{% endtab %}

{% tab title="React Native" %}

```
onNavigation: async (navigationInfo, navigationUserJourney) => {
  switch (navigationInfo.getTarget()) {
      case "cart": 
         // Goto cart
         // ...
         userJourney.setNavigationSuccess();
         return NavigationUserJourney.AppState.NAVIGATION;
    
      // ...     
   }
},
```

{% endtab %}

{% tab title="Web" %}

```
onNavigation: async (navigationInfo, navigationUserJourney) => {
  switch (navigationInfo.target) {
      case "cart": 
         // Goto cart
         // ...
         navigationUserJourney.setNavigationSuccess();
         return NavigationUserJourney.AppStates.NAVIGATION;
    
      // ...     
   }
},
```

{% endtab %}

{% tab title="Android (Deprecated)" %}

```java
public NavigationUserJourney.AppState onNavigation(NavigationInfo navigationInfo, NavigationUserJourney userJourney) {
   switch (navigationInfo.getTarget()) {
      case "cart": 
         // Goto cart
         // ...
         userJourney.setNavigationSuccess();
         return NavigationUserJourney.AppState.NAVIGATION;
    
      // ...     
   }
}
```

{% endtab %}
{% endtabs %}

## Sample Utterances that could trigger Navigation

The following are some examples of commands that could trigger this journey

* *"go to my cart"*
* *"pharmacy"*
* *"take me home"*

## `NavigationInfo` Parameter

The parameter`NavigationInfo` contains the breakdown of the original navigation request. It has the following structure:

{% tabs %}
{% tab title="Android Native" %}

```
Class NavigationInfo {
	String getTarget(); // Target to which app has been asked to navigate
}

// Possible target values
"back", "home", "pharmacy", "grocery", "basket", "order"
```

{% endtab %}

{% tab title="React Native" %}

```
```

{% endtab %}

{% tab title="Web" %}

```
NavigationInfo : { target:  <target> }

// Possible target values
"back", "home", "pharmacy", "grocery", "basket", "order"
```

{% endtab %}
{% endtabs %}

### Supported `AppState`s

The following `AppState`s are supported.

* **NAVIGATION\_COMPLETE (`NavigationCompleteAppState`):** To be returned when the app handles the navigation request
* **UNSUPPORTED (`UnsupportedAppState`):** To be returned when the app is not ready to handle navigation yet. The Assistant will speak out an appropriate prompt to the user.&#x20;

{% hint style="info" %}
The Slang Retail Assistant provides a special `AppState` **`'WAITING' (WaitingAppState)`** that is common across all `UserJourney` types for completing asynchronous operations within the callback. Refer to the [Asynchronous Action Handling](broken://pages/-MOf016Tfk_kJdogKS1g#asynchronous-action-handling) section for details of how to deal with asynchronous operations.
{% endhint %}

### Supported `Condition`s

The following `Condition`s are supported for each of the `AppState`s supported by the Assistant

| **App State**                                      | **App State Condition**                                                                                  | Description                                                                                                                             |
| -------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `NAVIGATION_COMPLETE (NavigationCompleteAppState)` | <ul><li><code>SUCCESS</code></li><li><code>TARGET\_INVALID</code></li><li><code>FAILURE</code></li></ul> | <ul><li>The navigation was successful</li><li>The navigation target is not valid</li><li>There was a failure while navigating</li></ul> |

### Assistant Prompts

Based on the App State and the Condition that was set, the Assistant will speak out an appropriate message to the user. You can examine the default set of prompts configured for the Assistant through the Console and also customize it to your needs. Refer to the [Customizing the Assistant](broken://pages/-MOf6QJG8KGxusCCCxx9) section for details.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.conva.ai/slang/getting-started/integrating-slang-retail-assistant/code-integration-basic-steps/code-integration-basic-steps-1/supported-user-journeys/navigation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
