Alexmhack / Django-Rasa-Bot

Integrating Rasa Core with Django backend and finally using Webchat for chatbot user interface
32 stars 25 forks source link

No chat widget visible #13

Closed iamabhishekchakraborty closed 1 year ago

iamabhishekchakraborty commented 4 years ago

Hey @Alexmhack ... I cloned the entire repo and used it as-is (minimal changes w.r.t data and models) but whatever I have tried till now not able to view the chat widget in the browser once the url is opened. Let me know what information you would require on this aspect. Thanks in advance.

Alexmhack commented 4 years ago

Are there any errors in the browser console, send me a screenshot and have you implemented the basic setup given in the usage section of the repo.

iamabhishekchakraborty commented 4 years ago

Yes, I have my own data and stories, trained the rasa nlu and core based on that. The rasa chatbot works independently. Looking at the errors in browser console, I strongly feel there is definitely a configuration miss not able to trace it though. Screenshot for django server run details - image Screenshot for bot.py run - image Screenshot of browser console - image

Alexmhack commented 4 years ago

The problem seems to be with the rasa server which is not accepting any requests from django due to CORS, try this instead of running bot.py file for rasa server,

Create a new file inside rasachat folder and name it credentials.yml and add this piece of code in it,

socketio:
  user_message_evt: user_uttered
  bot_message_evt: bot_uttered

Now run the below command for rasa server,

python -m rasa_core.run -d models/dialogue -u models/current/nlu --credentials credentials.yml --cors *

Let me know if this works, also try checking out some other issues on this repo on the same problem.

iamabhishekchakraborty commented 4 years ago

Added the credentials.yml and invoked the rasa server, here are the results - Django run details: image rasa run details: image Browser console: image No chat widget visible yet but don't have the CORS error. I have one doubt in this, the django app is running on http://127.0.0.1:8000/ and when rasa server is invoked through the command it says that Rasa Core server is up and running on http://localhost:5005, but I haven't passed any endpoint(--endpoints endpoints.yml) through command line.

I will look for any sort of similar issue and if found will post here.

Alexmhack commented 4 years ago

You can change the rasa server url in templates/index.html by,

                           <div id="webchat">
                                ... 
                <script>
                    WebChat.default.init({
                                        ...
                        socketUrl: "http://localhost:5500/",  // <- changing the url here
                        ...
                    })
                </script>
                            </div>

Try changing this url or like you said use --endpoint option for another server url.

iamabhishekchakraborty commented 4 years ago

I change it to this - socketUrl: "http://127.0.0.1:8000", socketPath: "/socket.io/", Now when I run django app I get this: Django version 2.1, using settings 'chatsite.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. Not Found: /socket.io/ [04/Nov/2019 21:36:28] "GET /socket.io/?EIO=3&transport=polling&t=MutAkD5 HTTP/1.1" 404 2249 Console error: webchat-0.5.8.js:33 GET http://127.0.0.1:8000/socket.io/?EIO=3&transport=polling&t=MutAno3 404 (Not Found) Error: xhr poll error at c.i.onError (webchat-0.5.8.js:6) at l. (webchat-0.5.8.js:33) at l.r.emit (webchat-0.5.8.js:6) at l.onError (webchat-0.5.8.js:33) at webchat-0.5.8.js:33

Alexmhack commented 4 years ago

Change that to,

socketUrl: "http://localhost:5005/",
iamabhishekchakraborty commented 4 years ago

Doing that it brings back the CORS error - Access to XMLHttpRequest at 'http://localhost:5005/socket.io/?EIO=3&transport=polling&t=MutDZcM' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. 127.0.0.1 - - [2019-11-04 21:48:50] "GET /socket.io/?EIO=3&transport=polling&t=MutDZcM HTTP/1.1" 400 122 0.001990 127.0.0.1 - - [2019-11-04 21:48:57] "GET /socket.io/?EIO=3&transport=polling&t=MutDb48 HTTP/1.1" 400 122 0.000997

even though I am running the rasa server like this - python -m rasa_core.run -d models/dialogue -u models/current/nlu --credentials credentials.yml --cors *

Alexmhack commented 4 years ago

Try changing the Django settings,

# allow cors headers
# CORS_ORIGIN_ALLOW_ALL = True  # <- comment out and write the below line

CORS_ORIGIN_WHITELIST = [
    'http://localhost:5005'
]

If this also doesn't work then try googling the error and tweak the code to make it work.

akshay1892 commented 4 years ago

I faced the same issue....then instead of web socket channel I used rest channel as mentioned in the the official link. https://rasa.com/docs/rasa/user-guide/connectors/your-own-website/#restinput

https://github.com/scalableminds/chatroom