2

我正在按照本教程使用 Recast AI 制作 FB 聊天机器人。尝试将我的机器人与令牌连接,但出现以下错误:

var client = new recastai(config.recast);
         ^
TypeError: recastai is not a function
    at Object.<anonymous> (/home/ubuntu/workspace/app/pokebot.js:5:14)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:990:3

这是我的代码:

const config = require("./config.js");
const restify = require("restify");
const builder = require("botbuilder");
var recastai = require('recastai');
var client = new recastai(config.recast);

const connector = new builder.ChatConnector({
    appId: config.appId,
    appPassword: config.appPassword
});

bot.dialog("/", (session) => {
    client.textRequest(session.message.text)
    .then(res => console.log(res))
    .catch(() => session.send('I need some some sleep right now.. Talk to me 
 later!'));
});

const server = restify.createServer();
server.listen(8080);
server.post("/", connector.listen());

谁能帮我?谢谢!

4

3 回答 3

3

var client = new recast.Client(config.recast)如果我是正确的,它应该是。

于 2017-04-11T10:00:10.047 回答
1

我不得不将我的 Node 版本降级到 v4.7.3 而不是 6,现在它可以工作了。var client = new recast.Client(config.recast) 对我不起作用,不过感谢您的帮助!

于 2017-05-09T08:07:52.200 回答
0

我从 Recast starter repo (github.com:RecastAI/starter-NodeJS.git) 开始。

这就是 SDK 的导入方式。这个对我有用。

const recastai = require('recastai').default
const client = new recastai(process.env.REQUEST_TOKEN)
client.connect.handleMessage({ body }, response, replyMessage)
于 2017-05-10T02:38:32.167 回答