A new Flutter package.
Thanks for the tutorials!
Add this to your package's pubspec.yaml file:
dependencies:
flutter_dialogflow: ^0.1.0
You can install packages from the command line: with Flutter:
$ flutter packages get
Dialogflow v1 Import it Now in your Dart code, you can use:
import 'package:flutter_dialogflow/flutter_dialogflow.dart';
Or Dialogflow v2 Import it Now in your Dart code, you can use:
import 'package:flutter_dialogflow/dialogflow_v2.dart';
Dialogflow dialogflow = Dialogflow(token: "Your Token");
AIResponse response = await dialogflow.sendQuery("Your Query");
void Response(query) async {
Dialogflow dialogflow = Dialogflow(token: "10178f9cb6cf12321asdf4aae75c87cd");
AIResponse response = await dialogflow.sendQuery(query);
print(response.getMessageResponse());
}
Dialogflow](https://dialogflow.com/) register and create new Agent
Project Setup and Authentication
In your project create folder assets(folder name recommended optional)
Move file json in your project in folder created
open file pubspec.yaml
flutter:
uses-material-design: true
assets:
- assets/your_file_downloaded_google_cloud.json
Import dialogflow_v2
import 'package:flutter_dialogflow/dialogflow_v2.dart';
Code
AuthGoogle authGoogle = await AuthGoogle(fileJson: "Asset Your File Json").build();
// Select Language.ENGLISH or Language.SPANISH or others...
Dialogflow dialogflow =Dialogflow(authGoogle: authGoogle,language: Language.ENGLISH);
AIResponse response = await dialogflow.detectIntent("Your Query");
Example
AuthGoogle authGoogle = await AuthGoogle(fileJson: "assets/your_file_downloaded_google_cloud.json").build();
Dialogflow dialogflow = Dialogflow(authGoogle: authGoogle,language: Language.ENGLISH);
AIResponse response = await dialogflow.detectIntent("Hi!!!");
print(response.getMessage())
Or Get List Message type Card
Call function response.getListMessage()
response List<dynamic>
example
new CardDialogflow(response.getListMessage()[0]).title
Convert first item in CardDialogflow for worked easy
CardDialogflow have
title
subtitle
imageUri
List buttonss
Or Setup custom authentication (session)
Get a session id from your backend server after authentication.(Eg: OAuth Token)
Pass the session id a named parameter 'sessionId' to AuthGoogle function.
On the dialogflow fulfillment, access it inside `agent.session` (WebhookClient.session)
and apply your session logic
Example: AuthGoogle authGoogle = await AuthGoogle(fileJson: "assets/your_file_downloaded_google_cloud.json", sessionId: "YOUR_CUSTOM_SESSION_ID").build(); Dialogflow dialogflow = Dialogflow(authGoogle: authGoogle,language: Language.ENGLISH); AIResponse response = await dialogflow.detectIntent("Hi!!!"); print(response.getMessage())
![Demo](https://github.com/VictorRancesCode/flutter_dialogflow/raw/master/demo.jpg)
### Dialogflow For Flutter Web
Visit the repository: [Flutter Dialogflow Web](https://github.com/VictorRancesCode/flutter_dialogflow_web) 🚀