Ich versuche, die neue wit.ai Bot Engine mit Javascript zu Hubot zu verbinden. Leider bin ich kein JS Entwickler, also kämpfe ich.wit.ai Bot Engines Stories verbunden mit hubot
Hier ist der Code, den ich habe:
'use strict';
const Wit = require('../../../node-wit').Wit;
const firstEntityValue = (entities, entity) => {
const val = entities && entities[entity] &&
Array.isArray(entities[entity]) &&
entities[entity].length > 0 &&
entities[entity][0].value
;
if (!val) {
return null;
}
return typeof val === 'object' ? val.value : val;
};
const actions = {
say: (sessionId, msg, cb) => {
console.log(msg);
cb();
},
merge: (context, entities, cb) => {
const loc = firstEntityValue(entities, "location");
if (loc) context.loc = loc;
cb(context);
},
error: (sessionId, msg) => {
console.log('Oops, I don\'t know what to do.');
},
'fetch-weather': (context, cb) => {
// Here should go the api call, e.g.:
// context.forecast = apiCall(context.loc)
context.forecast = 'sunny';
cb(context);
},
};
const client = new Wit('MY_TOKEN_HERE', actions);
client.interactive();
module.exports = function(robot) {
robot.respond(/hey\s+(.+$)/i, function(msg){
var match = msg.match[1];
msg.send("I've heared: " + match);
console.log(match)
process.stdout.write(match);
});
}
Das Skript hört "hey botname" und gibt, was danach geschrieben wurde. Mein Problem ist, ich habe keine Ahnung, wie diese Eingabe an den Wit-Client gesendet wird. Die Verwendung dieses Skripts in bash ohne den hubot-Kram funktioniert gut, da dies auf dem Schnellstart-Beispiel von wit.ai basiert.
Das andere Problem, mit dem ich konfrontiert bin, ist, dass ich möchte Hubot hören in einem privaten Kanal mit jedem Benutzer und haben es auf jede Nachricht ohne Präfix reagieren. So wie es das Knotenbeispiel in der Konsole macht.
Hilfe ist sehr geschätzt!