Best practice to pass metadata through the socketio channel

Hello, I use the channel provided by Rasa and now I want to pass metadata “through” Rasa, i.e. the incoming event has dynamic metadata that should be added to the outgoing event too. What is the least intrusive way doing this?

I figured that I can simply write a custom input channel and add the metadata like so:

message = UserMessage(

For the Output channel, though, I have no idea. Any thoughts?

Hi @ScienceGuy, did you have any luck solving this? I am trying to do a similar thing.

Hi, yes it turned out to be quite simple. In the custom INPUT channel, you can define the output channel to use. Here is what I did to add “metadata”.

@sio.on(self.user_message_evt, namespace=self.namespace)
        async def handle_message(sid: Text, data: Dict) -> None:
            # Changed Output channel to custom channel.
            output_channel = CustomSocketIOOutput(sio, self.bot_message_evt, data["metadata"])

Here is my custom output chanel:

class CustomSocketIOOutput(SocketIOOutput):

    def __init__(self, sio: AsyncServer, bot_message_evt: Text, metadata: Any) -> None:
        self.sio = sio
        self.bot_message_evt = bot_message_evt
        self.metadata = metadata

    async def _send_message(self, socket_id: Text, response: Any) -> None:
            Sends a message to the recipient using the bot event.
        response['metadata'] = self.metadata

        await self.sio.emit(self.bot_message_evt, response, room=socket_id)

Since the input channel seems to define its target output channel, they can share information this way.