When the user files a request a firestore document is being created with its respective data. This creation of a document triggers a firebase function which then sends an email to a specific address. It works fine, but how can I get the promise from the function to return a success/error alert (clientside), when this email has been send/not send.
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
exports.request = functions.firestore.document('requests/{requestId}').onCreate(async (snapshot, context) => {
const itemDataSnap = await snapshot.ref.get();
const name = itemDataSnap?.data()?.name ? itemDataSnap?.data()?.name : 'Unbekannt';
const email = itemDataSnap?.data()?.email;
const products = itemDataSnap?.data()?.products ? itemDataSnap?.data()?.products : 'Fehler: Keine Produkte vorhanden';
return admin.firestore().collection('mail').add({
to: [...],
from: [email],
message: {
subject: ...,
html: ...
}
}).then(() => console.log('Queued email for delivery!'))
});
As you can see, so far I'm logging 'Queued email for delivery!' as a success message for the firebase console - but how can I bring this to the client's side (to the user)?