2

nodejsでWatson会話APIを使ってサンプルアプリを作成しています。ユーザー名を取得してワトソンに送信しようとしていて、「$username」と挨拶したいのですが、ユーザーが名前を覚えているかどうか尋ねた場合にワトソンが言うことができるように、会話全体でそれを保持したいと思います「はい、「$ユーザー名」」.

サンプルコード、このユースケースでインテントを使用する方法を教えてください。

    // Start conversation with Hello message.
conversation.message({
  input: { text: "Hello" },
    }, processResponse);

// Process the conversation response.
function processResponse(err, response) {
  if (err) {
    console.error(err); // something went wrong
    return;
  }

  // If an intent was detected, log it out to the console.
  if (response.intents.length > 0) {
    //console.log('Detected intent: #' + response.intents[0].intent);
    console.log(response.context)
  }

  // Display the output from dialog, if any.
  if (response.output.text.length != 0) {
      console.log("Watson : "+response.output.text[0]);
  }

  // Prompt for the next round of input.
    var newMessageFromUser = prompt('Me : ');
    // Send back the context to maintain state.
    conversation.message({
      input: { text: newMessageFromUser },
      context : response.context,
    }, processResponse)
}
4

1 に答える 1