目前我正在使用firebase云消息处理推送通知。令牌click_action仍然受支持,但我仍然收到这个错误。我的代码是,
cmd(Firebase CLI(上的错误为,
notification: {
title: "Notification from" + from_name,
body: from_message,
sound: "default"
click_action: "com.example.tysf_trial"
}
部署时遇到此错误,
43:5 error Parsing error: Unexpected token click_action
? 1 problem (1 error, 0 warnings)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:UsersabcAppDataRoamingnpm-cache_logs2019-11-05T19_43_05_08
1Z-debug.log
events.js:187
throw er; // Unhandled 'error' event
^
Error: spawn npm --prefix "%RESOURCE_DIR%" run lint ENOENT
at notFoundError (C:UsersabcAppDataRoamingnpmnode_modules←[4mfirebase
-tools←[24mnode_modules←[4mcross-env←[24mnode_modules←[4mcross-spawn←[24mli
benoent.js:6:26)
at verifyENOENT (C:UsersabcAppDataRoamingnpmnode_modules←[4mfirebase-
tools←[24mnode_modules←[4mcross-env←[24mnode_modules←[4mcross-spawn←[24mlib
enoent.js:40:16)
at ChildProcess.cp.emit (C:UsersabcAppDataRoamingnpmnode_modules←[4mf
irebase-tools←[24mnode_modules←[4mcross-env←[24mnode_modules←[4mcross-spawn←
[24mlibenoent.js:27:25)
←[90m at Process.ChildProcess._handle.onexit (internal/child_process.js:272:1
2)←[39m
Emitted 'error' event on ChildProcess instance at:
at ChildProcess.cp.emit (C:UsersabcAppDataRoamingnpmnode_modules←[4mf
irebase-tools←[24mnode_modules←[4mcross-env←[24mnode_modules←[4mcross-spawn←
[24mlibenoent.js:30:37)
←[90m at Process.ChildProcess._handle.onexit (internal/child_process.js:272:1
2)←[39m {
code: ←[32m'ENOENT'←[39m,
errno: ←[32m'ENOENT'←[39m,
syscall: ←[32m'spawn npm --prefix "%RESOURCE_DIR%" run lint'←[39m,
path: ←[32m'npm --prefix "%RESOURCE_DIR%" run lint'←[39m,
spawnargs: []
}
这是我的钻孔工作代码,它昨天和我一起工作…^_^
'use-strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotification = functions.firestore.document
("NotifyUsers/{user_id}/Notification/{notification_id}")
.onWrite((change, context) => {
const user_id = context.params.user_id;
const notification_id = context.params.notification_id;
return admin.firestore().collection("NotifyUsers")
.doc(user_id).collection("Notification").doc(notification_id)
.get().then(queryResult => {
const {from:from_user_id, message:from_message} = queryResult.data();
const from_data = admin.firestore().collection("NotifyUsers")
.doc(from_user_id).get();
const to_data = admin.firestore().collection("NotifyUsers")
.doc(user_id).get();
return Promise.all([from_data, to_data, from_message , from_user_id]);
// added from_message so it's available in the next .then
})
.then(([from_data, to_data, from_message, from_user_id]) => { // added from_message
const from_name = from_data.data().name;
const {name:to_name, token_id} = to_data.data();
console.log("From: " + from_name + " | To : " + to_name +"from:" +from_user_id);
const payload = {
"notification" : {
"title" : "Notification From : " + from_name,
"body" : from_message,
"icon" : 'default',
"click_action": 'return.to.NotificationActivity'
},
"data": {
"from_user_id" : from_user_id,
"message" : from_message
}
};
return admin.messaging().sendToDevice(token_id, payload);
})
.then(result => {
return console.log("Notification Sent");
});
});
sound:
行后面缺少一个逗号:
notification: {
title: "Notification from" + from_name,
body: from_message,
sound: "default", // here
click_action: "com.example.tysf_trial"
}