server.js
/**
 * Send a query to the dialogflow agent, and return the query result.
 * @param {string} projectId The project to be used
 */
Send a query to the dialogflow agent, and return the query result.
@param {string} projectId The project to be used
Send a query to the dialogflow agent and return the query result . @param { string } projectId The project to be used
async function bot(text, cb) {
  const sessionId = uuid.v4();
  const projectId = 'leaflet-123';
  const sessionClient = new dialogflow.SessionsClient();
  const sessionPath = sessionClient.sessionPath(projectId, sessionId);
  const request = {
    session: sessionPath,
    queryInput: {
      text: {
        text: text,
        languageCode: 'en-US',
      },
    },
  };
  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}`);
  cb(result.fulfillmentText);
  if (result.intent) {
    console.log(`  Intent: ${result.intent.displayName}`);
  } else {
    console.log(`  No intent matched.`);
  }
}
async function bot ( text , cb ) { const sessionId = uuid . v4 ( ) ; const projectId = 'leaflet-123' ; const sessionClient = new dialogflow . SessionsClient ( ) ; const sessionPath = sessionClient . sessionPath ( projectId , sessionId ) ; const request = { session : sessionPath , queryInput : { text : { text : text , languageCode : 'en-US' , } , } , } ; const responses = await sessionClient . detectIntent ( request ) ; console . log ( 'Detected intent' ) ; const result = responses [ 0 ] . queryResult ; console . log ( ` ${ result . queryText } ` ) ; console . log ( ` ${ result . fulfillmentText } ` ) ; cb ( result . fulfillmentText ) ; if ( result . intent ) { console . log ( ` ${ result . intent . displayName } ` ) ; } else { console . log ( ` ` ) ; } }
Send a query to the dialogflow agent, and return the query result.
Send a query to the dialogflow agent and return the query result .
// A unique identifier for the given session // Create a new session // The text query request. // The query to send to the dialogflow agent // The language used by the client (en-US) // Send request and log result