How can I retrieve sender id passed to my web hook to fill the slot value

Hello All, I am trying to get the sender_id which is being passed to my webhook with the sender message. When a person initiate a conversation, I am trying to get the sender id ,which would be different for each user and setting the slot with the same value so that I can use it to retrieve the name of the sender from my database and do some personalization. Is there any way to do so? Any help would be greatly appreciated.

@yash_tanu It all depends on what information you are collecting from the user, according to GDPR policy. You can store the bot/user conversation whilst using Tracker store for any database Tracker Stores after that you need to write custom action to retrieve the sender id and user name etc for the slot filling. Can you give some example for more information. I hope my point is clear to you?

I would like to store the sender_id when a new conversation starts and retrieve his/her name from the backend and store it in the slot. Would like to do what is the first action that is being triggered when a person starts a conversation in rasa and how to store slots using the same action without returning anything.

@yash_tanu Did you tried the above mention suggestion for storing into the database the complete bot/user session? @yash_tanu I’d recommend try create on action called action_conversation. I am giving you small snippet code.

class ActionConversation(Action):

     def name(self) -> Text:
         return "action_conversation"

     def run(self, dispatcher: CollectingDispatcher,
             tracker: Tracker,
             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
             conversation=tracker.events
             print(conversation) 
             return []

check the output of this code in action logs and then you need to write the code to get the value of sender_id (id).

Can you tell me what is your frontend ?

My frontend is whatsapp

@yash_tanu ok and try above mention code to see what you getting.

I am getting below json seems like first action was ‘action_session_started’.@nik202 whats your thought in this to implement the same?

[ { “event”:“action”, “timestamp”:1629740964.4512715, “name”:“action_session_start”, “policy”:“None”, “confidence”:1.0, “action_text”:“None”, “hide_rule_turn”:false }, { “event”:“session_started”, “timestamp”:1629740964.4512715 }, { “event”:“action”, “timestamp”:1629740964.4512715, “name”:“action_listen”, “policy”:“None”, “confidence”:“None”, “action_text”:“None”, “hide_rule_turn”:false }, { “event”:“user”, “timestamp”:1629740986.5364962, “text”:“hi”, “parse_data”:{ “intent”:{ “id”:-3730224665793493547, “name”:“greet”, “confidence”:0.9999923706054681 }, “entities”:[

     ],
     "text":"hi",
     "message_id":"448fe18eb4864761962cb570a5a25720",
     "metadata":{
        
     },
     "intent_ranking":[
        {
           "id":-3730224665793493547,
           "name":"greet",
           "confidence":0.9999923706054681
        },
        {
           "id":2446355818078584727,
           "name":"action_intent",
           "confidence":3.482854253888945e-06
        },
        {
           "id":-5353641113552550327,
           "name":"bot_challenge",
           "confidence":1.5459936548722897e-06
        },
        {
           "id":26700559243797320,
           "name":"mood_great",
           "confidence":8.878944868229155e-07
        },
        {
           "id":-992762152646971941,
           "name":"goodbye",
           "confidence":7.590892323605658e-07
        },
        {
           "id":-7297362655265241018,
           "name":"deny",
           "confidence":7.166270847847045e-07
        },
        {
           "id":-3013165336768082546,
           "name":"mood_unhappy",
           "confidence":1.905183353301254e-07
        },
        {
           "id":1804258205528358946,
           "name":"affirm",
           "confidence":3.371881973635027e-08
        }
     ],
     "response_selector":{
        "all_retrieval_intents":[
           
        ],
        "default":{
           "response":{
              "id":"None",
              "responses":"None",
              "response_templates":"None",
              "confidence":0.0,
              "intent_response_key":"None",
              "utter_action":"utter_None",
              "template_name":"utter_None"
           },
           "ranking":[
              
           ]
        }
     }
  },
  "input_channel":"rasa",
  "message_id":"448fe18eb4864761962cb570a5a25720",
  "metadata":{
     
  }

}, { “event”:“user_featurization”, “timestamp”:1629740987.4107602, “use_text_for_featurization”:false }, { “event”:“action”, “timestamp”:1629740987.4107602, “name”:“utter_greet”, “policy”:“policy_0_MemoizationPolicy”, “confidence”:1.0, “action_text”:“None”, “hide_rule_turn”:false }, { “event”:“bot”, “timestamp”:1629740987.4107602, “metadata”:{ “utter_action”:“utter_greet” }, “text”:“Hey! How are you?”, “data”:{ “elements”:“None”, “quick_replies”:“None”, “buttons”:“None”, “attachment”:“None”, “image”:“None”, “custom”:“None” } }, { “event”:“action”, “timestamp”:1629740987.4225442, “name”:“action_listen”, “policy”:“policy_0_MemoizationPolicy”, “confidence”:1.0, “action_text”:“None”, “hide_rule_turn”:false }, { “event”:“user”, “timestamp”:1629741031.4448812, “text”:“run action server”, “parse_data”:{ “intent”:{ “id”:2446355818078584727, “name”:“action_intent”, “confidence”:0.99941074848175 }, “entities”:[

     ],
     "text":"run action server",
     "message_id":"005e117959f64e97851dfc09fb60e080",
     "metadata":{
        
     },
     "intent_ranking":[
        {
           "id":2446355818078584727,
           "name":"action_intent",
           "confidence":0.99941074848175
        },
        {
           "id":1804258205528358946,
           "name":"affirm",
           "confidence":0.000267144379904
        },
        {
           "id":-5353641113552550327,
           "name":"bot_challenge",
           "confidence":0.000166410856763
        },
        {
           "id":-3730224665793493547,
           "name":"greet",
           "confidence":7.484954403480515e-05
        },
        {
           "id":26700559243797320,
           "name":"mood_great",
           "confidence":3.48758912878111e-05
        },
        {
           "id":-3013165336768082546,
           "name":"mood_unhappy",
           "confidence":3.140127955703065e-05
        },
        {
           "id":-7297362655265241018,
           "name":"deny",
           "confidence":1.004710156848887e-05
        },
        {
           "id":-992762152646971941,
           "name":"goodbye",
           "confidence":4.583009285852313e-06
        }
     ],
     "response_selector":{
        "all_retrieval_intents":[
           
        ],
        "default":{
           "response":{
              "id":"None",
              "responses":"None",
              "response_templates":"None",
              "confidence":0.0,
              "intent_response_key":"None",
              "utter_action":"utter_None",
              "template_name":"utter_None"
           },
           "ranking":[
              
           ]
        }
     }
  },
  "input_channel":"rasa",
  "message_id":"005e117959f64e97851dfc09fb60e080",
  "metadata":{
     
  }

}, { “event”:“user_featurization”, “timestamp”:1629741031.4880068, “use_text_for_featurization”:false }, { “event”:“action”, “timestamp”:1629741031.4880068, “name”:“action_unlikely_intent”, “policy”:“policy_2_UnexpecTEDIntentPolicy”, “confidence”:1.0, “action_text”:“None”, “hide_rule_turn”:false } ]

@yash_tanu that’s seems nice above code is working, now you just need to write the python code to store the sender id for the slot value and can you formatted the code?

Hey @nik202 I am getting the error and slot is not being set from below code:-

class ActionSessionStart(Action):

def name(self) -> Text:

    return "action_session_start"

async def run(

  self, dispatcher, tracker: Tracker, domain: Dict[Text, Any]

) -> List[Dict[Text, Any]]:

    sender_id = tracker.sender_id

    conversation = tracker.events

    # Do something with the metadata

    print(sender_id)

    # the session should begin with a `session_started` event and an `action_listen`

    # as a user message follows

    return [SessionStarted(), ActionExecuted("action_listen"),SlotSet("sender_id",sender_id)]

Getting below error

@yash_tanu What are you trying to do with above mention code, check the data format for the same and the field name.

Whilst using this you will be able to get the sender_ id

sender_id = tracker.sender_id

Try match and see the same you getting whilst using

conversation = tracker.events # note this will return complete data, and data will be in JSON format.

I hope you getting my point.

@nik202 Is it possible to provide context about the conversation/user without them having to say it in an utterance? For example, if a user is logged in to our system, we will have sender_id already so can we pass that to rasa and fill those slots in as soon as they start the conversation? For example, if we know from the user’s sender_id that they are XYZ and their first message to Rasawould be anything?” Then Rasa should already have their sender_id slot filled and so we can give personalize message

@yash_tanu Well, we can do anything but by your last post what you looking for your use case is :

  1. Login on website with username and password [ how that linked to chatbot? ]
  2. Chatbot Widget have different interface and it’s a different entity all together [ chat widget and website have any connection?]
  3. You storing your website data and you storing the chatbot widget data also in one database?

Q1: Your website running on which server or platform?

Q2: What is your front end for your chatbot?

Q3: Which database you had decided to store and fetch the data?

Q4. What is your project end goal i.e what you making?

I hope what I suggested in last post you did it? It’s now a matter of format difference.

Basically, I already told you in my first post i.e June-16. For storing or accessing any user information you need to check GDPR Policy, else you and your company can be in big trouble.

I wanted to just store the sender_id that we are passing it on our rasa webhook with the request message attach to it and use it in my first default action triggered i.e Action_session_start to store it in a slot to use it further.I have written the code for it as above just that I am getting some event formatting error.If you can help me on this would be very helpful as I am struggling for so long on this @nik202

@yash_tanu check this demo code?

CHATBOT = "http://localhost:5005/webhooks/rest/webhook"

payload = '{"sender": "' + user + '", "message": "' + message + '"}'
r = requests.post(CHATBOT, data=payload).encode('utf-8')

response = json.loads(r.content)

@nik202 I keep getting sender_id value as ‘default’. I saw that this was a bug and github says it was fixed in version 2.1.1. However i’m using 3.1 and the problem still seems to persist. Do you know any solutions around it? Any help is appreciated

Thanks