2

I have created a story on wit.ai using the quickstart guide.

Now I want to make a conversation with my chat bot using node-wit in node.js.

I guess I should use https://github.com/wit-ai/node-wit#runactions to run the messages, but I'm not sure how to start a conversation that never ends. I need to send a message and then get the response from the chat bot until I break the conversation.

I have looked through the wit.ai examples, but I cannot find any example of how to start a simple conversation in node.js.

I use socket.io to transmit the messages between client and server, and I have tried to solve my problem with

let sessions = {};
const sessionId = new Date().toISOString();
sessions[sessionId] = { context: {} };

io.on('connection', function (socket) {
  socket.on('new message', function (message) {
    client.runActions(
      sessionId,
      message,
      sessions[sessionId].context
    ).then((context) => {
      console.log(context);
      sessions[sessionId].context = context;
    }).catch((err) => {
      console.error('Error: ', err.stack || err);
    });
  });
});

and it seems to almost work. I can chat with my bot, but it messes up the stories by sometimes answering multiple times from different stories. I guess I should probably end the stories somehow?

Jamgreen
  • 10,329
  • 29
  • 113
  • 224

3 Answers3

2

You should try with this link https://github.com/wit-ai/node-wit/blob/master/examples/quickstart.js

Just clone/download the whole node-wit module from git or npm-install.

Then just run the command node quickstart.js "wit-token".

wit-token == wit-app-token

it will work .

sanster_23
  • 800
  • 10
  • 17
0

Have you checked this Facebook Messenger integration example. The quickstart.js includes an interactive mode this is why it may be confusing.

l5t
  • 578
  • 2
  • 5
0

Look at the messenger.js example on how to use runActions and send messages back to Messenger. I was successful in doing this, although I'm still working on stories.

bvsdev
  • 1
  • 2