简体   繁体   中英

How to make a tree like based structured conversational action on google?

I want to make an action which ask user a question and answers in yes or no. The answers affect the future of player and gets different questions according to the user answers. And also I want to store the state so that user may resume afterwards. I think a binary tree like structure will work but how implement this in dialogflow.

There are two primary ways to do this.

The first way is to use contexts , which can be dynamically configured to limit the types of intents that can be triggered. This would allow you to develop a tree-like structure in a very precise way. However, this method would be more difficult to manage as you scale.

The alternative is to store data like questions answered and difficulty in session data and have a single Dialogflow intent that is able to capture the user's answer, give them a pass/fail, and provide the next question.

app.intent('My Question', (conv, {answer}) => {
  const {currentQuestion} = conv.data
  if (currentQuestion.answer === answer) {
    conv.ask('Correct!')
    conv.data.difficulty++
  } else {
    conv.ask('Wrong!')
    conv.data.difficulty--
  }
  const nextQuestion = customShuffle(conv.data.allQuestions, conv.data.difficulty)
  conv.data.allQuestions[nextQuestion.id] = undefined
  conv.ask('Next question! ' + nextQuestion.question)
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM