A Flutter implementation of DialogFlow, improved.
Build your integrations with DialogFlow easier and faster.
About the package
DialogFlowtter is a package that helps you to build integrations with DialogFlow easier and faster.
- Authenticate with Google Auth Json
- Get an authenticated http client so you can talk with your DialogFlow agent
- Get access to all DialogFlow responses and models easily
- Inspect what values a DialogFlow response could have
The problem with the current DialogFlow integration packages that are available in Pub is that they're:
- Completely abandoned
- Not well documented
- Lack functionality
- Lack flexibility
This one is intended to solve those problems and add more features that I've seen the users want. Check the TO-DO section for more info on that.
This package is fully supported in Android, iOS and Web. We have plans on testing and adding support for Windows, Linux and MacOS as this platforms mature in the Flutter SDK.
Add the package to your flutter dependencies in you
dependencies: dialog_flowtter: ^0.1.3
Make sure you add your dialog_flow_auth.json to the
flutter: uses-material-design: true assets: - assets/dialog_flow_auth.json
Add your DialogFlow Auth JSON to the
assetsfolder and rename it to
You can change the name and Path of your JSON later in the code. Just make sure to use the same one in the
Get the packages from:
flutter packages get
Get your keys
How to use
One of the core features of DialogFlow is to detect what a person is trying to say. You can do that by detecting an intent that you have defined in your DialogFlow console
- Create an instance of
DialogFlowtterand set the
sessionIdthat will be used to identify the current conversation of the user with DialogFlow.
It's highly recommended that you use a different
sessionIdfor every conversation that the user establishes with the Assistant
final DialogFlowtter dialogFlowtter = DialogFlowtter( sessionId: "YOUR_SESSION_ID_HERE", );
(OPTIONAL) Change the JSON path to the one you're using. This defaults to
DialogFlowtter( jsonPath: "YOUR_JSON_PATH_HERE", );
- Create a
QueryInputwhere you can specify what data you want to send to DialogFlow.
final QueryInput queryInput = QueryInput( text: TextInput( text: "Hi. How are you?", languageCode: "en", ), );
- Send your input to DialogFlow through the
DetectIntentResponse response = await dialogFlowtter.detectIntent( queryInput: queryInput, );
You can check the code for more info on what info you can send and receive
Get the info from the intent
You can access the info returned by DialogFlow from the
DetectIntentResponse that the
Get the text from the response
DetectIntentResponse response = await dialogFlowtter.detectIntent( queryInput: QueryInput(text: TextInput(text: "Hi")), ); String textResponse = response.text; print(textResponse); // Hi, how may I help you?
response.text returns null if there's no text returned by DialogFlow or if the first message returned it's not of type MessageType.text
Get the message from the response
See Message for more info on what the model properties can be
DetectIntentResponse response = await dialogFlowtter.detectIntent( queryInput: QueryInput(text: TextInput(text: "Hi")), ); Message messageResponse = response.message;
Get the response type of the message
MessageType messageType = response.message.type; print(messageType); /// MessageType.card
response.message returns null if there's no messages returned by DialogFlow
Be sure to dispose the instance when you're done using it
Change the project id
You can change the Project ID that
DialogFlowtter will use to find your intents in DialogFlow.
- Create an instance of
final DialogFlowtter dialogFlowtter = DialogFlowtter();
- Change the
projectIdprop of the instance;
dialogFlowtter.projectId = "deimos-apps-0905";
Pro tip. You can do the exact same thing as above with the special Dart's cascade notation.
final DialogFlowtter dialogFlowtter = DialogFlowtter()..projectId = "deimos-apps-0905";
Make authenticated http requests to your DialogFlow project
You can access the authenticated http client generated by the package by calling the
client attribute in your instance.
Keep in mind that this can become
null if you have disposed your instance before.
Create your own authenticated http client
You can get an authenticated, auto refreshing http client with your custom json data if you call the static
Keep in mind that this only authenticates with json provided by Google.
Check googleapis_auth for more info.
DialogFlowtter class is a singleton, so you don't have to worry about multiple authentication flows being prompted every time you instanciate it.
The class creates an authenticated http client, with the credentials obtained from the DialogFlow Auth JSON, whenever you instanciate the class and saves it for later use.
Make sure to
DialogFlowtter instance whenever you're done using it. This makes sure to close the authenticated http client and all its
StreamSubscriptions to avoid memory leaks.
Too many models
We have coded almost every model that you may need to use when implementing this package so you don't have to work with annoying
Map<String, dynamic> objects. Feel free to ask for any model that is missing to be added to the package.
The models that were not coded are included as annoying
Map<String, dynamic>and are tagged with the
//? Create model if necessary.
xAdd support for cards, images, etc.
DialogFlowtter is Starware.
This means you're free to use the project, as long as you star its GitHub repository.
Your appreciation makes us grow and glow up. ⭐
Your help is always appreciated.