Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function (options) {
if (!options || !options.accessToken) {
throw new Error('No wit.ai Access Token specified');
}
options.minConfidence = options.minConfidence || 0.5;
options.logLevel = options.logLevel ? (logLevels.indexOf(options.logLevel) !== -1 ? options.logLevel : "debug") : null;
const params = {
accessToken: options.accessToken
}
if (options.logLevel){
params.logger = new log.Logger(options.logLevel);
}
const client = new Wit(params);
const middleware = {};
middleware.receive = function (bot, message, next) {
//Avoid text payload generated by buttons in Facebook Messenger
if (message.text && message.text.indexOf("_") == -1 && !message.payload && !message.attachments && !message.quick_reply) {
client.message(message.text)
.then((data) => {
console.log('Wit.ai response: ' + JSON.stringify(data));
message.entities = data.entities;
next();
})