Connecting to Webchat

Hello everybody,

I am trying to connect this webchat widget to rasa (GitHub - botfront/rasa-webchat: A feature-rich chat widget for Rasa and Botfront), but I am getting this error in my console:

and this error on my connector console:

( By the way, two days ago I did not have this error in my connector, I was using this Package in Angular (angular-chat-widget-rasa - npm), but now I can’t even connect to this one also.)

I pasted this code on my website inside the < body > tag.

<body>
    <div id="webchat">
        <script src="https://storage.googleapis.com/mrbot-cdn/webchat-latest.js"></script>
        <script>
            WebChat.default.init({
                selector: "#webchat",
                initPayload: "/get_started",
                interval: 1000, // 1000 ms between each message
                customData: { "sender": "django" }, // arbitrary custom data. Stay minimal as this will be added to the socket
                socketUrl: "https://localhost:5002",
                title: "Connect",
                subtitle: "The bot which connects people",
                profileAvatar: "https://rasa.com/assets/img/demo/rasa_avatar.png",
                showCloseButton: true,
                fullScreenMode: false,
                hideWhenNotConnected: false,
            })
        </script>
    </div>

</body>

and here is the code of my connector:

from rasa.core.agent import Agent
from rasa.core.interpreter import RasaNLUInterpreter
from rasa.core.channels.socketio import SocketIOInput
from rasa.utils.endpoints import EndpointConfig

agent = Agent.load("./models/20190807-131628",
                   action_endpoint=EndpointConfig(url="http://localhost:5055/webhook"))

input_channel = SocketIOInput(
    # event name for messages sent from the user
    user_message_evt="user_uttered",
    # event name for messages sent from the bot
    bot_message_evt="bot_uttered",
    # socket.io namespace to use for the messages
    namespace=None
)

s = agent.handle_channels([input_channel], 5002)

Operating system macOS Mojave version 10.14.5 Rasa Version 1.0.9

Please help me solve this problem, Thanks

1 Like

hi @alainkhoury i want to do the same but i can’t find steps to do it can you give me how did you get this? thank you

Hi @SallemiDorsaf,

1- Go to the docs for Agent class Agent , there you can see how to load an Agent using your model and how to handle a channel.

2- Webchat use socket.io to communicate with Rasa, so we need a socket.io input channel, you can use this class rasa/socketio.py at master · RasaHQ/rasa · GitHub

and for the interface, you just need to paste this in the body tag and change the socketUrl if your bot is listening on different port

<div id="webchat">
        <script src="https://storage.googleapis.com/mrbot-cdn/webchat-latest.js"></script>
        <script>
            WebChat.default.init({
                selector: "#webchat",
                initPayload: "/get_started",
                interval: 1000, // 1000 ms between each message
                customData: { "sender": "django" }, // arbitrary custom data. Stay minimal as this will be added to the socket
                socketUrl: "https://localhost:5002",
                title: "Connect",
                subtitle: "The bot which connects people",
                profileAvatar: "https://rasa.com/assets/img/demo/rasa_avatar.png",
                showCloseButton: true,
                fullScreenMode: false,
                hideWhenNotConnected: false,
            })
        </script>
    </div>

I hope this helps you

1 Like

@alainkhoury thank youu but can you tell me how connect my bot with socket io

yes even I would like to know how to connect to socketio exactly

did you find any answer for this

pretty bad no one knows the answer ":frowning: