0

We are trying to read a document file from Firestore through Dialogflow. We get as far as "I can't find your reservation." Each document's id is auto generated, so we can't match from the Document ID field (or at least do not know how to). Any help would be greatly appreciated!

Fulfillment function code:

function readReservation(agent) {

    let id = agent.parameters.name.toString();
    let collectionRef = db.collection('reservations');
    let userDoc = collectionRef.doc(id);
          
    return userDoc.get()
        .then(doc => {
            if (!doc.exists) {
                                agent.add('I could not find your reservation.');
            } else {
                db.collection('reservations').doc(id).update({
                    newname: agent.parameters.newname
                }).catch(error => {
                    console.log('Transaction failure:', error);
                    return Promise.reject();
                });
                agent.add('Ok. I have updated the name on the reservation.');
            }
            return Promise.resolve();
        }).catch(() => {
            agent.add('Error reading entry from the Firestore database.');
        });
}

I have tried different ways to write this code, but was unsuccessful.

L A
  • 1
  • I figured it out. Now I have to figure out how to match the Firestore db doc id to a field. – L A Nov 14 '22 at 19:16

0 Answers0