小编cam*_*e92的帖子

如何在Firebase Web通知中获取`fcm_options.link`功能

我正在尝试使用针对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)

push-notification node.js firebase firebase-cloud-messaging

3
推荐指数
2
解决办法
1344
查看次数