2

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!

Sébastien
  • 21
  • 3
chemook78
  • 1,058
  • 3
  • 12
  • 35

3 Answers3

3

It should be var client = new recast.Client(config.recast) if I am correct.

King Reload
  • 3,430
  • 12
  • 35
  • Im having the same problem. I tried both recast and recast.Client. Neither one is working for me. Any more progress on this? – Joel May 05 '17 at 08:30
  • 1
    @Joel maybe it's now the problem of how you call to it, but maybe something else? Else I have this sample left for you: https://github.com/RecastAI/SDK-NodeJs – King Reload May 05 '17 at 08:40
1

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!

chemook78
  • 1,058
  • 3
  • 12
  • 35
0

I started from the Recast starter repo (github.com:RecastAI/starter-NodeJS.git).

This is how the SDK is imported. It works for me.

const recastai = require('recastai').default
const client = new recastai(process.env.REQUEST_TOKEN)
client.connect.handleMessage({ body }, response, replyMessage)
Joel
  • 1,281
  • 2
  • 10
  • 18