Tracking parameters(user_id)

Hi guys so i’m calling this POST request and this result.

POST request:

http://my–ip–:5005/conversations/27/tracker

Result:

{
	"active_form": {},
	"events": [{
		"confidence": null,
		"event": "action",
		"name": "action_listen",
		"policy": null,
		"timestamp": 1545028444.7635999
	}, {
		"event": "user",
		"input_channel": null,
		"parse_data": {
			"entities": [],
			"intent": {
				"confidence": 0.9589663743972778,
				"name": "greet"
			},
			"intent_ranking": [{
				"confidence": 0.9589663743972778,
				"name": "greet"
			}, {
				"confidence": 0.09613768756389618,
				"name": "deny"
			}, {
				"confidence": 0.08476360887289047,
				"name": "ask_bot_identity"
			}, {
				"confidence": 0.07856026291847229,
				"name": "greet+ask_bot_mood"
			}, {
				"confidence": 0.03787624090909958,
				"name": "thanks"
			}, {
				"confidence": 0.03389263153076172,
				"name": "mood_happy"
			}, {
				"confidence": 0.020171500742435455,
				"name": "greet+inform"
			}, {
				"confidence": 0.01849551498889923,
				"name": "ask_bot"
			}, {
				"confidence": 0.0,
				"name": "out_of_scope"
			}, {
				"confidence": 0.0,
				"name": "affirm+inform"
			}],
			"text": "hi"
		},
		"text": "hi",
		"timestamp": 1545028444.798955
	}, {
		"confidence": 1.0,
		"event": "action",
		"name": "utter_greet",
		"policy": "policy_2_MemoizationPolicy",
		"timestamp": 1545028444.9126012
	}, {
		"data": {
			"attachment": null,
			"buttons": null,
			"elements": null
		},
		"event": "bot",
		"text": "Hey! What can I do for you?",
		"timestamp": 1545028444.9126122
	}, {
		"confidence": 0.5627988213332434,
		"event": "action",
		"name": "action_listen",
		"policy": "policy_0_KerasPolicy",
		"timestamp": 1545028444.9144976
	}, {
		"event": "user",
		"input_channel": null,
		"parse_data": {
			"entities": [],
			"intent": {
				"confidence": 0.8902426362037659,
				"name": "ask_bot"
			},
			"intent_ranking": [{
				"confidence": 0.8902426362037659,
				"name": "ask_bot"
			}, {
				"confidence": 0.2874608337879181,
				"name": "out_of_scope"
			}, {
				"confidence": 0.17254899442195892,
				"name": "inform_lead"
			}, {
				"confidence": 0.1596004217863083,
				"name": "greet"
			}, {
				"confidence": 0.1230294480919838,
				"name": "greet+inform"
			}, {
				"confidence": 0.03998316079378128,
				"name": "greet+ask_bot_mood"
			}, {
				"confidence": 0.031222742050886154,
				"name": "affirm+inform"
			}, {
				"confidence": 0.008451215922832489,
				"name": "mood_happy"
			}, {
				"confidence": 0.0,
				"name": "inform_p"
			}, {
				"confidence": 0.0,
				"name": "ask_bot_identity"
			}],
			"text": "what can you do for me?"
		},
		"text": "what can you do for me?",
		"timestamp": 1545028462.9284985
	}, {
		"confidence": 1.0,
		"event": "action",
		"name": "utter_what_bot",
		"policy": "policy_2_MemoizationPolicy",
		"timestamp": 1545028462.930819
	}, {
		"data": {
			"attachment": null,
			"buttons": null,
			"elements": null
		},
		"event": "bot",
		"text": "Dot can help you with questions regarding users attendance and lead created.",
		"timestamp": 1545028462.9308283
	}, {
		"confidence": 1.0,
		"event": "action",
		"name": "action_listen",
		"policy": "policy_2_MemoizationPolicy",
		"timestamp": 1545028462.9327078
	}, {
		"event": "user",
		"input_channel": null,
		"parse_data": {
			"entities": [],
			"intent": {
				"confidence": 0.9600496888160706,
				"name": "goodbye"
			},
			"intent_ranking": [{
				"confidence": 0.9600496888160706,
				"name": "goodbye"
			}, {
				"confidence": 0.15173789858818054,
				"name": "ask_bot_mood"
			}, {
				"confidence": 0.04803198575973511,
				"name": "greet+inform"
			}, {
				"confidence": 0.04480105638504028,
				"name": "out_of_scope"
			}, {
				"confidence": 0.03656768798828125,
				"name": "greet+ask_bot_mood"
			}, {
				"confidence": 0.029518842697143555,
				"name": "thanks"
			}, {
				"confidence": 0.02339249849319458,
				"name": "ask_bot_identity"
			}, {
				"confidence": 0.02167341858148575,
				"name": "affirm"
			}, {
				"confidence": 0.0,
				"name": "deny"
			}, {
				"confidence": 0.0,
				"name": "inform_p"
			}],
			"text": "bye"
		},
		"text": "bye",
		"timestamp": 1545029260.9358497
	}, {
		"confidence": 0.9999990710290291,
		"event": "action",
		"name": "utter_goodbye",
		"policy": "policy_0_KerasPolicy",
		"timestamp": 1545029260.938287
	}, {
		"data": {
			"attachment": null,
			"buttons": null,
			"elements": null
		},
		"event": "bot",
		"text": "Talk to you later!",
		"timestamp": 1545029260.938296
	}, {
		"confidence": 0.9999807788641267,
		"event": "action",
		"name": "action_listen",
		"policy": "policy_0_KerasPolicy",
		"timestamp": 1545029260.9402716
	}],
	"followup_action": null,
	"latest_action_name": "action_listen",
	"latest_event_time": 1545029260.9402716,
	"latest_input_channel": null,
	"latest_message": {
		"entities": [],
		"intent": {
			"confidence": 0.9600496888160706,
			"name": "goodbye"
		},
		"intent_ranking": [{
			"confidence": 0.9600496888160706,
			"name": "goodbye"
		}, {
			"confidence": 0.15173789858818054,
			"name": "ask_bot_mood"
		}, {
			"confidence": 0.04803198575973511,
			"name": "greet+inform"
		}, {
			"confidence": 0.04480105638504028,
			"name": "out_of_scope"
		}, {
			"confidence": 0.03656768798828125,
			"name": "greet+ask_bot_mood"
		}, {
			"confidence": 0.029518842697143555,
			"name": "thanks"
		}, {
			"confidence": 0.02339249849319458,
			"name": "ask_bot_identity"
		}, {
			"confidence": 0.02167341858148575,
			"name": "affirm"
		}, {
			"confidence": 0.0,
			"name": "deny"
		}, {
			"confidence": 0.0,
			"name": "inform_p"
		}],
		"text": "bye"
	},
	"paused": false,
	** "sender_id": "27" ** ,
	"slots": {
		"name": null,
		"offline": null,
		"online": null,
		"team": null,
		"timeline": null
	}
}

so check out this sender_id :27 i want to store this as a parameter in a custom action…How should i do that ? AS i’m passing this from my web side and I want this id to be in my rasa core action file.

Hi @Akshit, you can use rasa_core_sdk to run a custom action server. You can parse the content of your POST in your custom action in whatever way you like, and modify the dialogue in response.

It sounds like you want to access the tracker’s sender_id property, which you can do in your custom action’s run() method:

 def run(self, dispatcher, tracker, domain):
    sender_id = tracker.sender_id
    (do something with the sender_id ...)

Please check out the docs on Actions

1 Like

hey It’s not working for me! I ran the REST server then in my custom action I added this.

class ActionOnline(Action): def name(self): return ‘action_online’

def run(self, dispatcher, tracker, domain):
    online = tracker.get_slot('online')
    #tracker for user_id
    user_id = (tracker.current_state())["sender_id"]
    dispatcher.utter_message(user_id)
    parameters = {}

    for i in ('user_id'):
        parameters[i] = locals()[i]
    
    data = requests.post("my_api_url",params= parameters)
    response = data.json()
    onlineuser= response["onlineUserList"][0]["user_name"]#change
    answer = """These users are currently online {} .""".format(onlineuser)
    dispatcher.utter_message(answer)
    return [SlotSet('online',online)]

I tried to dispatch the user_id by utter_message but I’m getting Keyerror bcoz user_id is empty in loop. So user_id is not allocating. can you check this action

1 Like

Hi @Akshit, can you post a full stacktrace of the error? I don’t fully understand what you’re trying to achieve, but you should only expect one sender_id per tracker, so looping over many sender_ids will not be possible like that

The for loop is just for creating a dictionary/json format of some parameters which i need to pass to the API call. I need to pass the parameters in dictionary format only.

Is there any other way I can do that? The error is like json format not serializable. so it’s tracking the ID but for loop thing is not working.

1 Like

I don’t follow - your loop is over characters in the literal string 'user_id'.

Can you please share the full stacktrace so we can help you identify the problem? Your json serialisation error makes it sound like your API call does not return a valid json response.

2 Likes

Hey @ricwo Thanks for your help man!! I solved the issue by this method.

    user_id = tracker.sender_id
    parameters = {}
    parameters = {'user_id': user_id}
    data = requests.post("https:/my_api_url",params= parameters)
    response = data.json()

Appreciate your help man! Happy holidays! :slight_smile: :slight_smile:

1 Like

@ricwo @Akshit This Thread help me to solve a big puzzle. Good HEalth to both of you. God Bless. Thank you so much.