Fom*_*are 0 firebase google-cloud-functions
当我在Firebase数据库中创建新订单时,我想发送电子邮件,但是创建订单时没有任何反应。我的功能:
exports.sendEmailConfirmation = functions.database.ref('/orders').onCreate(event => {
const mailOptions = {
from: '"Someone." <noreply@firebase.com>',
to: 'someone@gmail.com',
};
// Building Email message.
mailOptions.subject = 'New order from mobile app!';
mailOptions.text = 'John Doe lorem ipsum';
return mailTransport.sendMail(mailOptions)
.then(() => console.log('¡¡¡ Enail sent !!!'))
.catch((error) => console.error('Error!!', error));
});
Run Code Online (Sandbox Code Playgroud)
此代码使用onWrite()工作。
您的函数没有触发,因为它/orders
已经存在。仅当您指定的路径是新创建的时,onCreate触发器才会运行。
如果您想知道何时在下方新添加了一个孩子/orders
,则应在路径中使用通配符:
functions.database.ref('/orders/{orderId}')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
841 次 |
最近记录: |