Code Integration - Basic Steps
Integrating the Slang Voice Assistant with your app
By now you must have configured and published your Assistant via the Slang Console. Congratulations! :) If you have not already done that, you can do so by following the instructions here.
While the overall idea is similar across platforms, the specific steps involved vary slightly based on the platform on which your app is built. Supported platforms are:
Android Native
React Native for Android
Web (JS)
Let's start coding!
For testing, we recommend using a physical Android device instead of an emulator because most emulators don't work well with microphones.
1. Configure the build system
The first step is to update the app's build system to include Slang's Travel Assistant SDK.
2. Code integration
2.1 Initialization
The next step is to initialize the SDK with the keys you obtained after creating the Assistant in the Slang console.
The recommendation is to perform the initialization in the onCreate
method of the Application
class. If the app does not use an Application
class, the next best place would be the onCreate
method of the primary Activity
class.
2.2 Show the Trigger (microphone icon)
Once the Assistant is initialized, the next step is to show the microphone UI element (what we call the Trigger) that the app's users can click on to invoke the Assistant and speak to it.
Add the below line to the onResume
method of the Activities where you want the Assistant to be enabled.
The trigger is sticky, which means that it will show up on all Activities after it is made visible. To prevent the trigger from showing up on specific activities, you will need to call: SlangTravelAssistant.getUI().hideTrigger(this)
2.3 Implement Actions
Refresher: A UserJourney
represents a path that a user may take to reach their goal when using a web or mobile app. See Voice Assistant Concepts for details.
Last but not the least, the app needs to implement the Actions associated with the various User Journeys supported by the Assistant. This can be done as shown below
The following user journeys are currently supported by the Slang Travel Assistant:
Voice Search
Voice Navigation
The Action Handler interface has an explicit callback for each of the supported user journeys. Whenever the Assistant detects the user journey the user is interested in (based on what they spoke), it invokes the callback associated with that user journey.
When these callbacks are invoked, the Assistant also passes the parametric data corresponding to the user journey that the Assistant was able to gather. The app is then expected to:
Consume the parametric data as needed
Optionally launch appropriate UI actions
Set appropriate conditions in the Assistant based on the app's internal state
Return the
AppState
that the app transitioned to
2.4 Return the AppState
and Condition
AppState
and Condition
Refresher: An AppState
typically corresponds to a screen that the app transitioned to based on user input. See Voice Assistant Concepts for details.
An AppState
indicates which state the app transitioned to, based on the user-journey and parametric data that was passed to the app. The list ofAppStates
that are supported depends on the user journey.
Conditions
represent more detailed states of the app within a particular app state. For example, when performing a search, the search might have failed or the items might be out of stock. The app can useAppState
conditions to indicate to the Assistant the correct condition. The condition controls the message that the Assistant speaks up after the call-back returns.
2.4.2 Assistant Prompts
Based on the AppState
returned and the conditions that were set, the Assistant will speak out an appropriate message to the user.
The prompts spoken by the Assistant are customizable. Refer to the Customizing the Assistant section, if you're interested in customization.
That's it! These are the basic set of steps required to add Slang's In-App Voice Assistant into your app.
Beyond this integration, Slang Voice Assistants provide a lot more power and flexibility to cater to the more advanced needs of apps. Please refer to the Advanced Concepts section for more details.
Last updated