@Serge @ghost Heya, I was having the same issue, so I looked a bit into the source code (Rasa 1.1.3).
Well, Iâm actually directly calling the dispatcher.utter_custom_json
method from custom actions, but I could confirm it was the same issue by adding logs on the method eventually called on the socketio channel, send_custom_json()
. That method is itself calling sio.emit(self.bot_message_evt, **json_message)
.
As you can see, that method is unpacking the json message before emitting through socketio (**json_message
), so in your case it would be something like calling sio.emit(self.bot_message_evt, title="click here to see[...]", video="https://[...]", room=self.sid)
(the room arg is added in the json message by the send_custom_json method).
Now, from what I understood, if you look at that emit method, youâll notice that whatâs actually sent to the client is in the data
parameter. Your title
and video
args though, are included in the extra kwargs and sent to the asyncio_manager.AsyncManager()
manager, which does⌠nothing with them, since itâs not expecting any title
or video
arg. Meanwhile, as the data
arg is actually empty, whatâs sent is a null message to the client, resulting in an error on rasa-webchat (since itâs trying to convert a null to an object to check its length, according to what I see from their source code).
Fortunately, itâs pretty easy to solve that issue. From what I see, youâd have two options:
-
Make a custom SocketIo channel to override the
send_custom_json
method so that it doesnât unpack. For it to work, you could look at how other methods are implemented, but you could do something as simple as this:
async def send_custom_json(
self, recipient_id: Text, json_message: Dict[Text, Any], **kwargs: Any
) -> None:
"""Sends custom json to the output"""
await self.sio.emit(self.bot_message_evt, json_message, room=self.sid)
// Or use await self._send_message(self.sid, json_message) instead, same thing
-
Pack your custom message in a
data
block. When calling send_custom_json
, it will make it so it ends up calling sio.emit(self.bot_message_evt, data={title="click here to see[...]", video="https://[...]"}, room=self.sid)
, which will then send that json to the front-end.
- For those using custom actions. you would do something like this:
message = {}
message["data"] = {"my_custom_element": "var1", "my_other_custom_element": "Hello world"}
dispatcher.utter_custom_json(message)
- For those using the domain file, like what I can see youâre doing, it would be something like this:
utter_csmb_hardware_grid
- custom:
data:
title: "click here to see the page with the info table, and here is the video: https://myinernalurl.com/index.html"
video: "https://my.url.com/video"
Both should be working from what I tried. I could check that the message was actually sent:
2019-07-29 12:20:18 INFO engineio.server - c1b8c2bf0b7d4396b23f68778762abf4: Sending packet MESSAGE data 2["bot_uttered",{"title":"click here to see the page with the info table, and here is the video: https://myinernalurl.com/index.html","video":"https://my.url.com/video"}]
On the Firefox Console, I also checked that it was received by adding some logging:
But then again, as @erohmensing, for it to do anything, it would need to be data formatted in a format expected by the front-end, which doesnât look like to be the case for rasa-webchat (for videos, another format is expected). So while it has been received, nothing is displayed.
Hope it helps.