Conversation UI is the new way of enriching your user experience by allowing users to access your app content and performs actions by using their voice. The two main tasks are as follows:
- Capture users intent by understanding their voice
- Respond to users intents through speakable responses.
Conversation UI can revolutionise the way users use your apps. For iOS apps, this is where SiriKit comes into play.
SiriKit was first introduced by Apple in iOS 10. SiriKit allows iOS apps to work with Siri, Apple’s intelligent voice assistant. Siri performs the natural language processing and semantic analysis for you. Thus taking care of the difficult part.
To enable your apps to interact with Siri, you can use SiriKit by creating an Intents App Extension of your app and register for the domain specific intents your app wants to handle.
Whenever your user makes a request to Siri, it does the natural language analysis and identifies the intent the user is trying to perform. Siri converts the spoken request into instructions that your application can handle.
Presently Apple has limited the SiriKit capabilities to the below mentioned domains:
- Audio/Video calling: Initiate calls and search call history.
- CarPlay integration: Allows your app to interact with a vehicle’s CarPlay system.
- Fitness activities: Allows users to start, pause or end a fitness activity.
- List and Notes: Allows users to create and manage notes & to-do lists.
- Messaging: Allows users to send messages or search for messages received.
- Payments: Allows users to send or receive payments.
- Photo management: Allows users to search and display photos.
- Ride booking: Allows users to book rides or check the status of rides booked.
- Vehicle integration: Allows users to control their vehicle and perform actions like locking the doors or check on fuel/power level etc.
- Visual codes: Shows visual codes like QR or barcode.
If your application belongs to any of the above domains, you can use SiriKit to provide a conversation experience for your users to perform actions by just conversing with Siri. It also allows users to access your app features from lock screen or background.
Lets see how you can create a SiriKit extension for your iOS App for Requesting a Ride using Conversation UI.
Step 1: Enabling Siri Capabilities
You will need to enable Siri in your app capabilities.
The next step is to request Siri authorisation.
Step 2: Adding an Intents App Extension
Add a new scheme to your application. Choose the “Intents Extension” options from XCode to add to your app. The “Intents UI Extension” is added by default. If you do not wish to add it, uncheck the option from the dialog which appears next.
By adding the Intents Extension, the following files are added to your XCode project:
- IntentHandler.swift — Use this file to register your intent extension to an existing Intents domains or to new Intents created by you (more of that later).
- IntentViewController.swift: This controller is used to provide a UI as response to user via Siri.
- MainInterface.storyboard: As all storyboards, use this file to create your custom UI response.
Step 3: Register for an Intent
To register for an intent you can use the “IntentHandler.swift” file. This file is a subclass of INExtension class. To register for an intent you need to make this class conform to any chosen intent.
The example i chose is for Requesting a Ride. My IntentHandler registers for INRequestRideIntentHandling. The file looks like this:
Step 4: Resolve Intent Request Parameters
Whenever Siri gets a user request for a ride booking it tries to resolve the basic parameters to complete a ride booking i.e. Pickup location, drop-off location, party size, scheduled pickup times and ride options. The delegate methods invoked in your app extensions are needed to resolve the parameters.
This behaviour depends on how the user communicates their request to Siri.
A request might be
“Book a ride to London Heathrow Airport for one passenger at 9 AM tomorrow”
In the above statement the user has already provided the drop off location, party size and pickup time.
Another user might say
“Get me to London”
The intent extension must try to resolve all the parameters to successfully complete the request. This is where the delegate come in use.
If the user has provided the value for any of the parameter, we can accept it by providing a success response. Alternatively, you can ask Siri to confirm on the value provided by invoking a confirmationRequired request. Another option is to present some options to the user to disambiguate
For partySize and scheduledPickupTime, if the user has specified the values, you can return a success response else you can ask Siri to resolve the value by specifying needsValue
Once all the required parameters are resolved, the extension needs to handle the intent and provide a confirmation to the user via Siri. Handling a request might be used to implement your business logic to complete the request.
To provide a confirmation to the user, you create a INRequestRideIntentResponse object with a userActivity and pass it as a completion to the SiriKit.
Step 5: Presenting a UI to user via Siri
Confirming an intent with a userActivity invokes your Intent UI Handler and presents a UI to the user. The IntentViewController looks like
Use the “configureView” method to display the values to the user. Once the user confirms the presented options, SiriKit allows your extension to complete the request.
Viola! The user can book a ride through your app by just having a conversation with Siri.
Some things to keep in mind:
- Try to provide quick responses to the user. Responses should be speakable and crisp, keeping the user engaged.
- Move all your network requests into a framework, keeping the intentHandler light weight.
You can also add custom vocabulary to Siri or create Shortcuts to enhance your user experience. More of that in my next article.
Hope you enjoyed this one. Watch this space for more!