How to send additional data from Web Page mrbot to actions.py

I have this in my web page and everything is working great for all of the normal actions and intents, but I want to send the IP address back to actions.py from the Web page. Can I do that in customData like below? The variable ip has the user’s IP address. If so, how to I get the ipaddress data in actions.py.

WebChat.default.init({ selector: “#webchat”, initPayload: “/get_started”, customData: {“language”: “en”, “ipaddress”: ip}, // arbitrary custom data. Stay minimal as this will be added to the socket socketUrl: “https://chat.myexample.com”, socketPath: “/socket.io/”, title: “My Title”, subtitle: “My Subtitle”, })

Hi,

Obviously you can transfer whatever data you want, the only change is that you need to make the channel a custom channel,

In the channel you can add something like this (in the Input class that is written as something like: class YourNameSocketIOInput(InputChannel): )

add whatever data you want to the json, parse it and transfer it to the metadata field:

        if "customData" in data and isinstance(data["customData"], dict):
            user_token = data["customData"]
        else:
            user_token = None

        message = UserMessage(
            data["message"], output_channel, sender_id, input_channel=self.name(), metadata=user_token
        )

then to access the metadata:

def get_meta_data(tracker: Tracker):
    try:
        events = tracker.current_state()['events']
        user_events = []
        for e in events:
            if e['event'] == 'user':
                user_events.append(e)
        meta = user_events[-1]['metadata']
        return meta
    except:
        return None

Thanks I was able to follow the steps here and it works:

https://github.com/JiteshGaikwad/socketChannel_RasaBot

@billwparker, Can you please send me your files…