How to get current user UID from Firebase into Dialogflow webhook

Viewed 67

I have a Flutter project where I used to create a chatbot using Dialogflow. User will need to log in first. So this is the code to get the current user uid in Flutter:

getUid() async {
    FirebaseAuth auth = FirebaseAuth.instance;
    User? user;
    user = await auth.currentUser;
    setState(() {
      uid = user!.uid;
    });
  }

To conect Flutter with Dialogflow, I used a package name dialogflow_grpc and here is example of the detect intent from text input request

DetectIntentResponse data = await dialogflow.detectIntent(text, 'ms-MY');
    String fulfillmentText = data.queryResult.fulfillmentText;

And for the webhook, I use Node.js. In here, I already wrote the user uid. So, I want it to use the current user uid based on the current user logged in. May I know how to do this?

const ref = await db.collection('name').doc(uid)
            .set({
                name: name
            });
1 Answers

try this :

getUid() async {
 FirebaseAuth auth = FirebaseAuth.instance;
 User? user;
 user = await auth.currentUser;
 return user!.uid;
}

and after that add this :

getUid.then((uid) async {
    const ref = await db.collection('name').doc(uid)
        .set({
            name: name
        });
 });
Related