License

Auto-generated Flutter Dialogflow library for detecting intents using gRPC. A faster integration with the Dialogflow API and also the possibility to do audio streaming. Built by Google Developer Advocate for Dialogflow, Lee Boonstra

Disclaimer: This package is made by Google developer advocate Lee Boonstra. This is not an official Google package. This package is provided as-is, without warranty or representation for any use or purpose. Feel free to improve this package, and contribute.

gRPC protos have been generated from:

Docs:

Usage

Before making use of this package, enable the Dialogflow API in the Google Cloud console.

gcloud services enable dialogflow.googleapis.com

Afterwards, download a service account JSON file which has Dialogflow Integration access rights, and store this in your project. (e.g. assets/credentials.json)

Example

Edit the pubspec.yaml file with the dialogflow_grpc dependency. And point to your service account (e.g. assets/credentials.json)

...
dependencies:
  dialogflow_grpc: any

...
# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  assets:
    - assets/credentials.json

Import this package in your code. Load your service account, and create a DialogflowGrpc instance:

import 'package:dialogflow_grpc/v2beta1.dart';
import 'package:dialogflow_grpc/generated/google/cloud/dialogflow/v2beta1/session.pb.dart';
import 'package:dialogflow_grpc/dialogflow_auth.dart';

final serviceAccount = ServiceAccount.fromString(
    '${(await rootBundle.loadString('assets/credentials.json'))}');

DialogflowGrpc dialogflow = DialogflowGrpc.viaServiceAccount(serviceAccount);

CAUTION: When working with production apps Storing the service account in a client asset folder (or even in a secure key client keychain) can be dangerous if it’s not handled well. First of all, you will need to be very careful with your service accounts. Which read and access rights will you give your components? When you give admin rights to Google Cloud’s compute engine, you can imagine that attackers could hack and decompile your app. When they get access to your compute engine, they could drive you into costs by for example, mining bitcoins for them. Now, even when you don’t give compute access rights to your Google Cloud service accounts, you still won’t expose your keys. Even though for Dialogflow, it only gives you access to your chatbot within your project, it might be possible for attackers to read PII data from the chat history if your end-users were sharing PII data in the chat. That can be a huge problem. On top of that, it’s not so easy to change service account keys in applications, as you don’t want the app to stop working for current users. So how can you serve service accounts and keys secure in mobile clients? By, for example, building a mechanism to rotate (a second set of) keys. Like working with JSON Web Tokens (JWT), an Internet proposed standard for creating data with optional signature and optional encryption whose payload holds JSON that asserts some number of claims. The tokens are signed either using a private secret or a public/private key. Or you can run (parts) of your integration on a server.

Example: DetectIntent

Detecting an intent based on a text input:

    var data = await dialogflow.detectIntent(text, 'en-US');
    print(data.queryResult.fulfillmentText);

Example: StreamingDetectIntent

Detecting an intent based on an audio stream:

    var biasList = SpeechContextV2Beta1(
      phrases: [
        'Dialogflow CX',
        'Dialogflow Essentials',
        'Action Builder',
        'HIPAA'
      ],
      boost: 20.0
    );

    var config = InputConfigV2beta1(
        encoding: 'AUDIO_ENCODING_LINEAR_16',
        languageCode: 'en-US',
        sampleRateHertz: 8000,
        singleUtterance: false,
        speechContexts: [biasList]
    );
    
    // import 'dart:io' show Platform;
    // On iOS
    if (Platform.isIOS) {
      config = InputConfigV2beta1(
          encoding: 'AUDIO_ENCODING_LINEAR_16',
          languageCode: 'en-US',
          sampleRateHertz: 16000,
          singleUtterance: false,
          speechContexts: [biasList]
      );
    }

    // Make the streamingDetectIntent call, with the InputConfig and the audioStream
    final responseStream = dialogflow.streamingDetectIntent(config, _audioStream);
    responseStream.listen((data) {
        print(data);
    });

Example: Making use of generated code

Use imports such as:

import 'package:dialogflow_grpc/generated/google/cloud/dialogflow/v2beta1/session.pb.dart';

Official API documentation: https://cloud.google.com/dialogflow/es/docs/reference/rpc

Example: Tests

Make sure you have a service account: assets/credentials.json

flutter test test/v2_test.dart
flutter test test/v2beta1_test.dart

Environments

MacOS

https://flutter.dev/desktop In order to run dialogflow_grpc in your MacOS app, enable internet. Edit the .entitlements files in your macos/Runner/ folder.

<key>com.apple.security.network.client</key>
<true/>

Android

In order to build the example for Android devices; the audio recorder library sound_stream requires a minSdk of at least 21. So let's change this in android/app/build.gradle in the defaultConfig block. Also, don't forget to go into the virtual device settings and enable your microphone.

defaultConfig {
   applicationId "com.myname.flutter_dialogflow_agent"
   minSdkVersion 21
   targetSdkVersion 30
   versionCode flutterVersionCode.toInteger()
   versionName flutterVersionName
}

iOS

In order to build the example for iOS devices, you will need to give permissions to the microphone. Add this to the ios/Runner/Info.plist file.

<key>NSMicrophoneUsageDescription</key>
<string>Need microphone access for uploading videos</string>

Developer Website: https://www.leeboonstra.dev

TODO

  • x Support DetectIntent TextInput
  • x Add streamingDetectIntent support
  • x Working app example audio streaming / chat app
  • x Get the session from the service account
  • x Support for V2Beta1, (Knowledge Base Connectors, SpeechContext)
  • x Test Cases
  • x Windows, Linux, MacOS support
  • Share demo Dialogflow Agent
  • Codelab working audio streaming app
  • Support DetectIntent with Events
  • Support for CX
screenshot

Libraries

agent.pb
agent.pb
agent.pb
agent.pb
agent.pbenum
agent.pbenum
agent.pbenum
agent.pbenum
agent.pbgrpc
agent.pbgrpc
agent.pbgrpc
agent.pbgrpc
agent.pbjson
agent.pbjson
agent.pbjson
agent.pbjson
answer_record.pb
answer_record.pb
answer_record.pbenum
answer_record.pbenum
answer_record.pbgrpc
answer_record.pbgrpc
answer_record.pbjson
answer_record.pbjson
any.pb
any.pbenum
any.pbjson
any_test.pb
any_test.pbenum
any_test.pbjson
api.pb
api.pbenum
api.pbjson
audio_config.pb
audio_config.pb
audio_config.pb
audio_config.pb
audio_config.pbenum
audio_config.pbenum
audio_config.pbenum
audio_config.pbenum
audio_config.pbjson
audio_config.pbjson
audio_config.pbjson
audio_config.pbjson
calendar_period.pb
calendar_period.pbenum
calendar_period.pbjson
color.pb
color.pbenum
color.pbjson
context.pb
context.pb
context.pbenum
context.pbenum
context.pbgrpc
context.pbgrpc
context.pbjson
context.pbjson
conversation.pb
conversation.pb
conversation.pbenum
conversation.pbenum
conversation.pbgrpc
conversation.pbgrpc
conversation.pbjson
conversation.pbjson
conversation_event.pb
conversation_event.pb
conversation_event.pbenum
conversation_event.pbenum
conversation_event.pbjson
conversation_event.pbjson
conversation_profile.pb
conversation_profile.pb
conversation_profile.pbenum
conversation_profile.pbenum
conversation_profile.pbgrpc
conversation_profile.pbgrpc
conversation_profile.pbjson
conversation_profile.pbjson
cx
cxv3beta1
date.pb
date.pbenum
date.pbjson
datetime.pb
datetime.pbenum
datetime.pbjson
dayofweek.pb
dayofweek.pbenum
dayofweek.pbjson
descriptor.pb
descriptor.pbenum
descriptor.pbjson
dialogflow_auth
dialogflow_grpc
document.pb
document.pb
document.pbenum
document.pbenum
document.pbgrpc
document.pbgrpc
document.pbjson
document.pbjson
duration.pb
duration.pbenum
duration.pbjson
empty.pb
empty.pbenum
empty.pbjson
entity_type.pb
entity_type.pb
entity_type.pb
entity_type.pb
entity_type.pbenum
entity_type.pbenum
entity_type.pbenum
entity_type.pbenum
entity_type.pbgrpc
entity_type.pbgrpc
entity_type.pbgrpc
entity_type.pbgrpc
entity_type.pbjson
entity_type.pbjson
entity_type.pbjson
entity_type.pbjson
environment.pb
environment.pb
environment.pb
environment.pb
environment.pbenum
environment.pbenum
environment.pbenum
environment.pbenum
environment.pbgrpc
environment.pbgrpc
environment.pbgrpc
environment.pbgrpc
environment.pbjson
environment.pbjson
environment.pbjson
environment.pbjson
experiment.pb
experiment.pb
experiment.pbenum
experiment.pbenum
experiment.pbgrpc
experiment.pbgrpc
experiment.pbjson
experiment.pbjson
expr.pb
expr.pbenum
expr.pbjson
field_mask.pb
field_mask.pbenum
field_mask.pbjson
flow.pb
flow.pb
flow.pbenum
flow.pbenum
flow.pbgrpc
flow.pbgrpc
flow.pbjson
flow.pbjson
fraction.pb
fraction.pbenum
fraction.pbjson
fulfillment.pb
fulfillment.pb
fulfillment.pbenum
fulfillment.pbenum
fulfillment.pbjson
fulfillment.pbjson
gcs.pb
gcs.pb
gcs.pbenum
gcs.pbenum
gcs.pbjson
gcs.pbjson
http_request.pb
http_request.pbenum
http_request.pbjson
human_agent_assistant_event.pb
human_agent_assistant_event.pb
human_agent_assistant_event.pbenum
human_agent_assistant_event.pbenum
human_agent_assistant_event.pbjson
human_agent_assistant_event.pbjson
input_config
input_config
input_config
input_config
intent.pb
intent.pb
intent.pb
intent.pb
intent.pbenum
intent.pbenum
intent.pbenum
intent.pbenum
intent.pbgrpc
intent.pbgrpc
intent.pbgrpc
intent.pbgrpc
intent.pbjson
intent.pbjson
intent.pbjson
intent.pbjson
interval.pb
interval.pbenum
interval.pbjson
knowledge_base.pb
knowledge_base.pb
knowledge_base.pbenum
knowledge_base.pbenum
knowledge_base.pbgrpc
knowledge_base.pbgrpc
knowledge_base.pbjson
knowledge_base.pbjson
label.pb
label.pbenum
label.pbjson
latlng.pb
latlng.pbenum
latlng.pbjson
launch_stage.pb
launch_stage.pbenum
launch_stage.pbjson
localized_text.pb
localized_text.pbenum
localized_text.pbjson
log_entry.pb
log_entry.pbenum
log_entry.pbjson
log_severity.pb
log_severity.pbenum
log_severity.pbjson
logging.pb
logging.pbenum
logging.pbgrpc
logging.pbjson
map_lite_unittest.pb
map_lite_unittest.pbenum
map_lite_unittest.pbjson
map_proto2_unittest.pb
map_proto2_unittest.pbenum
map_proto2_unittest.pbjson
map_unittest.pb
map_unittest.pbenum
map_unittest.pbjson
money.pb
money.pbenum
money.pbjson
monitored_resource.pb
monitored_resource.pbenum
monitored_resource.pbjson
month.pb
month.pbenum
month.pbjson
operations.pb
operations.pbenum
operations.pbgrpc
operations.pbjson
page.pb
page.pb
page.pbenum
page.pbenum
page.pbgrpc
page.pbgrpc
page.pbjson
page.pbjson
participant.pb
participant.pb
participant.pbenum
participant.pbenum
participant.pbgrpc
participant.pbgrpc
participant.pbjson
participant.pbjson
phone_number.pb
phone_number.pbenum
phone_number.pbjson
postal_address.pb
postal_address.pbenum
postal_address.pbjson
quaternion.pb
quaternion.pbenum
quaternion.pbjson
response_message.pb
response_message.pb
response_message.pbenum
response_message.pbenum
response_message.pbjson
response_message.pbjson
security_settings.pb
security_settings.pb
security_settings.pbenum
security_settings.pbenum
security_settings.pbgrpc
security_settings.pbgrpc
security_settings.pbjson
security_settings.pbjson
session.pb
session.pb
session.pb
session.pb
session.pbenum
session.pbenum
session.pbenum
session.pbenum
session.pbgrpc
session.pbgrpc
session.pbgrpc
session.pbgrpc
session.pbjson
session.pbjson
session.pbjson
session.pbjson
session_entity_type.pb
session_entity_type.pb
session_entity_type.pb
session_entity_type.pb
session_entity_type.pbenum
session_entity_type.pbenum
session_entity_type.pbenum
session_entity_type.pbenum
session_entity_type.pbgrpc
session_entity_type.pbgrpc
session_entity_type.pbgrpc
session_entity_type.pbgrpc
session_entity_type.pbjson
session_entity_type.pbjson
session_entity_type.pbjson
session_entity_type.pbjson
source_context.pb
source_context.pbenum
source_context.pbjson
status.pb
status.pbenum
status.pbjson
struct.pb
struct.pbenum
struct.pbjson
test_case.pb
test_case.pb
test_case.pbenum
test_case.pbenum
test_case.pbgrpc
test_case.pbgrpc
test_case.pbjson
test_case.pbjson
test_messages_proto2.pb
test_messages_proto2.pbenum
test_messages_proto2.pbjson
test_messages_proto3.pb
test_messages_proto3.pbenum
test_messages_proto3.pbjson
timeofday.pb
timeofday.pbenum
timeofday.pbjson
timestamp.pb
timestamp.pbenum
timestamp.pbjson
transition_route_group.pb
transition_route_group.pb
transition_route_group.pbenum
transition_route_group.pbenum
transition_route_group.pbgrpc
transition_route_group.pbgrpc
transition_route_group.pbjson
transition_route_group.pbjson
type.pb
type.pbenum
type.pbjson
unittest.pb
unittest.pbenum
unittest.pbgrpc
unittest.pbjson
unittest_arena.pb
unittest_arena.pbenum
unittest_arena.pbjson
unittest_custom_options.pb
unittest_custom_options.pbenum
unittest_custom_options.pbgrpc
unittest_custom_options.pbjson
unittest_drop_unknown_fields.pb
unittest_drop_unknown_fields.pbenum
unittest_drop_unknown_fields.pbjson
unittest_embed_optimize_for.pb
unittest_embed_optimize_for.pbenum
unittest_embed_optimize_for.pbjson
unittest_empty.pb
unittest_empty.pbenum
unittest_empty.pbjson
unittest_enormous_descriptor.pb
unittest_enormous_descriptor.pbenum
unittest_enormous_descriptor.pbjson
unittest_import.pb
unittest_import.pbenum
unittest_import.pbjson
unittest_import_lite.pb
unittest_import_lite.pbenum
unittest_import_lite.pbjson
unittest_import_public.pb
unittest_import_public.pbenum
unittest_import_public.pbjson
unittest_import_public_lite.pb
unittest_import_public_lite.pbenum
unittest_import_public_lite.pbjson
unittest_lazy_dependencies.pb
unittest_lazy_dependencies.pbenum
unittest_lazy_dependencies.pbjson
unittest_lazy_dependencies_custom_option.pb
unittest_lazy_dependencies_custom_option.pbenum
unittest_lazy_dependencies_custom_option.pbjson
unittest_lazy_dependencies_enum.pb
unittest_lazy_dependencies_enum.pbenum
unittest_lazy_dependencies_enum.pbjson
unittest_lite.pb
unittest_lite.pbenum
unittest_lite.pbjson
unittest_lite_imports_nonlite.pb
unittest_lite_imports_nonlite.pbenum
unittest_lite_imports_nonlite.pbjson
unittest_mset.pb
unittest_mset.pbenum
unittest_mset.pbjson
unittest_mset_wire_format.pb
unittest_mset_wire_format.pbenum
unittest_mset_wire_format.pbjson
unittest_no_field_presence.pb
unittest_no_field_presence.pbenum
unittest_no_field_presence.pbjson
unittest_no_generic_services.pb
unittest_no_generic_services.pbenum
unittest_no_generic_services.pbgrpc
unittest_no_generic_services.pbjson
unittest_optimize_for.pb
unittest_optimize_for.pbenum
unittest_optimize_for.pbjson
unittest_preserve_unknown_enum.pb
unittest_preserve_unknown_enum.pbenum
unittest_preserve_unknown_enum.pbjson
unittest_preserve_unknown_enum2.pb
unittest_preserve_unknown_enum2.pbenum
unittest_preserve_unknown_enum2.pbjson
unittest_proto3.pb
unittest_proto3.pbenum
unittest_proto3.pbjson
unittest_proto3_arena.pb
unittest_proto3_arena.pbenum
unittest_proto3_arena.pbjson
unittest_proto3_arena_lite.pb
unittest_proto3_arena_lite.pbenum
unittest_proto3_arena_lite.pbjson
unittest_proto3_lite.pb
unittest_proto3_lite.pbenum
unittest_proto3_lite.pbjson
unittest_proto3_optional.pb
unittest_proto3_optional.pbenum
unittest_proto3_optional.pbjson
unittest_well_known_types.pb
unittest_well_known_types.pbenum
unittest_well_known_types.pbjson
v2
v2beta1
validation_message.pb
validation_message.pb
validation_message.pbenum
validation_message.pbenum
validation_message.pbjson
validation_message.pbjson
validation_result.pb
validation_result.pb
validation_result.pbenum
validation_result.pbenum
validation_result.pbjson
validation_result.pbjson
version.pb
version.pb
version.pbenum
version.pbenum
version.pbgrpc
version.pbgrpc
version.pbjson
version.pbjson
webhook.pb
webhook.pb
webhook.pb
webhook.pb
webhook.pbenum
webhook.pbenum
webhook.pbenum
webhook.pbenum
webhook.pbgrpc
webhook.pbgrpc
webhook.pbjson
webhook.pbjson
webhook.pbjson
webhook.pbjson
wrappers.pb
wrappers.pbenum
wrappers.pbjson