【发布时间】:2020-09-30 05:29:17
【问题描述】:
我要创建的是一个简单地向主题发送通知的函数
所以我所做的一切只是发送一个频道名称,而我所拥有的就是这个
exports.sendNotification = functions.https.onRequest((req, res) => {
const dest = req.query.dest;
console.log(dest);
console.log('Message received');
const payLoad = {
notification:{
title: "Message title",
body: "You have a new message"
}
};
console.log("*** about to send message ");
admin.messaging().sendToTopic(dest, payLoad).then((response) => {
console.log("Successfully sent message ", response);
return res.send(JSON.stringify({"success":"true"}));
})
.catch((error) => {
console.log("Error sending message: ", error);
return res.send(JSON.stringify({"success":"false"}));
})
});
从我拥有的功能日志中:
11:12:47.622 下午 发送通知 函数执行开始
11:12:47.704 下午 发送通知 9Td4I6aWOoVvNXWNE0pZYjwbXNv1
晚上 11:12:47.705 sendNotification 收到消息
晚上 11:12:47.720 发送通知 函数执行耗时 98 毫秒,完成状态为:'crash'
好像创建payLoad的时候崩溃了,但是我不知道为什么
谢谢
【问题讨论】:
-
您能否显示您的
index.js文件的全部内容,包括require语句?
标签: javascript node.js firebase google-cloud-functions