Skip to content

Instantly share code, notes, and snippets.

@ayoisaiah
Created March 19, 2020 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayoisaiah/6057028cdb8db64b744235ec5a36b0b5 to your computer and use it in GitHub Desktop.
Save ayoisaiah/6057028cdb8db64b744235ec5a36b0b5 to your computer and use it in GitHub Desktop.
const projectId = '<your dialogflow project id>';
const sessionId = '123456';
const languageCode = 'en-US';
const dialogflow = require('dialogflow');
const config = {
credentials: {
private_key: process.env.DIALOGFLOW_PRIVATE_KEY,
client_email: process.env.DIALOGFLOW_CLIENT_EMAIL,
},
};
const sessionClient = new dialogflow.SessionsClient(config);
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
module.exports = async event => {
const message = event.message.text;
const request = {
session: sessionPath,
queryInput: {
text: {
text: message,
languageCode: languageCode,
},
},
};
const responses = await sessionClient.detectIntent(request);
const result = responses[0].queryResult;
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment