DialogflowGrpcV2Beta1.viaServiceAccount constructor

DialogflowGrpcV2Beta1.viaServiceAccount(
  1. ServiceAccount account
)

Creates a SessionsClient using a service account. From the service account it will get authentication and the Dialogflow project id. It uses a UUID to create a unique session

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'))}');

DialogflowGrpcV2Beta1 dialogflow = DialogflowGrpcV2Beta1.viaServiceAccount(serviceAccount);

Implementation

factory DialogflowGrpcV2Beta1.viaServiceAccount(ServiceAccount account) {
  var projectId = account.projectId;
  var uuid = Uuid().v4();
  DialogflowAuth.session = 'projects/$projectId/agent/sessions/$uuid';

  return DialogflowGrpcV2Beta1._(account.callOptions);
}