How to use the dialogflow.v2beta1.ContextsClient function in dialogflow

To help you get started, we’ve selected a few dialogflow examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-dialogflow / samples / detect.v2beta1.js View on Github external
const inputAudio = await readFile(audioFilePath);
  const request = {
    session: sessionPath,
    queryInput: {
      audioConfig: {
        audioEncoding: `AUDIO_ENCODING_LINEAR_16`,
        sampleRateHertz: 16000,
        languageCode: languageCode,
        model: model,
      },
    },
    inputAudio: inputAudio,
  };
  // Recognizes the speech in the audio and detects its intent.
  const responses = await sessionClient.detectIntent(request);
  const contextClient = new dialogflow.ContextsClient();
  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.`);
  }
  const parameters = JSON.stringify(struct.decode(result.parameters));
  console.log(`  Parameters: ${parameters}`);
  if (result.outputContexts && result.outputContexts.length) {
    console.log(`  Output contexts:`);
    result.outputContexts.forEach(context => {
      const contextId = contextClient.matchContextFromContextName(context.name);
      const contextParameters = JSON.stringify(
        struct.decode(context.parameters)