【发布时间】:2020-07-17 14:25:58
【问题描述】:
当用户提出请求时,将使用其各自的数据创建一个firestore 文档。文档的创建会触发firebase function,然后将电子邮件发送到特定地址。它工作正常,但是当此电子邮件已发送/未发送时,我如何从函数中获得返回成功/错误警报(客户端)的承诺。
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!'))
});
如您所见,到目前为止,我正在记录 'Queued email for delivery!' 作为 Firebase 控制台的成功消息 - 但我如何才能将其带到客户端(给用户)?
【问题讨论】:
标签: angular typescript firebase google-cloud-firestore google-cloud-functions