Rasa WebChat

Hi, I have created a chatbot on slack using Rasa-Core and Rasa-NLU by watching this video : Building a chatbot with Rasa NLU and Rasa Core on Vimeo

It works pretty well on Slack.com. But what I need is to add this to our website using a code snippet. When I looked up on that, I was able to find out that RASA Webchat (GitHub - mrbot-ai/rasa-webchat: A simple webchat widget to connect with a chatbot ) can be used to add the chatbot to the website. So, I pasted this code on my website inside the < body > tag.

<div id="webchat"/>
<script src="https://storage.googleapis.com/mrbot-cdn/webchat-0.4.1.js"></script>
<script>
    WebChat.default.init({
        selector: "#webchat",
        initPayload: "/get_started",
        interval: 1000, // 1000 ms between each message
        customData: {"userId": "123"}, // arbitrary custom data. Stay minimal as this will be added to the socket
        socketUrl: "http://localhost:5500",
        socketPath: "/socket.io/",
        title: "Title",
        subtitle: "Subtitle",
        profileAvatar: "http://to.avat.ar",
    })
</script> 

“Run_app.py” is the file which starts the chatbot ( It’s available in the video : Building a chatbot with Rasa NLU and Rasa Core on Vimeo )

Here is the code of Run_app.py :

from rasa_core.channels import HttpInputChannel
from rasa_core.agent import Agent
from rasa_core.interpreter import RasaNLUInterpreter
from rasa_slack_connector import SlackInput



nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/weathernlu')
agent = Agent.load('./models/dialogue', interpreter = nlu_interpreter)

input_channel = SlackInput('xoxp-381510545829-382263177798-381274424643-a3b461a2ffe4a595e35795e1f98492c9', #app verification token
							'xoxb-381510545829-381150752228-kNSPU0X7HpaS8oJaqd77TPQE', # bot verification token
							'B709JgyLSSyKoodEDwOiJzic', # slack verification token
							True)

agent.handle_channel(HttpInputChannel(5004, '/', input_channel))

I want to connect this python chat-bot to the “Rasa-webchat” instead of using Slack. But I don’t know how to do that. I tried looking everywhere, But I couldn’t find anything helpful on the internet. Can someone help me? Thank you.

1 Like

Hi Dilanka,

you need two things:

  1. You need to setup a socket channel as described here: Socket.io Channel Setup
  2. In the widget snippet, you need to add your socketUrl and socketPath

OT: I found myself in a similar situation a few weeks ago. Depending on your use case, instead of using the Rasa webchat widget, it could be useful to setup a Messenger bot and just use the Facebook chat widget snippet on your website as well. For me, as I wanted a Messenger bot with all its features (e.g. button types), this was the easier way to do it.

1 Like

Thank you Simon,

I just changed the ,py file like this :

from rasa_core.channels import HttpInputChannel
from rasa_core.agent import Agent
from rasa_core.interpreter import RasaNLUInterpreter
from rasa_slack_connector import SlackInput

from rasa_core.channels.socketio import SocketIOInput
from rasa_core.agent import Agent
from rasa_core.interpreter import RegexInterpreter




nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/weathernlu')

agent = Agent.load('./models/dialogue', interpreter = nlu_interpreter)

 

input_channel = SocketIOInput(user_message_evt="user_uttered", bot_message_evt="bot_uttered", namespace=None)

    # set serve_forever=False if you want to keep the server running
s = agent.handle_channels([input_channel], 5004, serve_forever=False)

I’m getting this error now :

(base) C:\Users\Dilanka's laptop\Desktop\Chatbot\bot>run_app.py
Traceback (most recent call last):
  File "C:\Users\Dilanka's laptop\Desktop\Chatbot\bot\run_app.py", line 6, in <module>
    from rasa_core.channels.socketio import SocketIOInput
ModuleNotFoundError: No module named 'rasa_core.channels.socketio'

That looks weird. Can you share your rasa_core version?

Quick idea: Can you try importing it like this:

from rasa_core.channels import SocketIOInput

Still I’m getting this error :

(base) C:\Users\Dilanka's laptop\Desktop\Chatbot\bot>run_app.py
Traceback (most recent call last):
  File "C:\Users\Dilanka's laptop\Desktop\Chatbot\bot\run_app.py", line 6, in <module>
    from rasa_core.channels import SocketIOInput
ImportError: cannot import name 'SocketIOInput'

Can you please tell me how to check the rasa core version?

Strange, I just tested the same on my machine and it works as expected.

In your python shell you can just type:

import rasa_core
rasa_core.__version__

In the same shell, can you then also try to import the socketio input:

from rasa_core.channels.socketio import SocketIOInput

Does it throw an error there as well?

I’m getting this error on both Anaconda prompt and windows CMD.

(base) C:\Users\Dilanka's laptop>import rasa_core
'import' is not recognized as an internal or external command,
operable program or batch file.

(base) C:\Users\Dilanka's laptop>rasa_core.__version__
'rasa_core.__version__' is not recognized as an internal or external command,
operable program or batch file.

(base) C:\Users\Dilanka's laptop>from rasa_core.channels.socketio import SocketIOInput
'from' is not recognized as an internal or external command,
operable program or batch file.

Please Help!! :frowning:

Hi Dilanka, sorry for the late reply. You need to enter a Python shell, e.g. by just typing python in your CMD. Then you can try importing rasa_core.

Hi Dilanka , Did you get a solution for this. I am also stuck in the same scenario.

I am not sure the above error got resolved or not. I believe you have tried the demo Weatherbot based from the Video using Slack. If we want to switch to Socket IO - we have to first socket io then try compiling run_app.py.

More details: if you look at the error, it says from rasa_core.channels import SocketIOInput ImportError: cannot import name ‘SocketIOInput’

You can check your installed location of rasa_core and it doesnt have socket.io.py. I did faced the issue and after importing I am able to execute run_app.py. Now I got stuck in receiving messages from front end app (react or javascript app). I am getting the message in the Bot server “405 error” (Method not allowed). Any Help is highly appreciated.

what rasa version you are using ?