// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.cloud.dialogflow.v2;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/dialogflow/v2/audio_config.proto";
import "google/cloud/dialogflow/v2/participant.proto";
import "google/longrunning/operations.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";

option cc_enable_arenas = true;
option csharp_namespace = "Google.Cloud.Dialogflow.V2";
option go_package = "google.golang.org/genproto/googleapis/cloud/dialogflow/v2;dialogflow";
option java_multiple_files = true;
option java_outer_classname = "ConversationProfileProto";
option java_package = "com.google.cloud.dialogflow.v2";
option objc_class_prefix = "DF";
option (google.api.resource_definition) = {
  type: "dialogflow.googleapis.com/CXSecuritySettings"
  pattern: "projects/{project}/locations/{location}/securitySettings/{security_settings}"
};
option (google.api.resource_definition) = {
  type: "dialogflow.googleapis.com/ConversationModel"
  pattern: "projects/{project}/locations/{location}/conversationModels/{conversation_model}"
};

// Service for managing [ConversationProfiles][google.cloud.dialogflow.v2.ConversationProfile].
service ConversationProfiles {
  option (google.api.default_host) = "dialogflow.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/cloud-platform,"
      "https://www.googleapis.com/auth/dialogflow";

  // Returns the list of all conversation profiles in the specified project.
  rpc ListConversationProfiles(ListConversationProfilesRequest) returns (ListConversationProfilesResponse) {
    option (google.api.http) = {
      get: "/v2/{parent=projects/*}/conversationProfiles"
      additional_bindings {
        get: "/v2/{parent=projects/*/locations/*}/conversationProfiles"
      }
    };
    option (google.api.method_signature) = "parent";
  }

  // Retrieves the specified conversation profile.
  rpc GetConversationProfile(GetConversationProfileRequest) returns (ConversationProfile) {
    option (google.api.http) = {
      get: "/v2/{name=projects/*/conversationProfiles/*}"
      additional_bindings {
        get: "/v2/{name=projects/*/locations/*/conversationProfiles/*}"
      }
    };
    option (google.api.method_signature) = "name";
  }

  // Creates a conversation profile in the specified project.
  //
  // [ConversationProfile.CreateTime][] and [ConversationProfile.UpdateTime][]
  // aren't populated in the response. You can retrieve them via
  // [GetConversationProfile][google.cloud.dialogflow.v2.ConversationProfiles.GetConversationProfile] API.
  rpc CreateConversationProfile(CreateConversationProfileRequest) returns (ConversationProfile) {
    option (google.api.http) = {
      post: "/v2/{parent=projects/*}/conversationProfiles"
      body: "conversation_profile"
      additional_bindings {
        post: "/v2/{parent=projects/*/locations/*}/conversationProfiles"
        body: "conversation_profile"
      }
    };
    option (google.api.method_signature) = "parent,conversation_profile";
  }

  // Updates the specified conversation profile.
  //
  // [ConversationProfile.CreateTime][] and [ConversationProfile.UpdateTime][]
  // aren't populated in the response. You can retrieve them via
  // [GetConversationProfile][google.cloud.dialogflow.v2.ConversationProfiles.GetConversationProfile] API.
  rpc UpdateConversationProfile(UpdateConversationProfileRequest) returns (ConversationProfile) {
    option (google.api.http) = {
      patch: "/v2/{conversation_profile.name=projects/*/conversationProfiles/*}"
      body: "conversation_profile"
      additional_bindings {
        patch: "/v2/{conversation_profile.name=projects/*/locations/*/conversationProfiles/*}"
        body: "conversation_profile"
      }
    };
    option (google.api.method_signature) = "conversation_profile,update_mask";
  }

  // Deletes the specified conversation profile.
  rpc DeleteConversationProfile(DeleteConversationProfileRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/v2/{name=projects/*/conversationProfiles/*}"
      additional_bindings {
        delete: "/v2/{name=projects/*/locations/*/conversationProfiles/*}"
      }
    };
    option (google.api.method_signature) = "name";
  }
}

// Defines the services to connect to incoming Dialogflow conversations.
message ConversationProfile {
  option (google.api.resource) = {
    type: "dialogflow.googleapis.com/ConversationProfile"
    pattern: "projects/{project}/conversationProfiles/{conversation_profile}"
    pattern: "projects/{project}/locations/{location}/conversationProfiles/{conversation_profile}"
  };

  // The unique identifier of this conversation profile.
  // Format: `projects/<Project ID>/locations/<Location
  // ID>/conversationProfiles/<Conversation Profile ID>`.
  string name = 1;

  // Required. Human readable name for this profile. Max length 1024 bytes.
  string display_name = 2 [(google.api.field_behavior) = REQUIRED];

  // Output only. Create time of the conversation profile.
  google.protobuf.Timestamp create_time = 11 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Update time of the conversation profile.
  google.protobuf.Timestamp update_time = 12 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Configuration for an automated agent to use with this profile.
  AutomatedAgentConfig automated_agent_config = 3;

  // Configuration for agent assistance to use with this profile.
  HumanAgentAssistantConfig human_agent_assistant_config = 4;

  // Configuration for connecting to a live agent.
  //
  // Currently, this feature is not general available, please contact Google
  // to get access.
  HumanAgentHandoffConfig human_agent_handoff_config = 5;

  // Configuration for publishing conversation lifecycle events.
  NotificationConfig notification_config = 6;

  // Configuration for logging conversation lifecycle events.
  LoggingConfig logging_config = 7;

  // Configuration for publishing new message events. Event will be sent in
  // format of [ConversationEvent][google.cloud.dialogflow.v2.ConversationEvent]
  NotificationConfig new_message_event_notification_config = 8;

  // Settings for speech transcription.
  SpeechToTextConfig stt_config = 9;

  // Language which represents the conversationProfile.
  // If unspecified, the default language code en-us applies. Users need to
  // create a ConversationProfile for each language they want to support.
  string language_code = 10;
}

// The request message for [ConversationProfiles.ListConversationProfiles][google.cloud.dialogflow.v2.ConversationProfiles.ListConversationProfiles].
message ListConversationProfilesRequest {
  // Required. The project to list all conversation profiles from.
  // Format: `projects/<Project ID>/locations/<Location ID>`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "dialogflow.googleapis.com/ConversationProfile"
    }
  ];

  // The maximum number of items to return in a single page. By
  // default 100 and at most 1000.
  int32 page_size = 2;

  // The next_page_token value returned from a previous list request.
  string page_token = 3;
}

// The response message for [ConversationProfiles.ListConversationProfiles][google.cloud.dialogflow.v2.ConversationProfiles.ListConversationProfiles].
message ListConversationProfilesResponse {
  // The list of project conversation profiles. There is a maximum number
  // of items returned based on the page_size field in the request.
  repeated ConversationProfile conversation_profiles = 1;

  // Token to retrieve the next page of results, or empty if there are no
  // more results in the list.
  string next_page_token = 2;
}

// The request message for [ConversationProfiles.GetConversationProfile][google.cloud.dialogflow.v2.ConversationProfiles.GetConversationProfile].
message GetConversationProfileRequest {
  // Required. The resource name of the conversation profile.
  // Format: `projects/<Project ID>/locations/<Location
  // ID>/conversationProfiles/<Conversation Profile ID>`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "dialogflow.googleapis.com/ConversationProfile"
    }
  ];
}

// The request message for [ConversationProfiles.CreateConversationProfile][google.cloud.dialogflow.v2.ConversationProfiles.CreateConversationProfile].
message CreateConversationProfileRequest {
  // Required. The project to create a conversation profile for.
  // Format: `projects/<Project ID>/locations/<Location ID>`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "dialogflow.googleapis.com/ConversationProfile"
    }
  ];

  // Required. The conversation profile to create.
  ConversationProfile conversation_profile = 2 [(google.api.field_behavior) = REQUIRED];
}

// The request message for [ConversationProfiles.UpdateConversationProfile][google.cloud.dialogflow.v2.ConversationProfiles.UpdateConversationProfile].
message UpdateConversationProfileRequest {
  // Required. The conversation profile to update.
  ConversationProfile conversation_profile = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. The mask to control which fields to update.
  google.protobuf.FieldMask update_mask = 2 [(google.api.field_behavior) = REQUIRED];
}

// The request message for [ConversationProfiles.DeleteConversationProfile][google.cloud.dialogflow.v2.ConversationProfiles.DeleteConversationProfile].
//
// This operation fails if the conversation profile is still referenced from
// a phone number.
message DeleteConversationProfileRequest {
  // Required. The name of the conversation profile to delete.
  // Format: `projects/<Project ID>/locations/<Location
  // ID>/conversationProfiles/<Conversation Profile ID>`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "dialogflow.googleapis.com/ConversationProfile"
    }
  ];
}

// Defines the Automated Agent to connect to a conversation.
message AutomatedAgentConfig {
  // Required. ID of the Dialogflow agent environment to use.
  //
  // This project needs to either be the same project as the conversation or you
  // need to grant `service-<Conversation Project
  // Number>@gcp-sa-dialogflow.iam.gserviceaccount.com` the `Dialogflow API
  // Service Agent` role in this project.
  //
  // Format: `projects/<Project ID>/locations/<Location
  // ID>/agent/environments/<Environment ID or '-'>`. If environment is not
  // specified, the default `draft` environment is used. Refer to
  // [DetectIntentRequest](/dialogflow/docs/reference/rpc/google.cloud.dialogflow.v2#google.cloud.dialogflow.v2.DetectIntentRequest)
  // for more details.
  string agent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "dialogflow.googleapis.com/Agent"
    }
  ];
}

// Defines the Human Agent Assist to connect to a conversation.
message HumanAgentAssistantConfig {
  // Settings of suggestion trigger.
  message SuggestionTriggerSettings {
    // Do not trigger if last utterance is small talk.
    bool no_smalltalk = 1;

    // Only trigger suggestion if participant role of last utterance is
    // END_USER.
    bool only_end_user = 2;
  }

  // Config for suggestion features.
  message SuggestionFeatureConfig {
    // The suggestion feature.
    SuggestionFeature suggestion_feature = 5;

    // Automatically iterates all participants and tries to compile
    // suggestions.
    //
    // Supported features: ARTICLE_SUGGESTION, FAQ, DIALOGFLOW_ASSIST.
    bool enable_event_based_suggestion = 3;

    // Settings of suggestion trigger.
    //
    // Currently, only ARTICLE_SUGGESTION and FAQ will use this field.
    SuggestionTriggerSettings suggestion_trigger_settings = 10;

    // Configs of query.
    SuggestionQueryConfig query_config = 6;

    // Configs of custom conversation model.
    ConversationModelConfig conversation_model_config = 7;
  }

  // Detail human agent assistant config.
  message SuggestionConfig {
    // Configuration of different suggestion features. One feature can have only
    // one config.
    repeated SuggestionFeatureConfig feature_configs = 2;

    // If `group_suggestion_responses` is false, and there are multiple
    // `feature_configs` in `event based suggestion` or
    // StreamingAnalyzeContent, we will try to deliver suggestions to customers
    // as soon as we get new suggestion. Different type of suggestions based on
    // the same context will be in  separate Pub/Sub event or
    // `StreamingAnalyzeContentResponse`.
    //
    // If `group_suggestion_responses` set to true. All the suggestions to the
    // same participant based on the same context will be grouped into a single
    // Pub/Sub event or StreamingAnalyzeContentResponse.
    bool group_suggestion_responses = 3;
  }

  // Config for suggestion query.
  message SuggestionQueryConfig {
    // Knowledge base source settings.
    //
    // Supported features: ARTICLE_SUGGESTION, FAQ.
    message KnowledgeBaseQuerySource {
      // Required. Knowledge bases to query. Format:
      // `projects/<Project ID>/locations/<Location
      // ID>/knowledgeBases/<Knowledge Base ID>`. Currently, at most 5 knowledge
      // bases are supported.
      repeated string knowledge_bases = 1 [
        (google.api.field_behavior) = REQUIRED,
        (google.api.resource_reference) = {
          type: "dialogflow.googleapis.com/KnowledgeBase"
        }
      ];
    }

    // Document source settings.
    //
    // Supported features: SMART_REPLY, SMART_COMPOSE.
    message DocumentQuerySource {
      // Required. Knowledge documents to query from. Format:
      // `projects/<Project ID>/locations/<Location
      // ID>/knowledgeBases/<KnowledgeBase ID>/documents/<Document ID>`.
      // Currently, at most 5 documents are supported.
      repeated string documents = 1 [
        (google.api.field_behavior) = REQUIRED,
        (google.api.resource_reference) = {
          type: "dialogflow.googleapis.com/Document"
        }
      ];
    }

    // Dialogflow source setting.
    //
    // Supported feature: DIALOGFLOW_ASSIST.
    message DialogflowQuerySource {
      // Required. The name of a Dialogflow virtual agent used for end user side intent
      // detection and suggestion. Format: `projects/<Project Number/
      // ID>/locations/<Location ID>/agent`. When multiple agents are allowed in
      // the same Dialogflow project.
      string agent = 1 [
        (google.api.field_behavior) = REQUIRED,
        (google.api.resource_reference) = {
          type: "dialogflow.googleapis.com/Agent"
        }
      ];
    }

    // Settings that determine how to filter recent conversation context when
    // generating suggestions.
    message ContextFilterSettings {
      // If set to true, the last message from virtual agent (hand off message)
      // and the message before it (trigger message of hand off) are dropped.
      bool drop_handoff_messages = 1;

      // If set to true, all messages from virtual agent are dropped.
      bool drop_virtual_agent_messages = 2;

      // If set to true, all messages from ivr stage are dropped.
      bool drop_ivr_messages = 3;
    }

    // Source of query.
    oneof query_source {
      // Query from knowledgebase. It is used by:
      // ARTICLE_SUGGESTION, FAQ.
      KnowledgeBaseQuerySource knowledge_base_query_source = 1;

      // Query from knowledge base document. It is used by:
      // SMART_REPLY, SMART_COMPOSE.
      DocumentQuerySource document_query_source = 2;

      // Query from Dialogflow agent. It is used by DIALOGFLOW_ASSIST.
      DialogflowQuerySource dialogflow_query_source = 3;
    }

    // Maximum number of results to return. Currently, if unset, defaults to 10.
    // And the max number is 20.
    int32 max_results = 4;

    // Confidence threshold of query result.
    //
    // Agent Assist gives each suggestion a score in the range [0.0, 1.0], based
    // on the relevance between the suggestion and the current conversation
    // context. A score of 0.0 has no relevance, while a score of 1.0 has high
    // relevance. Only suggestions with a score greater than or equal to the
    // value of this field are included in the results.
    //
    // For a baseline model (the default), the recommended value is in the range
    // [0.05, 0.1].
    //
    // For a custom model, there is no recommended value. Tune this value by
    // starting from a very low value and slowly increasing until you have
    // desired results.
    //
    // If this field is not set, it defaults to 0.0, which means that all
    // suggestions are returned.
    //
    // Supported features: ARTICLE_SUGGESTION.
    float confidence_threshold = 5;

    // Determines how recent conversation context is filtered when generating
    // suggestions. If unspecified, no messages will be dropped.
    ContextFilterSettings context_filter_settings = 7;
  }

  // Custom conversation models used in agent assist feature.
  //
  // Supported feature: ARTICLE_SUGGESTION, SMART_COMPOSE, SMART_REPLY.
  message ConversationModelConfig {
    // Conversation model resource name. Format: `projects/<Project
    // ID>/conversationModels/<Model ID>`.
    string model = 1 [(google.api.resource_reference) = {
                        type: "dialogflow.googleapis.com/ConversationModel"
                      }];
  }

  // Configuration for analyses to run on each conversation message.
  message MessageAnalysisConfig {
    // Enable entity extraction in conversation messages on [agent assist
    // stage](https://cloud.google.com/dialogflow/priv/docs/contact-center/basics#stages).
    // If unspecified, defaults to false.
    //
    // Currently, this feature is not general available, please contact Google
    // to get access.
    bool enable_entity_extraction = 2;

    // Enable sentiment analysis in conversation messages on [agent assist
    // stage](https://cloud.google.com/dialogflow/priv/docs/contact-center/basics#stages).
    // If unspecified, defaults to false. Sentiment analysis inspects user input
    // and identifies the prevailing subjective opinion, especially to determine
    // a user's attitude as positive, negative, or neutral:
    // https://cloud.google.com/natural-language/docs/basics#sentiment_analysis
    // For [Participants.StreamingAnalyzeContent][google.cloud.dialogflow.v2.Participants.StreamingAnalyzeContent] method, result will be in
    // [StreamingAnalyzeContentResponse.message.SentimentAnalysisResult][google.cloud.dialogflow.v2.StreamingAnalyzeContentResponse.message].
    // For [Participants.AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent] method, result will be in
    // [AnalyzeContentResponse.message.SentimentAnalysisResult][google.cloud.dialogflow.v2.AnalyzeContentResponse.message]
    // For [Conversations.ListMessages][google.cloud.dialogflow.v2.Conversations.ListMessages] method, result will be in
    // [ListMessagesResponse.messages.SentimentAnalysisResult][google.cloud.dialogflow.v2.ListMessagesResponse.messages]
    // If Pub/Sub notification is configured, result will be in
    // [ConversationEvent.new_message_payload.SentimentAnalysisResult][google.cloud.dialogflow.v2.ConversationEvent.new_message_payload].
    bool enable_sentiment_analysis = 3;
  }

  // Pub/Sub topic on which to publish new agent assistant events.
  NotificationConfig notification_config = 2;

  // Configuration for agent assistance of human agent participant.
  SuggestionConfig human_agent_suggestion_config = 3;

  // Configuration for agent assistance of end user participant.
  //
  // Currently, this feature is not general available, please contact Google
  // to get access.
  SuggestionConfig end_user_suggestion_config = 4;

  // Configuration for message analysis.
  MessageAnalysisConfig message_analysis_config = 5;
}

// Defines the hand off to a live agent, typically on which external agent
// service provider to connect to a conversation.
//
// Currently, this feature is not general available, please contact Google
// to get access.
message HumanAgentHandoffConfig {
  // Configuration specific to LivePerson (https://www.liveperson.com).
  message LivePersonConfig {
    // Required. Account number of the LivePerson account to connect. This is
    // the account number you input at the login page.
    string account_number = 1 [(google.api.field_behavior) = REQUIRED];
  }

  // Configuration specific to Salesforce Live Agent.
  message SalesforceLiveAgentConfig {
    // Required. The organization ID of the Salesforce account.
    string organization_id = 1 [(google.api.field_behavior) = REQUIRED];

    // Required. Live Agent deployment ID.
    string deployment_id = 2 [(google.api.field_behavior) = REQUIRED];

    // Required. Live Agent chat button ID.
    string button_id = 3 [(google.api.field_behavior) = REQUIRED];

    // Required. Domain of the Live Agent endpoint for this agent. You can find
    // the endpoint URL in the `Live Agent settings` page. For example if URL
    // has the form https://d.la4-c2-phx.salesforceliveagent.com/...,
    // you should fill in d.la4-c2-phx.salesforceliveagent.com.
    string endpoint_domain = 4 [(google.api.field_behavior) = REQUIRED];
  }

  // Required. Specifies which agent service to connect for human agent handoff.
  oneof agent_service {
    // Uses LivePerson (https://www.liveperson.com).
    LivePersonConfig live_person_config = 1;

    // Uses Salesforce Live Agent.
    SalesforceLiveAgentConfig salesforce_live_agent_config = 2;
  }
}

// Defines notification behavior.
message NotificationConfig {
  // Format of cloud pub/sub message.
  enum MessageFormat {
    // If it is unspeified, PROTO will be used.
    MESSAGE_FORMAT_UNSPECIFIED = 0;

    // Pubsub message will be serialized proto.
    PROTO = 1;

    // Pubsub message will be json.
    JSON = 2;
  }

  // Name of the Pub/Sub topic to publish conversation
  // events like
  // [CONVERSATION_STARTED][google.cloud.dialogflow.v2.ConversationEvent.Type.CONVERSATION_STARTED] as
  // serialized [ConversationEvent][google.cloud.dialogflow.v2.ConversationEvent] protos.
  //
  // Notification works for phone calls, if this topic either is in the same
  // project as the conversation or you grant `service-<Conversation Project
  // Number>@gcp-sa-dialogflow.iam.gserviceaccount.com` the `Dialogflow Service
  // Agent` role in the topic project.
  //
  // Format: `projects/<Project ID>/locations/<Location ID>/topics/<Topic ID>`.
  string topic = 1;

  // Format of message.
  MessageFormat message_format = 2;
}

// Defines logging behavior for conversation lifecycle events.
message LoggingConfig {
  // Whether to log conversation events like
  // [CONVERSATION_STARTED][google.cloud.dialogflow.v2.ConversationEvent.Type.CONVERSATION_STARTED] to
  // Stackdriver in the conversation project as JSON format
  // [ConversationEvent][google.cloud.dialogflow.v2.ConversationEvent] protos.
  bool enable_stackdriver_logging = 3;
}

// The type of Human Agent Assistant API suggestion to perform, and the maximum
// number of results to return for that type. Multiple `Feature` objects can
// be specified in the `features` list.
message SuggestionFeature {
  // Defines the type of Human Agent Assistant feature.
  enum Type {
    // Unspecified feature type.
    TYPE_UNSPECIFIED = 0;

    // Run article suggestion model.
    ARTICLE_SUGGESTION = 1;

    // Run FAQ model.
    FAQ = 2;
  }

  // Type of Human Agent Assistant API feature to request.
  Type type = 1;
}
