Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a bubble button callback and rasa integration demo. #79

Merged
merged 5 commits into from
Jan 20, 2021

Conversation

shashwatrathod
Copy link
Contributor

Bubbles.js

Added a callback function called bubbleCallbackFn which is called whenever a user clicks on a 'bubble-pick' element. This is useful for scenarios where the action to be taken is not necessarily known or defined in the 'convo', like NLC tasks.

7-Rasa_demo.html

It demonstrates the integration of a famous NLC framework - RASA with chat-bubble. It also provides a usecase for bubbleCallbackFn.
To use this, a RASA server has to set up. The port and URL have to be edited in the html file. After the ice, the user can enter any text and the output will be delivered through RASA.

I think chat-bubble is a very powerful and easy tool to use. These changes will help demonstrate the versatility of the project. Thanks
!

Copy link
Owner

@dmitrizzle dmitrizzle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shashwatrathod,

Thank you for this example! This tool was meant to be used with NLC from day one but I couldn't add an example yet. So thank you, this is very useful.

I've added a few comments to your code. It looks good, just a few changes to make for consistency and readability.

Most importantly, I'd like to learn about the tool you're using for NLC and be able to replicate your process. I think it would be helpful for all developers interested in this library to do this. Could you start a README_RASA.md with basic info and steps on how to build the server (or perhaps a link to the RASA's relevant docs?)

I understand those changes may bee too much. If you don't have time to make them, I can apply them to your branch or a copy of your branch (depending on GH permissions) - unless you object.

Cheers,
-d.

@@ -8,6 +8,7 @@ function Bubbles(container, self, options) {
sidePadding = options.sidePadding || 6 // padding on both sides of chat bubbles
recallInteractions = options.recallInteractions || 0 // number of interactions to be remembered and brought back upon restart
inputCallbackFn = options.inputCallbackFn || false // should we display an input field?
bubbleCallbackFn = options.bubbleCallbackFn || false // is there a callback function for when a user clicks on a bubble button
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we name this responseCallbackFn to match inputCallbackFn naming a little closer?

// initialize by constructing a named function...
// ...and add text processing plugin:
function makeid() {
var result = '';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the spacing in this file is a little different from the rest of the project. Can you either 1) adjust it so it matches the rest of the project a little better 2) add prettier package so it does all of that automatically?

//A unique client id so that the data soesn't get mismatched
const client_id = makeid()

console.log(client_id)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please keep debug logs out of production code.

}

//the port at which RASA is running
port = '1001'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing variable keyword declaration var


var miss = function(text_inp = null){
let xhr = new XMLHttpRequest()
let url = "http://localhost:"+port+"/webhooks/rest/webhook"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this example requires running another server. I think we should explain how to start this server so that the example can be useful to all developers.

let xhr = new XMLHttpRequest()
let url = "http://localhost:"+port+"/webhooks/rest/webhook"

let input = false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this project, we can only use var for compatibility with older browsers. I haven't added any transpilers.

@shashwatrathod
Copy link
Contributor Author

Hello,
I have noted the changes to be done and I will start working on them. I will also create the README_RASA.md which might act as a beginner's guide to the framework.

Thanks!

@shashwatrathod
Copy link
Contributor Author

Hello!
I have made the changes you requested for! I have added a very brief guide showing how to get started with Rasa and use chat-bubble to communicate with Rasa servers. I also prettier-fied example/7-Rasa_demo.html .

@dmitrizzle
Copy link
Owner

Hi @shashwatrathod, thank you for the changes!

I've tried to run the example on my machine but there are XHR errors both when I run the file from the filesystem and when I try to serve it with [serve](https://www.npmjs.com/package/serve). Do you know what may be the issue?
Screen Shot 2020-12-06 at 11 56 19 AM

@shashwatrathod
Copy link
Contributor Author

shashwatrathod commented Dec 7, 2020

Hello,
I created a basic RASA project and tried serving ChatBubble using serve. It works fine for me. However, by the error you're getting, it seems like one of the two following steps could solve this issue:

  1. Make sure that you pass the "--enable-api" and "--cors *" argument while serving RASA. The command should look like this:
    rasa run --enable-api --cors * -p 1001.
    Find the reference for 'rasa run' here.

  2. Navigate to path/to/rasa/project/credentials.yml and add the following lines in the file to enable REST input:
    rest:
    image
    Find the reference in RASA docs here

I hope this solves your issue!

Regards

@dmitrizzle
Copy link
Owner

Nope, no luck. I tried adding a "callback" as per docs, used the credentials example and ran from the terminal with --enable-api --cors * -p 1001. Did you have to disable same-origin policy within your browser or have any other settings in your app which may have helped with CORS?
Screen Shot 2020-12-08 at 9 00 39 AM

@dmitrizzle dmitrizzle mentioned this pull request Jan 20, 2021
@dmitrizzle dmitrizzle merged commit 4f6c842 into dmitrizzle:master Jan 20, 2021
@dmitrizzle
Copy link
Owner

Hey @shashwatrathod, I merged your code in #85 with some minor tweaks. Turns out there were quotes missing from --cors '*' flag, adding the ' fixed everything. I'm usually much quicker with these things but the past few months have been insane for me both personally and at work.

Thank you again for your work, I really appreciate your contribution!

@shashwatrathod
Copy link
Contributor Author

shashwatrathod commented Jan 21, 2021

Hey! @dmitrizzle, thank you very much! I was also caught up in a couple of things this past month, so it was really generous of you to find that bug for me. chat-bubble is a nice project and it was fun to make this little contribution!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants