Giter Site home page Giter Site logo

Comments (13)

guidone avatar guidone commented on September 25, 2024

That is an interesting question. Yes it's possible, I've simplified the answer with this flow

api_like_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

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

listen_node

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.

function_node

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

api_ai_flow.txt

from node-red-contrib-chatbot.

ram1505 avatar ram1505 commented on September 25, 2024

Awesome! Thank you so much for such a detailed explanation. Let me try this out and feedback to you.

from node-red-contrib-chatbot.

ram1505 avatar ram1505 commented on September 25, 2024

For some reason, the example that you gave is not working for me. It keeps throwing Age,, in my Telegram chat window.

from node-red-contrib-chatbot.

ram1505 avatar ram1505 commented on September 25, 2024

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)

from node-red-contrib-chatbot.

ram1505 avatar ram1505 commented on September 25, 2024

Hi,
Any clue on why the example flow is not working?

from node-red-contrib-chatbot.

guidone avatar guidone commented on September 25, 2024

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

from node-red-contrib-chatbot.

ram1505 avatar ram1505 commented on September 25, 2024

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?

from node-red-contrib-chatbot.

guidone avatar guidone commented on September 25, 2024

Sorry, it worked the first time and then I cleaned up adding an extra null that was breaking

api_ai_flow.txt

from node-red-contrib-chatbot.

ram1505 avatar ram1505 commented on September 25, 2024

Worked perfectly now. Thanks. I'll experiment with this example.

from node-red-contrib-chatbot.

ram1505 avatar ram1505 commented on September 25, 2024

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.

from node-red-contrib-chatbot.

guidone avatar guidone commented on September 25, 2024

Yes the context variables are persisted unless manually removed (with the context node) or node-red is restarted

from node-red-contrib-chatbot.

ram1505 avatar ram1505 commented on September 25, 2024

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;`

from node-red-contrib-chatbot.

guidone avatar guidone commented on September 25, 2024

.remove() is the method to delete a variable from the chatcontext

from node-red-contrib-chatbot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.