I am using rasa-webchat for UI
import Widget from 'rasa-webchat';
import avatarImage from './chatbot.png';
export function CustomWidget() {
return (
<Widget
initPayload={"/utter_greet"}
socketUrl={"http://localhost:5005"}
socketPath={"/socket.io/"}
customData={{"language": "en", "studentId": "123"}} // arbitrary custom data. Stay minimal as this will be added to the socket
title={"Chatbot-beta"}
// subtitle={"powered by DigiTechnologyNepal"}
storage={"session"}
profileAvatar={avatarImage}
fullScreenMode={true}
/>
)
}
I want to access the information in customData from rasa. This is my credential.yaml file
socketio:
user_message_evt: user_uttered
bot_message_evt: bot_uttered
session_persistence: true
metadata_key: customData
I was trying to access the data of custonData in action.py
class CustomAction(Action):
def name(self) -> Text:
return "action_get_custom_data"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
metadata = tracker.latest_message.get("metadata")
# retrieve customData from metadata
custom_data = metadata.get("customData", {})
# Access the customData
print(custom_data)
custom_data = tracker.latest_message.get("metadata", {}).get("customData")
print(custom_data)
# Use the customData as needed
if custom_data:
# Use the customData as needed
student_id = custom_data.get("studentId")
language = custom_data.get("language")
dispatcher.utter_message("Received customData: student_id={}, language={}".format(student_id, language))
else:
dispatcher.utter_message("No customData received")
return []
but i am unable to access the customData
version
Rasa Version : 3.4.2
Minimum Compatible Version: 3.0.0
Rasa SDK Version : 3.4.0
Python Version : 3.10.6