Start conversation with Wit.ai chat bot in node.js
<p>I have created a story on <code>wit.ai</code> using the quickstart guide.</p>

<p>Now I want to make a conversation with my chat bot using <code>node-wit</code> in <code>node.js</code>.</p>

<p>I guess I should use <a href="https://github.com/wit-ai/node-wit#runactions" rel="nofollow">https://github.com/wit-ai/node-wit#runactions</a> 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.</p>

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

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

<pre><code>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) =&gt; {
      console.log(context);
      sessions[sessionId].context = context;
    }).catch((err) =&gt; {
      console.error('Error: ', err.stack || err);
    });
  });
});
</code></pre>

<p>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?</p>