Created
March 19, 2020 21:01
-
-
Save ayoisaiah/6057028cdb8db64b744235ec5a36b0b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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