I have created a chatbot on slack using Rasa-Core and Rasa-NLU by watching this video : https://vimeo.com/254777331
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 (https://github.com/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 : https://vimeo.com/254777331 )
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.
In order to connect Rasa Core with your web chat do the following:
Create a credentials file (credentials.yml
) with the following content:
socketio:
user_message_evt: user_uttered
bot_message_evt: bot_uttered
Start Rasa Core with the following command (I assume you have already trained your model):
python -m rasa_core.run \
--credentials <path to your credentials>.yml \
-d <path to your trained core model> \
-p 5500 # either change the port here to 5500 or to 5005 in the js script
Since you specified the socketio configuration in your credentials file, Rasa Core automatically starts the SocketIO Input Channel which the script on your website then connects to.
To add NLU you have to options:
-u <path to model>
in your Rasa Core run
command The Rasa Core documentation might also help you.