一旦在我的收藏集"我的英雄学院"中创建了文档,我将尝试向特定设备发送通知。当我尝试部署该功能时,我会得到以下错误-
Error: Error occurred while parsing your function triggers.
ReferenceError: chapter is not defined
代码:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
var msgData;
var token = "####";
exports.offerTrigger = functions.firestore.document(
'My Hero Academia'/{chapter}
).onCreate((snapshot,context) => {
msgData = snapshot.data();
var payload = {
"notifications": {
"title": "A new chapter has been released",
"body": "Read chapter " + msgData.number + " now!",
"sound": "default"
}
}
return admin.messaging().sendToDevice(token,payload).then((response) => {
console.log('Pushed notification');
}).catch((error) => {
console.log(error);
})
})
很明显,我把我的代币藏起来了。正如错误所说,章节没有定义。但是,{章}不是用来指代将要创建的新文档吗?
编辑:
{"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":13,"message":"INTERNAL"},"authenticationInfo":{"principalEmail":"user2312@gmail.com"},"requestMetadata":{"requestAttributes":{},"destinationAttributes":{}},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction","resourceName":"projects/dmscraper-c91da/locations/us-central1/functions/offerTrigger"}
更改此项:
functions.firestore.document(
'My Hero Academia'/{chapter}
).onCreate((snapshot,context) => {
进入这个:
functions.firestore.document('My Hero Academia/{chapter}')
.onCreate((snapshot,context) => {
你应该有'
也超过{chapter}
:
https://firebase.google.com/docs/firestore/extend-with-functions#wildcards-参数