@google-cloud/dialogflow-cx

Cx client for Node.js

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@google-cloud/dialogflow-cx
4.6.09 days ago4 years agoMinified + gzip package size for @google-cloud/dialogflow-cx in KB

Readme

Google Cloud Platform logorelease level npm version
Cx client for Node.js
A comprehensive list of changes in each version may be found in the CHANGELOG.

Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explainedexplained.
Table of contents:
Before you begin Installing the client library Using the client library

Quickstart

Before you begin

  1. Select or create a Cloud Platform projectprojects.
  2. Enable billing for your projectbilling.
  3. Enable the Dialogflow CX API APIenableapi.
  4. Set up authentication with a service accountauth so you can access the
API from your local workstation.

Installing the client library

npm install @google-cloud/dialogflow-cx

Using the client library

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// const projectId = 'my-project';
// const location = 'global';
// const agentId = 'my-agent';
// const audioFileName = '/path/to/audio.raw';
// const encoding = 'AUDIO_ENCODING_LINEAR_16';
// const sampleRateHertz = 16000;
// const languageCode = 'en'

// Imports the Google Cloud Some API library
const {SessionsClient} = require('@google-cloud/dialogflow-cx');
/**
 * Example for regional endpoint:
 *   const location = 'us-central1'
 *   const client = new SessionsClient({apiEndpoint: 'us-central1-dialogflow.googleapis.com'})
 */
const client = new SessionsClient();

const fs = require('fs');
const util = require('util');
// Assumes uuid module has been installed from npm,
// npm i uuid:
const {v4} = require('uuid');

async function detectIntentAudio() {
  const sessionId = v4();
  const sessionPath = client.projectLocationAgentSessionPath(
    projectId,
    location,
    agentId,
    sessionId
  );

  // Read the content of the audio file and send it as part of the request.
  const readFile = util.promisify(fs.readFile);
  const inputAudio = await readFile(audioFileName);

  const request = {
    session: sessionPath,
    queryInput: {
      audio: {
        config: {
          audioEncoding: encoding,
          sampleRateHertz: sampleRateHertz,
        },
        audio: inputAudio,
      },
      languageCode,
    },
  };
  const [response] = await client.detectIntent(request);
  console.log(`User Query: ${response.queryResult.transcript}`);
  for (const message of response.queryResult.responseMessages) {
    if (message.text) {
      console.log(`Agent Response: ${message.text.text}`);
    }
  }
  if (response.queryResult.match.intent) {
    console.log(
      `Matched Intent: ${response.queryResult.match.intent.displayName}`
    );
  }
  console.log(
    `Current Page: ${response.queryResult.currentPage.displayName}`
  );
}

detectIntentAudio();

Samples

Samples are in the samples/ directory. Each sample's README.md has instructions for running its sample.
| Sample | Source Code | Try it | | --------------------------- | --------------------------------- | ------ | | Agents.createagent | source code | !Open in Cloud Shellshellimg | | Agents.deleteagent | source code | !Open in Cloud Shellshellimg | | Agents.exportagent | source code | !Open in Cloud Shellshellimg | | Agents.getagent | source code | !Open in Cloud Shellshellimg | | Agents.getagentvalidationresult | source code | !Open in Cloud Shellshellimg | | Agents.getgenerativesettings | source code | !Open in Cloud Shellshellimg | | Agents.listagents | source code | !Open in Cloud Shellshellimg | | Agents.restoreagent | source code | !Open in Cloud Shellshellimg | | Agents.updateagent | source code | !Open in Cloud Shellshellimg | | Agents.updategenerativesettings | source code | !Open in Cloud Shellshellimg | | Agents.validateagent | source code | !Open in Cloud Shellshellimg | | Changelogs.getchangelog | source code | !Open in Cloud Shellshellimg | | Changelogs.listchangelogs | source code | !Open in Cloud Shellshellimg | | Deployments.getdeployment | source code | !Open in Cloud Shellshellimg | | Deployments.listdeployments | source code | !Open in Cloud Shellshellimg | | Entitytypes.createentitytype | source code | !Open in Cloud Shellshellimg | | Entitytypes.deleteentitytype | source code | !Open in Cloud Shellshellimg | | Entitytypes.exportentitytypes | source code | !Open in Cloud Shellshellimg | | Entitytypes.getentitytype | source code | !Open in Cloud Shellshellimg | | Entitytypes.importentitytypes | source code | !Open in Cloud Shellshellimg | | Entitytypes.listentitytypes | source code | !Open in Cloud Shellshellimg | | Entitytypes.updateentitytype | source code | !Open in Cloud Shellshellimg | | Environments.createenvironment | source code | !Open in Cloud Shellshellimg | | Environments.deleteenvironment | source code | !Open in Cloud Shellshellimg | | Environments.deployflow | source code | !Open in Cloud Shellshellimg | | Environments.getenvironment | source code | !Open in Cloud Shellshellimg | | Environments.listcontinuoustestresults | source code | !Open in Cloud Shellshellimg | | Environments.listenvironments | source code | !Open in Cloud Shellshellimg | | Environments.lookupenvironmenthistory | source code | !Open in Cloud Shellshellimg | | Environments.runcontinuoustest | source code | !Open in Cloud Shellshellimg | | Environments.updateenvironment | source code | !Open in Cloud Shellshellimg | | Experiments.createexperiment | source code | !Open in Cloud Shellshellimg | | Experiments.deleteexperiment | source code | !Open in Cloud Shellshellimg | | Experiments.getexperiment | source code | !Open in Cloud Shellshellimg | | Experiments.listexperiments | source code | !Open in Cloud Shellshellimg | | Experiments.startexperiment | source code | !Open in Cloud Shellshellimg | | Experiments.stopexperiment | source code | !Open in Cloud Shellshellimg | | Experiments.updateexperiment | source code | !Open in Cloud Shellshellimg | | Flows.createflow | source code | !Open in Cloud Shellshellimg | | Flows.deleteflow | source code | !Open in Cloud Shellshellimg | | Flows.exportflow | source code | !Open in Cloud Shellshellimg | | Flows.getflow | source code | !Open in Cloud Shellshellimg | | Flows.getflowvalidationresult | source code | !Open in Cloud Shellshellimg | | Flows.importflow | source code | !Open in Cloud Shellshellimg | | Flows.listflows | source code | !Open in Cloud Shellshellimg | | Flows.trainflow | source code | !Open in Cloud Shellshellimg | | Flows.updateflow | source code | !Open in Cloud Shellshellimg | | Flows.validateflow | source code | !Open in Cloud Shellshellimg | | Generators.creategenerator | source code | !Open in Cloud Shellshellimg | | Generators.deletegenerator | source code | !Open in Cloud Shellshellimg | | Generators.getgenerator | source code | !Open in Cloud Shellshellimg | | Generators.listgenerators | source code | !Open in Cloud Shellshellimg | | Generators.updategenerator | source code | !Open in Cloud Shellshellimg | | Intents.createintent | source code | !Open in Cloud Shellshellimg | | Intents.deleteintent | source code | !Open in Cloud Shellshellimg | | Intents.exportintents | source code | !Open in Cloud Shellshellimg | | Intents.getintent | source code | !Open in Cloud Shellshellimg | | Intents.importintents | source code | !Open in Cloud Shellshellimg | | Intents.listintents | source code | !Open in Cloud Shellshellimg | | Intents.updateintent | source code | !Open in Cloud Shellshellimg | | Pages.createpage | source code | !Open in Cloud Shellshellimg | | Pages.deletepage | source code | !Open in Cloud Shellshellimg | | Pages.getpage | source code | !Open in Cloud Shellshellimg | | Pages.listpages | source code | !Open in Cloud Shellshellimg | | Pages.updatepage | source code | !Open in Cloud Shellshellimg | | Securitysettingsservice.createsecuritysettings | source code | !Open in Cloud Shellshellimg | | Securitysettingsservice.deletesecuritysettings | source code | !Open in Cloud Shellshellimg | | Securitysettingsservice.getsecuritysettings | source code | !Open in Cloud Shellshellimg | | Securitysettingsservice.listsecuritysettings | source code | !Open in Cloud Shellshellimg | | Securitysettingsservice.updatesecuritysettings | source code | !Open in Cloud Shellshellimg | | Sessionentitytypes.createsessionentitytype | source code | !Open in Cloud Shellshellimg | | Sessionentitytypes.deletesessionentitytype | source code | !Open in Cloud Shellshellimg | | Sessionentitytypes.getsessionentitytype | source code | !Open in Cloud Shellshellimg | | Sessionentitytypes.listsessionentitytypes | source code | !Open in Cloud Shellshellimg | | Sessionentitytypes.updatesessionentitytype | source code | !Open in Cloud Shellshellimg | | Sessions.detectintent | source code | !Open in Cloud Shellshellimg | | Sessions.fulfillintent | source code | !Open in Cloud Shellshellimg | | Sessions.matchintent | source code | !Open in Cloud Shellshellimg | | Sessions.serverstreamingdetectintent | source code | !Open in Cloud Shellshellimg | | Sessions.streamingdetectintent | source code | !Open in Cloud Shellshellimg | | Sessions.submitanswerfeedback | source code | !Open in Cloud Shellshellimg | | Testcases.batchdeletetestcases | source code | !Open in Cloud Shellshellimg | | Testcases.batchruntestcases | source code | !Open in Cloud Shellshellimg | | Testcases.calculatecoverage | source code | !Open in Cloud Shellshellimg | | Testcases.createtestcase | source code | !Open in Cloud Shellshellimg | | Testcases.exporttestcases | source code | !Open in Cloud Shellshellimg | | Testcases.gettestcase | source code | !Open in Cloud Shellshellimg | | Testcases.gettestcaseresult | source code | !Open in Cloud Shellshellimg | | Testcases.importtestcases | source code | !Open in Cloud Shellshellimg | | Testcases.listtestcaseresults | source code | !Open in Cloud Shellshellimg | | Testcases.listtestcases | source code | !Open in Cloud Shellshellimg | | Testcases.runtestcase | source code | !Open in Cloud Shellshellimg | | Testcases.updatetestcase | source code | !Open in Cloud Shellshellimg | | Transitionroutegroups.createtransitionroutegroup | source code | !Open in Cloud Shellshellimg | | Transitionroutegroups.deletetransitionroutegroup | source code | !Open in Cloud Shellshellimg | | Transitionroutegroups.gettransitionroutegroup | source code | !Open in Cloud Shellshellimg | | Transitionroutegroups.listtransitionroutegroups | source code | !Open in Cloud Shellshellimg | | Transitionroutegroups.updatetransitionroutegroup | source code | !Open in Cloud Shellshellimg | | Versions.compareversions | source code | !Open in Cloud Shellshellimg | | Versions.createversion | source code | !Open in Cloud Shellshellimg | | Versions.deleteversion | source code | !Open in Cloud Shellshellimg | | Versions.getversion | source code | !Open in Cloud Shellshellimg | | Versions.listversions | source code | !Open in Cloud Shellshellimg | | Versions.loadversion | source code | !Open in Cloud Shellshellimg | | Versions.updateversion | source code | !Open in Cloud Shellshellimg | | Webhooks.createwebhook | source code | !Open in Cloud Shellshellimg | | Webhooks.deletewebhook | source code | !Open in Cloud Shellshellimg | | Webhooks.getwebhook | source code | !Open in Cloud Shellshellimg | | Webhooks.listwebhooks | source code | !Open in Cloud Shellshellimg | | Webhooks.updatewebhook | source code | !Open in Cloud Shellshellimg | | Agents.createagent | source code | !Open in Cloud Shellshellimg | | Agents.deleteagent | source code | !Open in Cloud Shellshellimg | | Agents.exportagent | source code | !Open in Cloud Shellshellimg | | Agents.getagent | source code | !Open in Cloud Shellshellimg | | Agents.getagentvalidationresult | source code | !Open in Cloud Shellshellimg | | Agents.getgenerativesettings | source code | !Open in Cloud Shellshellimg | | Agents.listagents | source code | !Open in Cloud Shellshellimg | | Agents.restoreagent | source code | !Open in Cloud Shellshellimg | | Agents.updateagent | source code | !Open in Cloud Shellshellimg | | Agents.updategenerativeset