See the image below:
How Can I implement auto responses using DialogFlow or any other chatbot frameworks in flutter.
I just want to know the method to get the desired result highlighted in the red region.
Dialogflow is a development suite that incorporates Google's machine learning expertise to build end-to-end,deploy-everywhere interfaces for websites, mobile applications, and IoT devices. Build natural and rich conversational experiences.
Dialogflow is a natural language understanding platform that makes it easy to design and integrate a conversational user interface into your mobile app, web application, device, bot, interactive voice response system, and so on.
Edit: Using dialogflow_v2 it seems you could do something like this to get custom suggestions:
In the Dialogflow console you could add a custom payload to your messages, like this:
{"suggestions": ["Reply 1", "Reply 2"]}
Create a BotSuggestions
class:
class BotSuggestions {
List<String> suggestions = [];
BotSuggestions(List<dynamic> messages) {
messages.forEach((message) {
if (message['payload'] != null) {
List<dynamic> suggestionList = message['payload']['suggestions'];
suggestionList.forEach((suggestion) => suggestions.add(suggestion));
}
});
}
}
Then, you could use it like this:
var botSuggestions = BotSuggestions(response.getListMessage());
print(botSuggestions.suggestions);
Here is a complete example of how to use it:
var userMessage = "Hi!!!";
print('User: $userMessage');
response = await dialogflow.detectIntent(userMessage);
var botSuggestions = BotSuggestions(response.getListMessage());
print('Bot: ${response.getMessage()}');
print('Suggestions: ${botSuggestions.suggestions}');
userMessage = botSuggestions.suggestions.first;
print('User: $userMessage');
response = await dialogflow.detectIntent(userMessage);
botSuggestions = BotSuggestions(response.getListMessage());
print('Bot: ${response.getMessage()}');
print('Suggestions: ${botSuggestions.suggestions}');
And this would be the output:
I/flutter ( 5917): User: Hi!!!
I/flutter ( 5917): Bot: Hi! How are you doing?
I/flutter ( 5917): Suggestions: [Reply 1, Reply 2]
I/flutter ( 5917): User: Reply 1
I/flutter ( 5917): Bot: Sorry, what was that?
I/flutter ( 5917): Suggestions: []
I asked about this in the package repository to see if there's another way to do it, here you can follow the thread: How to get suggestions in v2?.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With