Answer the question
In order to leave comments, you need to log in
How to make a sequential JS bot?
There is a code that works with certain entered words:
var message = 'хочу заказать пиццу';
if(message.indexOf('пиццу') + 1) { //если в предложении есть слово "пиццу"
alert('с чем пиццу хотите?');
}
var message = 'я хочу Гавайскую';
if(message.indexOf('пиццу') + 1) { //если в предложении есть слово "Гавайскую"
alert('Какого размера должна быть ваша пицца?');
}
Answer the question
In order to leave comments, you need to log in
The question is kind of vague.
The logical answer to your question is to simply nest the condition in your if(message.indexOf('pizza') + 1).
Preliminarily get a list of pizzas by ajax and then extract the name of the pizza using a regular expression.
Agree with previous post.
And only this will work) https://jsfiddle.net/sdhqkpxn/4/
Remember, your bot should always have a state. Regarding which the bot will expect some answers.
First, draw a diagram of the dialogue, what are the possible questions and what are the answers, and what are the next questions after the answers you will ask.
And then, a bunch of IF / THEN / ELSE in the code (if it's stupid on the forehead), or some DSL to make it all easy to support.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question