Alexmhack/Django-Rasa-Bot

No chat widget visible

iamabhishekchakraborty opened this issue · 10 comments

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.

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.

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

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.

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.

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.

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

Change that to,

socketUrl: "http://localhost:5005/",

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 *

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.

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