DialogFlow Detect Intent Request from NodeJS doesn't change data

128 Views Asked by At

I do detect intent request from NodeJS. I have done the same using Postman and it works to change the currentPage (I am making long-lasting session). But from NodeJS, the Dialogflow gives response but after I test it on Test Agent, the current page doesn't change.

Here is the code on the NodeJS. The session ID is not randomized. It's already exist ID.

'use strict';
const dialogflow = require('@google-cloud/dialogflow');

async function checkDialogFlow(current_page, session_id, project_id = '#####') {
  const agentId = '########';

  const sessionClient = new dialogflow.SessionsClient();
  const sessionPath = sessionClient.projectLocationAgentSessionPath(project_id, 'global', agentId, session_id);
  // The text query request.
  // This is the format the request needs to be in for DialogFlow to understand the query
  const request = {
    session: sessionPath,
    queryInput: {
      text: {
        text: 'djkabdjkbasjkbdkj',
        languageCode: 'en',
      },
    },
    queryParams: {
      timeZone: 'America/Los_Angeles',
      currentPage: current_page,
    },
  };

  // 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.`);
  }
  
  return result
}

module.exports = { checkDialogFlow };

and here is the response from the DialogFlow

result { fulfillmentMessages:
   [ { platform: 'PLATFORM_UNSPECIFIED',
       text: [Object],
       message: 'text' } ],
  outputContexts:
   [ { name:
        'projects/bilip-user-v2-uwoy/locations/global/agent/sessions/7b39a3cc-fee8-41e1-96ee-ca0ff90cb981/contexts/__system_counters__',
       lifespanCount: 1,
       parameters: [Object] } ],
  queryText: 'djkabdjkbasjkbdkj',
  speechRecognitionConfidence: 0,
  action: 'input.unknown',
  parameters: { fields: {} },
  allRequiredParamsPresent: true,
  fulfillmentText: 'I missed what you said. What was that?',
  webhookSource: '',
  webhookPayload: null,
  intent:
   { inputContextNames: [],
     events: [],
     trainingPhrases: [],
     outputContexts: [],
     parameters: [],
     messages: [],
     defaultResponsePlatforms: [],
     followupIntentInfo: [],
     name:
      'projects/bilip-user-v2-uwoy/locations/global/agent/intents/a54872dc-50b7-48eb-9152-332506829028',
     displayName: 'Default Fallback Intent',
     priority: 0,
     isFallback: true,
     webhookState: 'WEBHOOK_STATE_UNSPECIFIED',
     action: '',
     resetContexts: false,
     rootFollowupIntentName: '',
     parentFollowupIntentName: '',
     mlDisabled: false,
     liveAgentHandoff: false,
     endInteraction: false },
  intentDetectionConfidence: 1,
  diagnosticInfo: { fields: { webhook_latency_ms: [Object] } },
  languageCode: 'en',
  sentimentAnalysisResult:
   { queryTextSentiment:
      { score: 0.30000001192092896, magnitude: 0.30000001192092896 } },
  cancelsSlotFilling: false }
  Query: djkabdjkbasjkbdkj
  Response: I missed what you said. What was that?
  Intent: Default Fallback Intent

I expect the currentPage of the session to change. I have tried using Postman and it works.

0

There are 0 best solutions below