Get sender_id for facebook bot

Hello everyone, I’m creating a facebook bot with rasa stack. For the moment everything works perfectly and I have no problems. I would like to retrieve the name and surname through the sender_id. I already know that in this case the sender_id is equivalent to the messenger_id and only that I do not know how to recover the sender_id. Can you help me?

1 Like

In custom action you can get sender_id via tracker.current_state()[‘sender_id’]

Can you please provide the code for sender id. How do I call it. And if I want it to set in database, how do we do that? Do i need to take a slot?

SenderId is nothing but unique identifier for user from rasa perspective, in case of facebook facebookid is treated as sender_id, not too sure regarding other channel, if you are using rest channel you need to provide the sender_id. If you have configured tracker_store all conversation will be stored there one of the column is sender id in that table. If you want to control the sender_id rest and callback channel are your option.

1 Like

tracker.current_state()[“sender_id”], I have seen this in forum for getting sender id. I want it on telegram. I am bit confused how to provide that on action file. And how to store it in my db. I have used tracker store, where it has a sender id, but I want to get that column in my other table. And Is it it possible to get username from the bot?

1 Like

If you want to store it in your own DB you have two option

  1. telegram channel: If you are using the channel provided by rasa then to communicate with your own database custom action is your only option, I would suggest overriding action_session_start, here you can save the sender id to your own database and do other things.
  2. Use the rest channel to communicate with rasa, in this case, you can use a middle layer for communicating with rasa over rest, since it’s your middle layer responsible for communicating with rasa you will be responsible for providing the sender_id.

Not sure about your other question regarding username, rasa does not have any such info, based on your sender_id from rasa (which would mean different thing for different channel) you can query your channel provider (telegram) and get the user info, again you will have to use the custom action for this.

1 Like

I was able to store all my other conversation to my database, I need to get the sender id too. i am confused about how to code it. tracker.current_state()[“sender_id”] how to put it in full code on file

Not sure what’s the issue :thinking: If you have sender id in using sender_id = tracker.current_state()[“sender_id”]

then u can store sender_id to database either directly or otherwise, we are sending sender_id through our rest API in


some_url = os.getenv(‘API_URL’)

sender_id = tracker.current_state()[‘sender_id’]

import requests

r = requests.get(url=some_url , params= {“id”:str(sender_id )})

1 Like

Thank you so so so much. i was able to get it