dmitrizzle / chat-bubble

Simple chatbot UI for the Web with JSON scripting 👋🤖🤙
MIT License
579 stars 171 forks source link

How to call JS function when an option is selected? #66

Closed hamzaLeb closed 5 years ago

hamzaLeb commented 5 years ago

Hi everyone, I am using chat-bubble for a django application which answers users questions. In my use case I have to process the user input question before giving the answer back.

When the user directly types in a question, I figured out how to process the question with Python and send the answer back to JS (this is done using ajax, see my answer here for further information).

Now the problem comes when the user chose an option, in this case I can't find a way to do some processing and/or call a JS function depending on the option chosen. For example, in the keyboard input example, if we want to compute the number of times the 'banana' option is chosen along the conversation, how can we do that? Or, simplier, how can we call alert('you chosed banana') each time 'banana' is chosen?

In my case I need to record user feedback (options: 'good answer' vs 'bad answer') after each response to improve the chatbot reasoning afterward.

Hope the issue is well explained, thanks for your support 💯

dmitrizzle commented 5 years ago

Does this example help? It shows how to run a JavaScript function in response to user click: https://github.com/dmitrizzle/chat-bubble/blob/master/examples/4-run-scripts.html

hamzaLeb commented 5 years ago

It worked perfectly good, thank you!