Dialog flowtter-master - A Flutter implementation of DialogFlow, improved

Overview

logo

A Flutter implementation of DialogFlow, improved.

Build your integrations with DialogFlow easier and faster.

Pub Package Star on GitHub style: effective dart MIT License MIT License

About the package

Dialog Flow on Flutter, now with Null Safety support!

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

Why DialogFlowtter

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.

Platform support

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.

Installation

  1. Add the package to your flutter dependencies in you pubspec.yaml:

    dependencies:
        dialog_flowtter: ^0.3.1
  2. Make sure you add your dialog_flow_auth.json to the pubspec.yaml assets:

     flutter:
         uses-material-design: true
         assets:
             - assets/dialog_flow_auth.json
  3. Add your DialogFlow Auth JSON to the assets folder and rename it to dialog_flow_auth.json

You can change the name and Path of your JSON later in the code. Just make sure to use the same one in the pubspec.yaml

  1. Get the packages from:

    flutter packages get

Get your keys

Refer to Create a service account and download the private key file

How to use

Retrieve your keys

You can set your DialogFlow authentication keys in various ways.

  1. From an in-memory JSON
DialogAuthCredentials credentials = DialogAuthCredentials.fromJson(json);
  1. From a JSON file
DialogAuthCredentials credentials = await DialogAuthCredentials.fromFile(path);

This method is asynchronous!

  1. From the Network
DialogAuthCredentials credentials = await DialogAuthCredentials.fromNetwork(url);

This method is asynchronous!

Then, pass your credentials to you DialogFlowtter class

DialogFlowtter instance = DialogFlowtter(
  credentials: credentials,
);

You can also use the shorthand expression of these methods when instanciating the DialogFlowtter class

DialogFlowtter jsonInstance = DialogFlowtter.fromJson(json);

//! async
DialogFlowtter fileInstance = await DialogFlowtter.fromFile(path);

//! async
DialogFlowtter networkInstance = await DialogFlowtter.fromNetwork(url);

Detect intent

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

  1. Create an instance of DialogFlowtter and set the sessionId that will be used to identify the current conversation of the user with DialogFlow.

It's highly recommended that you use a different sessionId for every conversation that the user establishes with the Assistant

  final DialogFlowtter dialogFlowtter = DialogFlowtter(
    credentials: credentials,
    sessionId: "YOUR_SESSION_ID_HERE",
  );
  1. Create a QueryInput where you can specify what data you want to send to DialogFlow.
  final QueryInput queryInput = QueryInput(
    text: TextInput(
      text: "Hi. How are you?",
      languageCode: "en",
    ),
  );
  1. Send your input to DialogFlow through the detectIntent function.
  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 detectIntent function returns.

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 Also, check this issue to see how to create and use Rich Responses like cards and carousels

  DetectIntentResponse response = await dialogFlowtter.detectIntent(
    queryInput: QueryInput(text: TextInput(text: "Hi")),
  );
  
  Message? messageResponse = response.message;

Get audio from the response

  1. Set the audio configuration in the detectIntent function
  DetectIntentResponse response = await dialogFlowtter.detectIntent(
    queryInput: QueryInput(text: TextInput(text: "Hi")),
    
    // You can set your own configuration with the OutputAudioConfig class
    audioConfig: OutputAudioConfig(),
  );
  1. Retrieve the audio from the response
  String? audioBase64 = response.outputAudio;
  Uint8List? audioBytes = response.outputAudioBytes;
  1. Play the audio response with your favorite plugin!

Check Soundpool for playing the audio from memory

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

  dialogFlowtter.dispose();

Change the project id

You can change the Project ID that DialogFlowtter will use to find your intents in DialogFlow.

  1. Create an instance of DialogFlowtter
  final DialogFlowtter dialogFlowtter = DialogFlowtter(
    credentials: credentials,
  );
  1. Change the projectId prop 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(
        credentials: credentials,
      )..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 function

final credentials = DialogAuthCredentials.fromJson(yourJson);
final client = DialogFlowtter.getClient(credentials)

Keep in mind that this only authenticates with json provided by Google.

Check googleapis_auth for more info.

Further considerations

Every time you instanciate DialogFlowtter, the class creates an authenticated http client, with the credentials obtained from the DialogFlow Auth JSON. Be sure to save this instance and reuse it to avoid memory leaks

Memory leaks

Make sure to dispose your 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 Dialog Flow 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.

TO-DO

  • Add support for null safety
  • Add support for cards, images, etc.
  • Memory, file and remote auth JSON
  • Secure DialogFlow auth JSON
  • Support audio queries
  • Add a catalog of supported languages
  • Add direct access to common used attributes
  • Support use of custom HTTP Client

Starware

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.

Contribute

Your help is always appreciated.

You can contribute by checking our contributing guide or opening an issue.

You might also like...

Get It - Simple direct Service Locator that allows to decouple the interface from a concrete implementation and to access the concrete implementation from everywhere in your App. Maintainer: @escamoteur

Get It - Simple direct Service Locator that allows to decouple the interface from a concrete implementation and to access the concrete implementation from everywhere in your App. Maintainer: @escamoteur

❤️ Sponsor get_it This is a simple Service Locator for Dart and Flutter projects with some additional goodies highly inspired by Splat. It can be used

Jan 1, 2023

Custom calendar dialog widget for flutter with (multi select, single select, date range) mode

Custom calendar dialog widget for flutter with (multi select, single select, date range) mode

some calendar Custom calendar with Multi-select & range configurable calendar New Features Added View Mode Somecalendar #15 Help Maintenance I've take

Jan 3, 2023

A wrapper on top of alert dialog provided by flutter.

A wrapper on top of alert dialog provided by flutter.

material_dialog A wrapper on top of alert dialog provided by flutter. Demo Use this package as a library 1. Depend on it Add this to your package's pu

Aug 8, 2022

A simple flutter app that downloads a file from the internet, shows a custom-made download progress dialog and saves the file to device's internal storage

http_downloader A simple flutter app that downloads a file from the internet using the http plugin. It has a custom-designed progress dialog which dis

Apr 6, 2021

A simple screen that is shown when your app gets crashed instead of the normal crash dialog. It's very similar to the one in Flutter.

A simple screen that is shown when your app gets crashed instead of the normal crash dialog. It's very similar to the one in Flutter.

Red Screen Of Death What A simple screen that is shown when your app gets crashed instead of the normal crash dialog. It's very similar to the one in

Dec 9, 2022

A beautiful and customizable Star Rating Dialog package for Flutter

A beautiful and customizable Star Rating Dialog package for Flutter

rating_dialog A beautiful and customizable Rating Dialog package for Flutter! Supports all platforms that flutter supports! Import the rating_dialog p

Jul 13, 2022

A new flutter package project which contains lots of beautiful alert dialog that will help you lot to create beautiful awesome alert box very quickly and easily.

A new flutter package project which contains lots of beautiful alert dialog that will help you lot to create beautiful awesome alert box very quickly and easily.

A new flutter package project which contains lots of beautiful alert dialog that will help you lot to create beautiful awesome alert box very quickly and easily.

Jan 8, 2022

A dialog queue for you to manage your dialogs to display on flutter platform

A dialog queue for you to manage your dialogs to display on flutter platform

A dialog queue for you to manage your dialogs to display on flutter platform 中文 Features Support pop dialog orderly Support pop dialog by priority Sup

Nov 1, 2022

Internationalized dialog for picking a single month from an infinite list of years.

Internationalized dialog for picking a single month from an infinite list of years.

month_picker_dialog Internationalized material style dialog for picking a single month from an infinite list of years. This package makes use of the i

Nov 30, 2022
Owner
null
Adaptive dialog - Show alert dialog or modal action sheet adaptively according to platform.

adaptive_dialog Show alert dialog or modal action sheet adaptively according to platform. showOkAlertDialog Convenient wrapper of showAlertDialog. iOS

Masayuki Ono (mono) 244 Dec 17, 2022
A flutter plugin for improved row and column widgets with added spacing and optional interleaved dividers

flutter_series A flutter plugin for improved row and column widgets with added s

null 0 Nov 1, 2021
Raden Saleh 53 Jul 27, 2023
Slider Master Animation Flutter Dart

Flutter-animated-Slider ?? ?? untitled.1.mp4 Firt you need to add this in pub yamel : dependencies: carousel_slider: ^4.0.0 Finally import 'package

Hmida 8 Sep 10, 2022
Bwo-master - An infinity procedural online game using Flutter and flames with NodeJS and Firebase for the back-end

Borderless World Online (BWO) An infinity procedural online game using Flutter a

null 17 Nov 29, 2022
Bwo-master - An infinity procedural online game using Flutter and flames with NodeJS and Firebase for the back-end

Borderless World Online (BWO) An infinity procedural online game using Flutter a

null 0 Feb 2, 2022
From then on, developers only need to master one Button component, which is enough.

FButton From then on, developers only need to master one Button component, which is enough. Support corners, borders, icons, special effects, loading

Fliggy Mobile 198 Nov 22, 2022
Academic master is E-learning app where students can share their doubts wiith their peers they can chat and also they can find their notes

Academic Master is E-learning App. Features:- 1) You can post real Post query in Images and video formates. 2) We will Provide notes,books and previou

amit singh 25 Dec 14, 2022
Master Channel cannot use Glass Floating Action Button

Problem Master Channel cannot use GlassFloatingActionButton. About This package

null 7 Oct 2, 2022
Android test task master - Create PIN code screen, authentication by PIN code screen and menu screen

Here is described test tasks for a android dev. Need to implement three screens:

null 3 Oct 4, 2022