私は新しいwit.aiボットエンジンをハブトにJavascriptで接続しようとしています。 残念ながら私はJS開発者ではないので、苦労しています。wit.aiボットエンジンストーリーがハブットに接続
は、ここに私が持っているコードです:
'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);
});
}
スクリプトは、「botnameねえ」リッスンし、この後に書かれたものを出力します。私の問題は、私はこの入力をウィットクライアントに送るための手がかりがないということです。このスクリプトをbashで使用すると、wit.aiのクイックスタートの例に基づいているので、ハッボットのものはうまく動作しません。
私が直面しているもう一つの問題は、私がハプットにプライベートチャンネルですべてのユーザを聞いて、プレフィックスなしですべてのメッセージに応答させたいということです。コンソールのノードの例と同じです。
ヘルプは非常に便利です!