Using rasa with socketio and nodejs backend

I’m trying to setup rasa with a nodejs backend. I communicate to the rasa core server using socketio. I’m using the webchat widget and I can correctly communicate with the bot, however the messages persist between refreshes and I don’t understand how to separate chats among users. How can separate chats among users?

Hi @laujen. Are you using the official socketio channel?

yes I just added the following in the credentials.yml

socketio:
  user_message_evt: user_uttered
  bot_message_evt: bot_uttered
  session_persistence: true

@laujen What webchat widget are you using?

@tyd I’m using this one GitHub - botfront/rasa-webchat: A feature-rich chat widget for Rasa and Botfront with the standard configuration in react:

<Widget
     initPayload={"/get_started"}
     socketUrl={"http://localhost:5005"}
     socketPath={`/socket.io/`}
     customData={{"language": "en",
     "user_id": 123,
     "session_id": 123
   }} // arbitrary custom data. Stay minimal as this will be added to the socket
     title={"Title"}
   />

When the webchat component connects I get this message in console

connect:c0d9b4a0a3c84f29b1cf91dd37d0d1e5 index.js:96
session_confirm:c0d9b4a0a3c84f29b1cf91dd37d0d1e5 session_id:e6737cd2c53f445ca314fc7431fee954 index.js:96

I assume I have to send some customData through the webchat component but I don’t seem to be able to send anything through. When I send a message hello through my frontend, the docker console shows this output:

rasa_1           | 2020-10-29 11:02:31 DEBUG    rasa.core.lock_store  - Issuing ticket for conversation 'e6737cd2c53f445ca314fc7431fee954'.
rasa_1           | 2020-10-29 11:02:31 DEBUG    rasa.core.lock_store  - Acquiring lock for conversation 'e6737cd2c53f445ca314fc7431fee954'.
rasa_1           | 2020-10-29 11:02:31 DEBUG    rasa.core.lock_store  - Acquired lock for conversation 'e6737cd2c53f445ca314fc7431fee954'.
rasa_1           | 2020-10-29 11:02:31 DEBUG    rasa.core.tracker_store  - Recreating tracker for id 'e6737cd2c53f445ca314fc7431fee954'
rasa_1           | 2020-10-29 11:02:31 DEBUG    rasa.core.processor  - The latest session for conversation ID 'e6737cd2c53f445ca314fc7431fee954' has expired.
rasa_1           | 2020-10-29 11:02:31 DEBUG    rasa.core.processor  - Starting a new session for conversation ID 'e6737cd2c53f445ca314fc7431fee954'.
rasa_1           | 2020-10-29 11:02:31 DEBUG    rasa.core.processor  - Action 'action_session_start' ended with events '[<rasa.shared.core.events.SessionStarted object at 0x7f16f8086e50>, <rasa.shared.core.events.ActionExecuted object at 0x7f16c862f610>]'.
rasa_1           | 2020-10-29 11:02:31 DEBUG    rasa.core.processor  - Current slot values: 
rasa_1           | 	appointment_type: None
rasa_1           | 	requested_slot: None
rasa_1           | 	time: None
rasa_1           | 2020-10-29 11:02:31 DEBUG    rasa.nlu.classifiers.diet_classifier  - There is no trained model for 'ResponseSelector': The component is either not trained or didn't receive enough training data.
rasa_1           | 2020-10-29 11:02:31 DEBUG    rasa.nlu.selectors.response_selector  - Adding following selector key to message property: default
rasa_1           | 2020-10-29 11:02:31 DEBUG    rasa.core.processor  - Received user message 'hello' with intent '{'id': -8126804286673417350, 'name': 'greet', 'confidence': 0.9944643378257751}' and entities '[]'

I assume customData should be visible together with the message but I may be wrong.

Ideally I would be able to send the mongodb userId through the webchat client to perform database operations in custom actions

@laujen I am not super familiar with this chat widget, but I would assume to separate chats among users, you would want to use a different user_id for each user

how can I pass a user_id to rasa?

I assume by looking at this that it should be definitely possible but I don’t understand how to pass customData or other data through to rasa.

By default, the SocketIO channel uses the socket id as sender_id, which causes the session to restart at every page reload. session_persistence can be set to true to avoid that. In that case, the frontend is responsible for generating a session id and sending it to the Rasa Core server by emitting the event session_request with {session_id: [session_id]} immediately after the connect event.

The example Webchat implements this session creation mechanism (version >= 0.5.0).

otherwise do you have any suggestions for another chat widget or frontend that I could use with a nodejs backend and react frontend?

Thanks a lot for your help

Hi @laujen were you able to find a solution? Can you attach relevant code/info?