How to get user access_token in actions

Hi @yprashant!

Sorry for the late reply. :sweat_smile:

You can customize the socketio channel. You can then catch the token and then pass it as metadata to rasa by editing this line like this:

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

This will be now added to the tracker and you can extract it from the tracker in your actions with something like this:

def get_access_token(tracker: Tracker):
	for event in reversed(tracker.events_after_latest_restart()):
		if event.get('event') == 'user' and 'metadata' in event:
                access_token = event.get('metadata')
                return access_token

Hope that helps. :slightly_smiling_face:

1 Like