1

Hi I have created a fb chatbot using dialogflow which saves specific user inputs to firebase . Is there a way to also store the fb id of the user in firebase . heres what I've got so far.

  function getNameHandler(agent) {
    let code = agent.parameters.code ;
   // let user_id = agent["outputContexts"][0]["parameters"]["facebook_sender_id"];

    db.collection("codes").add({ code: code});

    agent.add(`Please wait for the response for code : ${code}`);
  }

Thank you

Sairaj Sawant
  • 1,842
  • 1
  • 12
  • 16
user6537067
  • 357
  • 2
  • 6
  • 16

1 Answers1

1

To get the messenger_id you have to used this code:

let user_id = agent.originalRequest.payload.data.sender.id;

function handler(agent){
    
      let user_id = agent.originalRequest.payload.data.sender.id;
    
      return admin.database().ref('/spo').push({user_id :user_id}).then((snapshot) => {
     
      agent.add(`Thank you. `);
    });
     
    
   }
  
user6537067
  • 357
  • 2
  • 6
  • 16