@capacitor-mlkit/smart-reply
v8.2.0
Published
Capacitor plugin for ML Kit Smart Reply on Android and iOS.
Maintainers
Readme
Capacitor ML Kit Smart Reply Plugin
Unofficial Capacitor plugin for ML Kit Smart Reply.[^1]
Use Cases
The Smart Reply plugin generates contextual reply suggestions for a conversation directly on the device, for example:
- Messaging apps: Offer quick reply suggestions below an incoming message.
- Customer support: Help agents respond faster with suggested replies.
- Wearables: Provide tappable reply chips where typing is inconvenient.
- Chatbots: Suggest follow-up responses based on the recent conversation.
Compatibility
| Plugin Version | Capacitor Version | Status | | -------------- | ----------------- | -------------- | | 8.x.x | >=8.x.x | Active support |
Installation
You can use our AI-Assisted Setup to install the plugin. Add the Capawesome Skills to your AI tool using the following command:
npx skills add capawesome-team/skills --skill capacitor-pluginsThen use the following prompt:
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capacitor-mlkit/smart-reply` plugin in my project.If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:
npm install @capacitor-mlkit/smart-reply
npx cap syncAttention: This plugin only supports CocoaPods for iOS dependency management. Swift Package Manager (SPM) is not supported for the ML Kit SDK, see this comment.
Android
Variables
If needed, you can define the following project variable in your app’s variables.gradle file to change the default version of the dependency:
$mlkitSmartReplyVersionversion ofcom.google.mlkit:smart-reply(default:17.0.4)
This can be useful if you encounter dependency conflicts with other plugins in your project.
iOS
Minimum Deployment Target
Make sure to set the deployment target in your ios/App/Podfile to at least 15.5:
platform :ios, '15.5'Configuration
No configuration required for this plugin.
Demo
A working example can be found here: robingenz/capacitor-mlkit-plugin-demo
Usage
The following example shows how to generate reply suggestions for a conversation between two users.
Smart Reply only supports conversations in English. For any other language, the status will be NOT_SUPPORTED_LANGUAGE and no suggestions are returned. Reply suggestions are only generated for the messages of remote users (isLocalUser: false), so remote messages must provide a stable userId.
import {
SmartReply,
SmartReplySuggestionResultStatus,
} from '@capacitor-mlkit/smart-reply';
const suggestReplies = async () => {
const { status, suggestions } = await SmartReply.suggestReplies({
messages: [
{
text: 'Are you free for lunch today?',
timestamp: Date.now() - 60_000,
isLocalUser: false,
userId: 'user-1',
},
{
text: 'Sure, where do you want to go?',
timestamp: Date.now() - 30_000,
isLocalUser: true,
},
{
text: 'How about the new place downtown?',
timestamp: Date.now(),
isLocalUser: false,
userId: 'user-1',
},
],
});
if (status === SmartReplySuggestionResultStatus.Success) {
return suggestions;
}
return [];
};API
suggestReplies(...)
suggestReplies(options: SuggestRepliesOptions) => Promise<SuggestRepliesResult>Generate reply suggestions for a conversation.
Smart Reply only supports conversations in English. If the conversation is
in another language or no suitable reply is found, the status will
reflect this and suggestions will be empty.
Only available on Android and iOS.
| Param | Type |
| ------------- | ----------------------------------------------------------------------- |
| options | SuggestRepliesOptions |
Returns: Promise<SuggestRepliesResult>
Since: 8.2.0
Interfaces
SuggestRepliesResult
| Prop | Type | Description | Since |
| ----------------- | --------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | ----- |
| status | SmartReplySuggestionResultStatus | The status of the suggestion generation. | 8.2.0 |
| suggestions | string[] | The generated reply suggestions. Contains up to 3 suggestions and is empty unless status is SUCCESS. | 8.2.0 |
SuggestRepliesOptions
| Prop | Type | Description | Since |
| -------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----- |
| messages | TextMessage[] | The recent messages of the conversation in chronological order (oldest first). Only the last 10 messages are considered by the model. The array must not be empty. | 8.2.0 |
TextMessage
| Prop | Type | Description | Since |
| ----------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------- | ----- |
| text | string | The text content of the message. | 8.2.0 |
| timestamp | number | The time the message was sent in milliseconds since epoch. | 8.2.0 |
| isLocalUser | boolean | Whether the message was sent by the local user. Reply suggestions are only generated for messages sent by remote users. | 8.2.0 |
| userId | string | A stable identifier of the user who sent the message. Required when isLocalUser is false. | 8.2.0 |
Enums
SmartReplySuggestionResultStatus
| Members | Value | Description | Since |
| -------------------------- | ------------------------------------- | --------------------------------------------------------------------------------- | ----- |
| Success | 'SUCCESS' | Suggestions were generated successfully. | 8.2.0 |
| NotSupportedLanguage | 'NOT_SUPPORTED_LANGUAGE' | No suggestions were generated because the conversation language is not supported. | 8.2.0 |
| NoReply | 'NO_REPLY' | No suggestions were generated for the conversation. | 8.2.0 |
FAQ
Which platforms are supported by this plugin?
The plugin is available on Android and iOS. The suggestReplies(...) method is only available on Android and iOS, so there is no web implementation.
Which languages are supported?
Smart Reply only supports conversations in English. If the conversation is in another language, the result status is NOT_SUPPORTED_LANGUAGE and no suggestions are returned.
Why did I not get any suggestions?
The model may not return suggestions for every conversation, for example when the language is not supported (NOT_SUPPORTED_LANGUAGE) or when it cannot generate a suitable reply for the given context (NO_REPLY). Always check the status and handle the case where suggestions is empty.
How many suggestions are returned?
The model returns up to 3 reply suggestions. It only considers the last 10 messages of the conversation.
Do I need to provide a userId for every message?
You must provide a userId for messages sent by remote users (isLocalUser: false), as the model uses it to distinguish participants. Messages sent by the local user (isLocalUser: true) do not need a userId.
Can I install this plugin using Swift Package Manager?
No, this plugin only supports CocoaPods for iOS dependency management because the ML Kit SDK itself does not support Swift Package Manager. Also make sure to set the deployment target in your ios/App/Podfile to at least 15.5 (see Installation).
Related Plugins
- Translation: Translate a conversation before generating reply suggestions.
- Language Identification: Detect the language of a conversation.
Terms & Privacy
This plugin uses the Google ML Kit:
Newsletter
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.
Changelog
See CHANGELOG.md.
License
See LICENSE.
[^1]: This project is not affiliated with, endorsed by, sponsored by, or approved by Google LLC or any of their affiliates or subsidiaries.
