Track user ID passed in the GET request

Rasa Core version : 0.12.3 Python version : 3.6.7 Operating system (windows, osx, …): Ubuntu 18.04

Issue :

Hi guys! So I have created a bot for my web app and uploaded it on AWS so that my web app can send a GET request and get the response from the rasa_core. But for a specific user i need to pass an id in the GET request. like :

http://my_ip_.amazonaws.com:5005/conversations/27/respond?q='who is online today?’

So i want to track this 27 in my action file so that i can make an api call using this id as a parameter.

OR IF you can suggest a way that I can get the user_id in the start of conversation when my user opens the bot widget. I tried to set as user_id = tracker.get_slot(‘recipient_id’) but this doesn’t work! Any help is appreciated. I’m stuck on this issue for 2 days!

#1 See my GET request:

http://my_amazon_ip:5005/conversations/ 27 /respond?q=hello

so 27 here is a unique user_id that i want to fetch.

#2 My response

[{“recipient_id”:“27”,“text”:“Hey! What can I do for you?”}]

so now I want to track that id 27 and use it inside a custom function for calling the APIs. Please respond and help :frowning: @akelad @JustinaPetr

[I know this method of calling for response is depracated but I don’t know how to setup REST api so i’m using the older version only!

1 Like

that’s a duplicate of Tracking User_id from GET request

To create the rest channel start core with

 python -m rasa_core.run -d models/dialogue -u models/nlu/current --credentials credentials.yml

The important part hereby is --credentials credentials.yml. credentials.yml should have this content for REST

rest:
  # no config needed

You can the send message to the REST channel by doing a POST request to /webhooks/rest/webhook with the content (e.g. localhost:5005/webhooks/rest/webhook)

{
  "sender": "<your-sender-id>",
  "message": "<your message>"
}
1 Like

Yet another method using custom action would be saving sender_id in a slot.

sender_id=( tracker.current_state())[“sender_id”]

1 Like

hey@ ashukrishna 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_id",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

Looks version issue. Switch to 0.11 or higher

Hey @ashukrishna100 Thanks for answering. I solved the issue by

user_id=tracker.sender_id

apparantly I wasn’t creating parameters the right way which was giving the error.

Happy new year !!

hi @Akshit I encountered a similar issue as you, but my version is 0.11.12 As the doc HTTP API GET, the link is http://localhost:5005/conversations/default/tracker

Now I want to get the log of each user’s data, I guess I need to replace default to user_id ?

I tried your method, but the bot just stopped reply and crashed.

Part of my action code:

def submit(self, dispatcher, tracker, domain):
        
        agree_info = AgreeInfo()
        booking = agree_info.save(tracker.latest_message.get("text"))
        user_id = tracker.sender_id
        print (user_id)
        r = requests.get('http://localhost:5005/conversations/' + user_id + '/tracker')
        indexFile_senderid = open(str(tracker.latest_message.get("text")) + '.txt', 'w+', encoding='utf-8')
        indexFile_senderid.write('student ID: ' + tracker.latest_message.get("text") + str('\n\n') + str(r.content) + str('\n\n'))
        
        indexFile_senderid.close()
        return[]
1 Like

You are getting the user_id as default from the print(user_id) command right? Try printing the tracker info and comment the next lines. Make sure you are getting the data from tracker.

Yes, the action commandline shows:

DEBUG:rasa_core_sdk.executor:Received request to run 'action_agree'

DEBUG:actions:-------slot_agree---------

DEBUG:actions:123456789

DEBUG:actions:-------slot_agree---------

c06c5089-5b3e-4ceb-a114-fe4536188b27

also what kind of tracker infor I need to print?

hey I didn’t find any content key in tracker data…are you sure r.content is working?

indexFile_senderid.write(‘student ID: ’ + tracker.latest_message.get(“text”) + str(’\n\n’) + str(r.content) + str(’\n\n’))

Need to use python requests package: import requests

It’s working when in command line by using:

>>python
>>import requests
>>r = requests.get('http://localhost:5005/conversations/default/tracker')
>>r.text or r.content (both work)

So I guess now the problem is to replace default as user_id since there will be lots of user on my server??

Oh I thought you would have done that already! :slight_smile: That’s why I was telling you to check if a response is coming or not. Do you use postman? You can run the api call and get the tracker data. It’s good for a clearer answer!

I do not use postman, should I use postman to debug? or something wrong in my code?

Yes I’m doing something similar! We have 10 client right now who has access to our demo bot and we are saving the tracker details and storing all in our db!

I don’t see anything wrong! Maybe someone with coding background can help you! POSTMAN Is just for using api calls and getting the response. it’s helpful if you want to see the tracker data in a more clearer way! check this out

I use the action server to get the user_id as b6e2dc06-00fb-4b4f-a888-9ecb0121f38a Then I replaced default to the user_id http://localhost:5005/conversations/b6e2dc06-00fb-4b4f-a888-9ecb0121f38a/tracker

But the postman shows

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>

Did you change the request to GET?

Yes

Did you manually add this id or is it autogenerated? Try creating a new user_id and then try the tracker!