Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

dialogflow es - detectIntent api call not returning response whereas testing in console returns the result

under the intent initiate quote i have created a training phrase invoke quote response, which is supposed to return the response Please enter quote amount.

when in run the tests things work as expected, but when I send the same training phrase via detectIntent node api client library, I am not getting the intended response but instead the fallback intent's response. What is the mistake in my code/configurations?

the configurations done

enter image description here

enter image description here

the test result in dialogflow ui

test result in dialogflow console ui

the code I am using for retrieving the same response programmatically

/**
 * TODO(developer): UPDATE these variables before running the sample.
 */
// projectId: ID of the GCP project where Dialogflow agent is deployed
// const projectId = 'PROJECT_ID';
// sessionId: String representing a random number or hashed user identifier
// const sessionId = '123456';
// queries: A set of sequential queries to be send to Dialogflow agent for Intent Detection
// const queries = [
//   'Reserve a meeting room in Toronto office, there will be 5 of us',
//   'Next monday at 3pm for 1 hour, please', // Tell the bot when the meeting is taking place
//   'B'  // Rooms are defined on the Dialogflow agent, default options are A, B, or C
// ]
// languageCode: Indicates the language Dialogflow agent should use to detect intents
// const languageCode = 'en';

// Imports the Dialogflow library
const dialogflow = require('@google-cloud/dialogflow');
const { v4: uuidv4 } = require('uuid');


// Instantiates a session client
const sessionClient = new dialogflow.SessionsClient();

async function detectIntent(
  projectId,
  sessionId,
  query,
  contexts,
  languageCode
) {
  // The path to identify the agent that owns the created intent.
  const sessionPath = sessionClient.projectAgentSessionPath(
    projectId,
    sessionId
  );

  // The text query request.
  const request = {
    session: sessionPath,
    queryInput: {
      text: {
        text: query,
        languageCode: languageCode,
      },
    },
  };

//   console.log("The context", JSON.stringify(contexts));

  if (contexts && contexts.length > 0) {
    request.queryParams = {
      contexts: contexts,
    };
  }

  console.log(request);

  const responses = await sessionClient.detectIntent(request);
  console.log(responses);
  return responses[0];
}

async function executeQueries(projectId, sessionId, queries, languageCode) {
  // Keeping the context across queries let's us simulate an ongoing conversation with the bot
  let context; 
  let intentResponse;

  for (const query of queries) {
    try {
      console.log(`Sending Query: ${query}`);
      intentResponse = await detectIntent(
        projectId,
        sessionId,
        query,
        context,
        languageCode
      );
      console.log('Detected intent');
      console.log(
        `Fulfillment Text: ${intentResponse.queryResult.fulfillmentText}`
      );
      // Use the context from this response for next queries
      context = intentResponse.queryResult.outputContexts;
    } catch (error) {
      console.log(error);
    }
  }
}

executeQueries("shipnext-auth", uuidv4(), ["invoke quote response"], "en-IN");

the entire output for the above code is as below

Sending Query: invoke quote response
{ session:
   'projects/shipnext-auth/agent/sessions/650c736d-9ad7-43ff-bb67-bc4e342915ef',
  queryInput:
   { text: { text: 'invoke quote response', languageCode: 'en-IN' } } }
[ { responseId: 'ff6a9463-65d9-4239-b5c3-fb09eb958902-5811cb77',
    queryResult:
     { fulfillmentMessages: [Array],
       outputContexts: [Array],
       queryText: 'invoke quote response',
       speechRecognitionConfidence: 0,
       action: 'input.unknown',
       parameters: [Object],
       allRequiredParamsPresent: true,
       fulfillmentText: 'I didn't get that. Can you repeat?',
       webhookSource: '',
       webhookPayload: null,
       intent: [Object],
       intentDetectionConfidence: 1,
       diagnosticInfo: null,
       languageCode: 'en-in',
       sentimentAnalysisResult: null },
    webhookStatus: null,
    outputAudio: <Buffer >,
    outputAudioConfig: null },
  null,
  null ]
Detected intent
Fulfillment Text: I didn't get that. Can you repeat?

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...