cam*_*e92 3 push-notification node.js firebase firebase-cloud-messaging
我正在尝试使用针对node.js的firebase管理SDK(版本7.0.0)来使FCM Web通知包含指向我的网站的可点击链接。据我所知,我正在将文档跟在T后面,但无法使链接正常工作。要澄清的是,我的通知可以正常工作,否则,这只是我没有工作的链接。
该文档指出:
对于从应用服务器发送的通知消息,FCM JavaScript API支持fcm_options.link键。通常,此设置设置为您的Web应用程序中的页面
我已将其包含webpush.fcm_options.link在通知消息中。我已确保notification在消息中包含显式负载,因为文档指出data消息不支持fcm_options.link。
这是我当前的消息结构:
{
notification: {
title: 'Title',
body: 'Body',
},
data: {
// my data here
},
webpush: {
notification: {
requireInteraction: true,
icon: '/icons/notification.png'
},
fcm_options: {
link: 'https://example.com/'
}
},
// android: {},
// apns: {},
topic: 'sometopic'
};
Run Code Online (Sandbox Code Playgroud)
这是我用来发送消息的功能:
const admin = require('firebase-admin')
const sendMessage = message => {
admin
.messaging()
.send(message)
.then(response => {
console.log(response)
})
.catch(error => {
console.log(error)
});
};
Run Code Online (Sandbox Code Playgroud)
该link属性应根据文档正常工作:我的url包括https并且我的通知是从应用服务器发送的,并且包括一个明确的通知有效负载。此刻,单击通知只会使其消失,而没有其他任何事情。
在通知中试试这个
"notification":{
"title":"IssA",
"body":"Lafi",
"icon": "Icon URL",
"click_action": "Your URL here"
}
Run Code Online (Sandbox Code Playgroud)
更新:我弄清楚了问题所在-我的服务人员正在使用该importScripts功能,但是我使用的是不支持的Firebase脚本的最新版本fcm_options.link。我将其更改为当前版本的firebase(5.8.5),并且可以正常工作。全部排序!
| 归档时间: |
|
| 查看次数: |
1344 次 |
| 最近记录: |