Closed ram1505 closed 7 years ago
That is an interesting question. Yes it's possible, I've simplified the answer with this flow
The chatbot here is used like a state machine, in the default state it try to parse the user input trying to get age, gender and the occupation, when the state (the chat context variable "topic") turns into "complete" the flow proceed in the upper side of the flow. This is the purpose of the topic node
The parse node tries to extract values from the natural language, I've added just a few combination, but there's no limit
Refer to the listen node docs. For example the rule "I" + "am" + "[number]->age" is satisfied if the user sentence contains the keyword "I", the keyword "am" and a number (it doesn't matter if it's written in number or letters) and store it in the "age" variable of the chat context. In order to catch a sentence that doesn't match anything add a rule with just "*" as last element and provide any kind of feedback.
The function node gets all variables from the chat context and redirects the flow to the right output if some variable is missing, for example if the gender is missing it goes through the second output triggering a question with inline buttons.
If all variables are present and validated, the topic is switched to "complete" and the flow is redirected in the upper part.
Here is the exported flow
Awesome! Thank you so much for such a detailed explanation. Let me try this out and feedback to you.
For some reason, the example that you gave is not working for me. It keeps throwing Age,, in my Telegram chat window.
Also, is it possible to use the Listen node with Quick replies in FB? I've plans to add some quick replies for each question, for instance
1) Fav color? (quick reply will have Red, Green, White etc) 2) Fav place? (quick reply will have something like London, Paris, Singapore etc) 3) Fav food? (Pasta, Pizza, etc)
Hi, Any clue on why the example flow is not working?
It keeps asking the age because the listen node doesn't understand the sentence and immediately ask the first question. The example flow is quite basic.
The usability of the flow can be improved adding a final rule with just a "*" and connect that to message node that gives back a "I didn't understand" message to the user.
The listen node rules need to be constantly tuned to better understand the user input, here is the doc of the listen node
https://github.com/guidone/node-red-contrib-chatbot#parse-sentences
It uses this library for natural language processing
https://github.com/nlp-compromise/compromise
I suggest to enable the debug of listen node and check the console to see how the library split the entities of each sentence and then improves the rules for a better match
What I mean was, it doesn't even prompt any questions for me. It straightaway prints on debug "Age,,," and when I notice the topic it says complete. I'm sorry, but did the flow work for you?
Sorry, it worked the first time and then I cleaned up adding an extra null that was breaking
Worked perfectly now. Thanks. I'll experiment with this example.
Oh wait..once the variable gets stored, it wont ask me the questions second time? When I talk to the bot, it already is throwing out the recorded variables based on my previous chat.
Yes the context variables are persisted unless manually removed (with the context node) or node-red is restarted
Ok, I got it working by having 4 separate Context nodes right after Telegram Receiver that are set to Delete the 3 variables and the topic upon each new message received. Is there a simpler way? I tried the below function and it didn't work. Not sure if chat.delete is a valid command.
var chat = msg.chat();
chat.delete('age');
chat.delete('gender');
chat.delete('job');
chat.delete('topic');
return msg;`
.remove() is the method to delete a variable from the chatcontext
How can I create a canned connected conversation with anyone who initiates a chat via FB messenger? What I'm trying to do is to mimic API.AI with Redbot. I would like to get the response from a user for a multiple choice question and make the output as a single JSON formatted output.
For instance, you can think of a scenario like Q1. What is your Age? Q2. Male or Female? Q3. Occupation Q4. Phone Number
While asking these questions, I would like the chatbot to follow a set of pre-defined question that will guide the user to mandatorily give the expected output (like how API.AI and Rivescript does).
Can such a scenario be built using Redbot? I would like to mimic how the API.AI works with redbot.