Search code examples
javascriptchatbotsap-conversational-ai

Recastai is not a function


I am following this tutorial to make FB chat bot with Recast AI. Trying to connect my bot with the token but get the following error:

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

Here is my code:

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());

Can anyone help me? Thanks!


Solution

  • I had to downgrade my Node version to v4.7.3 instead of 6, and now it works. var client = new recast.Client(config.recast) didn't work for me, thanks for the help though!