Google Cloud Platform logo

Dialogflow: Node.js Client

release level npm version codecov

Dialogflow is an enterprise-grade NLU platform that makes it easy for developers to design and integrate conversational user interfaces into mobile apps, web applications, devices, and bots.

Using the client library

  1. Select or create a Cloud Platform project.

  2. Enable billing for your project.

  3. Enable the Dialogflow API.

  4. Set up authentication with a service account so you can access the API from your local workstation.

  5. Install the client library:

     npm install --save dialogflow
    
  6. Try an example:


const dialogflow = require('dialogflow');
const uuid = require('uuid');

/**
 * Send a query to the dialogflow agent, and return the query result.
 * @param {string} projectId The project to be used
 */
async function runSample(projectId = 'your-project-id') {
  // A unique identifier for the given session
  const sessionId = uuid.v4();

  // Create a new session
  const sessionClient = new dialogflow.SessionsClient();
  const sessionPath = sessionClient.sessionPath(projectId, sessionId);

  // The text query request.
  const request = {
    session: sessionPath,
    queryInput: {
      text: {
        // The query to send to the dialogflow agent
        text: 'hello',
        // The language used by the client (en-US)
        languageCode: 'en-US',
      },
    },
  };

  // Send request and log result
  const responses = await sessionClient.detectIntent(request);
  console.log('Detected intent');
  const result = responses[0].queryResult;
  console.log(`  Query: ${result.queryText}`);
  console.log(`  Response: ${result.fulfillmentText}`);
  if (result.intent) {
    console.log(`  Intent: ${result.intent.displayName}`);
  } else {
    console.log(`  No intent matched.`);
  }
}

Samples

Samples are in the samples/ directory. The samples' README.md has instructions for running the samples.

Sample Source Code Try it
Detect Intent (Text) source code Open in Cloud Shell
Create Knowledge Base source code Open in Cloud Shell
Get Knowledge Base source code Open in Cloud Shell
list Knowledge Base source code Open in Cloud Shell
list Knowledge Base source code Open in Cloud Shell
create Document source code Open in Cloud Shell
list Documents source code Open in Cloud Shell
Get Document source code Open in Cloud Shell
delete Document source code Open in Cloud Shell
detect Intent with sentiment analysis source code Open in Cloud Shell
detect Intent with text-to-speech response source code Open in Cloud Shell
detect Intent with Knowledge Base source code Open in Cloud Shell
Detect Intent (Audio) source code Open in Cloud Shell
Detect Intent (Streaming) source code Open in Cloud Shell
Create Entity source code Open in Cloud Shell
Delete Entity source code Open in Cloud Shell
Create Intent source code Open in Cloud Shell
Delete Intent source code Open in Cloud Shell
Create Context source code Open in Cloud Shell
Delete Context source code Open in Cloud Shell
Create Session Entity Type source code Open in Cloud Shell
Delete Session Entity Type source code Open in Cloud Shell

The Dialogflow Node.js Client API Reference documentation also contains samples.

Versioning

This library follows Semantic Versioning.

This library is considered to be in beta. This means it is expected to be mostly stable while we work toward a general availability release; however, complete stability is not guaranteed. We will address issues and requests against beta libraries with a high priority.

More Information: Google Cloud Platform Launch Stages

Contributing

Contributions welcome! See the Contributing Guide.

License

Apache Version 2.0

See LICENSE

What's Next

Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.

google

google.cloud

google.cloud.dialogflow

google.cloud.dialogflow.v2

google.cloud.dialogflow.v2
google.cloud.dialogflow.v2.Agent
google.cloud.dialogflow.v2.AudioEncoding
google.cloud.dialogflow.v2.AutoExpansionMode
google.cloud.dialogflow.v2.BasicCard
google.cloud.dialogflow.v2.BatchCreateEntitiesRequest
google.cloud.dialogflow.v2.BatchDeleteEntitiesRequest
google.cloud.dialogflow.v2.BatchDeleteEntityTypesRequest
google.cloud.dialogflow.v2.BatchDeleteIntentsRequest
google.cloud.dialogflow.v2.BatchUpdateEntitiesRequest
google.cloud.dialogflow.v2.BatchUpdateEntityTypesRequest
google.cloud.dialogflow.v2.BatchUpdateEntityTypesResponse
google.cloud.dialogflow.v2.BatchUpdateIntentsRequest
google.cloud.dialogflow.v2.BatchUpdateIntentsResponse
google.cloud.dialogflow.v2.Button
google.cloud.dialogflow.v2.Card
google.cloud.dialogflow.v2.CarouselSelect
google.cloud.dialogflow.v2.Context
google.cloud.dialogflow.v2.CreateContextRequest
google.cloud.dialogflow.v2.CreateEntityTypeRequest
google.cloud.dialogflow.v2.CreateIntentRequest
google.cloud.dialogflow.v2.CreateSessionEntityTypeRequest
google.cloud.dialogflow.v2.DeleteAllContextsRequest
google.cloud.dialogflow.v2.DeleteContextRequest
google.cloud.dialogflow.v2.DeleteEntityTypeRequest
google.cloud.dialogflow.v2.DeleteIntentRequest
google.cloud.dialogflow.v2.DeleteSessionEntityTypeRequest
google.cloud.dialogflow.v2.DetectIntentRequest
google.cloud.dialogflow.v2.DetectIntentResponse
google.cloud.dialogflow.v2.Entity
google.cloud.dialogflow.v2.EntityOverrideMode
google.cloud.dialogflow.v2.EntityType
google.cloud.dialogflow.v2.EntityTypeBatch
google.cloud.dialogflow.v2.EventInput
google.cloud.dialogflow.v2.Platform
google.cloud.dialogflow.v2.QueryInput
google.cloud.dialogflow.v2.QueryParameters
google.cloud.dialogflow.v2.QueryResult
google.cloud.dialogflow.v2.QuickReplies
google.cloud.dialogflow.v2.RestoreAgentRequest
google.cloud.dialogflow.v2.SearchAgentsRequest
google.cloud.dialogflow.v2.SearchAgentsResponse
google.cloud.dialogflow.v2.SelectItemInfo
google.cloud.dialogflow.v2.Sentiment
google.cloud.dialogflow.v2.SentimentAnalysisRequestConfig
google.cloud.dialogflow.v2.SentimentAnalysisResult
google.cloud.dialogflow.v2.SessionEntityType
google.cloud.dialogflow.v2.SimpleResponse
google.cloud.dialogflow.v2.SimpleResponses
google.cloud.dialogflow.v2.SpeechModelVariant
google.cloud.dialogflow.v2.SsmlVoiceGender
google.cloud.dialogflow.v2.StreamingDetectIntentRequest
google.cloud.dialogflow.v2.StreamingDetectIntentResponse
google.cloud.dialogflow.v2.StreamingRecognitionResult
google.cloud.dialogflow.v2.Suggestion
google.cloud.dialogflow.v2.Suggestions
google.cloud.dialogflow.v2.SynthesizeSpeechConfig
google.cloud.dialogflow.v2.Text
google.cloud.dialogflow.v2.TextInput
google.cloud.dialogflow.v2.TrainAgentRequest
google.cloud.dialogflow.v2.TrainingPhrase
google.cloud.dialogflow.v2.Type
google.cloud.dialogflow.v2.UpdateContextRequest
google.cloud.dialogflow.v2.UpdateEntityTypeRequest
google.cloud.dialogflow.v2.UpdateIntentRequest
google.cloud.dialogflow.v2.UpdateSessionEntityTypeRequest
google.cloud.dialogflow.v2.VoiceSelectionParams
google.cloud.dialogflow.v2.WebhookState

google.cloud.dialogflow.v2beta1

google.cloud.dialogflow.v2beta1
google.cloud.dialogflow.v2beta1.Agent
google.cloud.dialogflow.v2beta1.Answer
google.cloud.dialogflow.v2beta1.AudioEncoding
google.cloud.dialogflow.v2beta1.AutoExpansionMode
google.cloud.dialogflow.v2beta1.BasicCard
google.cloud.dialogflow.v2beta1.BatchCreateEntitiesRequest
google.cloud.dialogflow.v2beta1.BatchDeleteEntitiesRequest
google.cloud.dialogflow.v2beta1.BatchDeleteEntityTypesRequest
google.cloud.dialogflow.v2beta1.BatchDeleteIntentsRequest
google.cloud.dialogflow.v2beta1.BatchUpdateEntitiesRequest
google.cloud.dialogflow.v2beta1.BatchUpdateEntityTypesRequest
google.cloud.dialogflow.v2beta1.BatchUpdateEntityTypesResponse
google.cloud.dialogflow.v2beta1.BatchUpdateIntentsRequest
google.cloud.dialogflow.v2beta1.BatchUpdateIntentsResponse
google.cloud.dialogflow.v2beta1.Button
google.cloud.dialogflow.v2beta1.Card
google.cloud.dialogflow.v2beta1.CarouselSelect
google.cloud.dialogflow.v2beta1.Context
google.cloud.dialogflow.v2beta1.CreateContextRequest
google.cloud.dialogflow.v2beta1.CreateDocumentRequest
google.cloud.dialogflow.v2beta1.CreateEntityTypeRequest
google.cloud.dialogflow.v2beta1.CreateIntentRequest
google.cloud.dialogflow.v2beta1.CreateKnowledgeBaseRequest
google.cloud.dialogflow.v2beta1.CreateSessionEntityTypeRequest
google.cloud.dialogflow.v2beta1.DeleteAllContextsRequest
google.cloud.dialogflow.v2beta1.DeleteContextRequest
google.cloud.dialogflow.v2beta1.DeleteDocumentRequest
google.cloud.dialogflow.v2beta1.DeleteEntityTypeRequest
google.cloud.dialogflow.v2beta1.DeleteIntentRequest
google.cloud.dialogflow.v2beta1.DeleteKnowledgeBaseRequest
google.cloud.dialogflow.v2beta1.DeleteSessionEntityTypeRequest
google.cloud.dialogflow.v2beta1.DetectIntentRequest
google.cloud.dialogflow.v2beta1.DetectIntentResponse
google.cloud.dialogflow.v2beta1.Document
google.cloud.dialogflow.v2beta1.Entity
google.cloud.dialogflow.v2beta1.EntityOverrideMode
google.cloud.dialogflow.v2beta1.EntityType
google.cloud.dialogflow.v2beta1.EntityTypeBatch
google.cloud.dialogflow.v2beta1.EventInput
google.cloud.dialogflow.v2beta1.ExportAgentRequest
google.cloud.dialogflow.v2beta1.ExportAgentResponse
google.cloud.dialogflow.v2beta1.FollowupIntentInfo
google.cloud.dialogflow.v2beta1.GetAgentRequest
google.cloud.dialogflow.v2beta1.GetContextRequest
google.cloud.dialogflow.v2beta1.GetDocumentRequest
google.cloud.dialogflow.v2beta1.GetEntityTypeRequest
google.cloud.dialogflow.v2beta1.GetIntentRequest
google.cloud.dialogflow.v2beta1.GetKnowledgeBaseRequest
google.cloud.dialogflow.v2beta1.GetSessionEntityTypeRequest
google.cloud.dialogflow.v2beta1.Image
google.cloud.dialogflow.v2beta1.ImportAgentRequest
google.cloud.dialogflow.v2beta1.InputAudioConfig
google.cloud.dialogflow.v2beta1.Intent
google.cloud.dialogflow.v2beta1.IntentBatch
google.cloud.dialogflow.v2beta1.IntentView
google.cloud.dialogflow.v2beta1.Item
google.cloud.dialogflow.v2beta1.Kind
google.cloud.dialogflow.v2beta1.KnowledgeAnswers
google.cloud.dialogflow.v2beta1.KnowledgeBase
google.cloud.dialogflow.v2beta1.KnowledgeOperationMetadata
google.cloud.dialogflow.v2beta1.KnowledgeType
google.cloud.dialogflow.v2beta1.LinkOutSuggestion
google.cloud.dialogflow.v2beta1.ListContextsRequest
google.cloud.dialogflow.v2beta1.ListContextsResponse
google.cloud.dialogflow.v2beta1.ListDocumentsRequest
google.cloud.dialogflow.v2beta1.ListDocumentsResponse
google.cloud.dialogflow.v2beta1.ListEntityTypesRequest
google.cloud.dialogflow.v2beta1.ListEntityTypesResponse
google.cloud.dialogflow.v2beta1.ListIntentsRequest
google.cloud.dialogflow.v2beta1.ListIntentsResponse
google.cloud.dialogflow.v2beta1.ListKnowledgeBasesRequest
google.cloud.dialogflow.v2beta1.ListKnowledgeBasesResponse
google.cloud.dialogflow.v2beta1.ListSelect
google.cloud.dialogflow.v2beta1.ListSessionEntityTypesRequest
google.cloud.dialogflow.v2beta1.ListSessionEntityTypesResponse
google.cloud.dialogflow.v2beta1.MatchConfidenceLevel
google.cloud.dialogflow.v2beta1.MatchMode
google.cloud.dialogflow.v2beta1.Message
google.cloud.dialogflow.v2beta1.MessageType
google.cloud.dialogflow.v2beta1.OpenUriAction
google.cloud.dialogflow.v2beta1.OutputAudioConfig
google.cloud.dialogflow.v2beta1.OutputAudioEncoding
google.cloud.dialogflow.v2beta1.Parameter
google.cloud.dialogflow.v2beta1.Part
google.cloud.dialogflow.v2beta1.Platform
google.cloud.dialogflow.v2beta1.QueryInput
google.cloud.dialogflow.v2beta1.QueryParameters
google.cloud.dialogflow.v2beta1.QueryResult
google.cloud.dialogflow.v2beta1.QuickReplies
google.cloud.dialogflow.v2beta1.ReloadDocumentRequest
google.cloud.dialogflow.v2beta1.RestoreAgentRequest
google.cloud.dialogflow.v2beta1.SearchAgentsRequest
google.cloud.dialogflow.v2beta1.SearchAgentsResponse
google.cloud.dialogflow.v2beta1.SelectItemInfo
google.cloud.dialogflow.v2beta1.Sentiment
google.cloud.dialogflow.v2beta1.SentimentAnalysisRequestConfig
google.cloud.dialogflow.v2beta1.SentimentAnalysisResult
google.cloud.dialogflow.v2beta1.SessionEntityType
google.cloud.dialogflow.v2beta1.SimpleResponse
google.cloud.dialogflow.v2beta1.SimpleResponses
google.cloud.dialogflow.v2beta1.SpeechModelVariant
google.cloud.dialogflow.v2beta1.SsmlVoiceGender
google.cloud.dialogflow.v2beta1.State
google.cloud.dialogflow.v2beta1.StreamingDetectIntentRequest
google.cloud.dialogflow.v2beta1.StreamingDetectIntentResponse
google.cloud.dialogflow.v2beta1.StreamingRecognitionResult
google.cloud.dialogflow.v2beta1.Suggestion
google.cloud.dialogflow.v2beta1.Suggestions
google.cloud.dialogflow.v2beta1.SynthesizeSpeechConfig
google.cloud.dialogflow.v2beta1.TelephonyPlayAudio
google.cloud.dialogflow.v2beta1.TelephonySynthesizeSpeech
google.cloud.dialogflow.v2beta1.TelephonyTransferCall
google.cloud.dialogflow.v2beta1.Text
google.cloud.dialogflow.v2beta1.TextInput
google.cloud.dialogflow.v2beta1.TrainAgentRequest
google.cloud.dialogflow.v2beta1.TrainingPhrase
google.cloud.dialogflow.v2beta1.Type
google.cloud.dialogflow.v2beta1.UpdateContextRequest
google.cloud.dialogflow.v2beta1.UpdateDocumentRequest
google.cloud.dialogflow.v2beta1.UpdateEntityTypeRequest
google.cloud.dialogflow.v2beta1.UpdateIntentRequest
google.cloud.dialogflow.v2beta1.UpdateKnowledgeBaseRequest
google.cloud.dialogflow.v2beta1.UpdateSessionEntityTypeRequest
google.cloud.dialogflow.v2beta1.VoiceSelectionParams
google.cloud.dialogflow.v2beta1.WebhookState

v2beta1.ContextsClient

v2beta1.SessionEntityTypesClient