howdyai / botkit-middleware-witai Goto Github PK
View Code? Open in Web Editor NEWMiddleware for using Wit.ai with Botkit-powered bots
License: MIT License
Middleware for using Wit.ai with Botkit-powered bots
License: MIT License
Bot failed to reply on message_receive event. It looks like control never returns to bot controller and it hangs in wit.hears method, getting below log
debug: Successfully subscribed to Facebook events: {"success":true} {"msg_id":"262e9aa7-a945-452a-a275-3be9ff7c8970","_text":"hello","outcomes":[{"_text":"hello","confidence":null,"intent":"default_intent","entities":{"contact":[{"confidence":0.5748402256063738,"type":"value","value":"hello","suggested":true}]}}],"WARNING":"DEPRECATED"} debug: RECEIVED MESSAGE debug: CUSTOM FIND CONVO 1297127133704505 1297127133704505
`module.exports = function(bot, controller){
var wit = require('botkit-middleware-witai')({
token: process.env.wit_server_access_token,
logLevel: 'debug',
minConfidence: 0,
});
//Inject wit in receive
controller.middleware.receive.use(wit.receive);
// user said hello
controller.hears(['hello'], 'direct_message',wit.hears, function(bot, message) {
bot.botkit.log("Wit.ai detected entities", message.entities);
bot.reply(message, 'Hey there');
});
};
`
I've used both this repo and the fork that includes an API update, I'm new to Wit, my bot doesn't respond at all once I include the middleware for hears. Any clue?
EDIT: looked at the code, and if I don't get intents
returned it doesn't seem to run at all, so this might be my. Any info would be highly appreciated.
as written in the title, the receive middleware never calls next if message.text evaluates to false
therefore, for instance for attachment messages via facebook messenger, using the middleware will prevent the message from being processed
Doubt it will happen but you should probably call next() if you don't have message,text
middleware.receive = function(bot, message, next) {
if (message.text) {
wit.captureTextIntent(config.token, message.text, function(err, res) {
if (err) {
next(err);
} else {
console.log(JSON.stringify(res));
message.intents = res.outcomes;
next();
}
});
}
};
Hey there,
I noticed an issue where confidence score is not being returned when using botkit-middleware-witai. This is because it is using an old version on node-wit as a dependency.
Would it be possible to get this updated or is there a work around/something else I should be doing?
var VERSION = "20150306" is now deprecated. The latest is '20160516'
Thanks in advance for everything!
Hey guys, just a headsup about the npm package.
It looks like it's not up to date to the latest release from this repo and thus doesn't work with the current Wit API version.
To make it work, I've downloaded the code from this repo directly and included in my project.
In botkit-middleware-witai.js
, the receive
function has this condition:
message.text && message.text.indexOf(bot.identity.id) > -1)
When I directly message the bot, the message.text
doesn't contain the bot's identity so this always condition always fails. I want to be able to DM the bot, and have wit.ai process the message.
This code doesn't working with latest version of wit.ai.
I can't get any intent from wit.ai now.
I'm running into an error while using this middleware along with the example code from the README. My experience with Botkit and Wit.ai is limited so I'm not sure if it's something I'm doing incorrectly or an actual bug.
I've included the code I'm testing with and the output of the console.
const Botkit = require('botkit');
const controller = Botkit.facebookbot({
'access_token': process.env.FACEBOOK_PAGE_TOKEN,
'verify_token': process.env.VERIFY_TOKEN
});
const wit = require('botkit-middleware-witai')({
'token': process.env.WITAI_TOKEN
});
controller.middleware.receive.use(wit.receive);
controller.setupWebserver(process.env.PORT, (err, webserver) => {
controller.createWebhookEndpoints(webserver, controller.spawn());
});
controller.hears(['hello'], 'message_received', wit.hears, (bot, message) => {
bot.reply(message, 'hi!');
});
{
"engines": {
"node": ">=6.0"
},
"dependencies": {
"botkit": "0.4.0",
"botkit-middleware-witai": "howdyai/botkit-middleware-witai"
}
}
14:55:41 web.1 | info: ERROR IN RECEIVE MIDDLEWARE: TypeError: Cannot read property 'id' of undefined
14:55:41 web.1 | at Ware.middleware.receive (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/botkit-middleware-witai/src/botkit-middleware-witai.js:34:62)
14:55:41 web.1 | at Ware.<anonymous> (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/wrap-fn/index.js:45:19)
14:55:41 web.1 | at next (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/ware/lib/index.js:85:20)
14:55:41 web.1 | at Ware.run (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/ware/lib/index.js:88:3)
14:55:41 web.1 | at Object.Botkit.botkit.receiveMessage (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/botkit/lib/CoreBot.js:973:35)
14:55:41 web.1 | at /Users/scottdoxey/git/github/scottdoxeybot/node_modules/botkit/lib/Facebook.js:202:45
14:55:41 web.1 | at Layer.handle [as handle_request] (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/express/lib/router/layer.js:95:5)
14:55:41 web.1 | at next (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/express/lib/router/route.js:131:13)
14:55:41 web.1 | at Route.dispatch (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/express/lib/router/route.js:112:3)
14:55:41 web.1 | at Layer.handle [as handle_request] (/Users/scottdoxey/git/github/scottdoxeybot/node_modules/express/lib/router/layer.js:95:5)
How would I access the intents within this method or would I need to make a separate call to wit.ai? Thanks!
`convo.ask('What can I help with?',function(response, convo) {
convo.say('Great, finding an article for you now...');
console.log("response:" + response.text);
console.log("convo:" + convo.text);
convo.next();
});`
The message.text
value passed to the middleware.receive
function contains the username mentioned, which means it gets set to wit.ai. For example, a "direct_mention" shows up in wit.ai as:
<@U0ZA78R19> testing pt 2
. This may be an issue with how https://github.com/howdyai/botkit works, but is there any way to strip out the user prior to passing it to wit.captureTextIntent
in the case of "direct_mention" and "direct_message"?
In the README, you have:
The results of the call to Wit.ai are added into the incoming message as
message.intents
, and ...
But that should be message.entities
.
With wit.ai new api it's no longer appropriate to classify things off of the intent attribute.
It seems there has to be another strategy to figure it out.
Investigating this.
Getting "WARNING":"DEPRECATED" in the returned payload. I can see my intent in the intent
array, but not on the top object under outcomes
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.