【问题标题】:How to get `fcm_options.link` functioning in firebase web notifications如何在 Firebase 网络通知中获得“fcm_options.link”功能
【发布时间】:2019-08-18 06:04:48
【问题描述】:

我正在尝试使用适用于 node.js 的 firebase 管理 SDK(版本 7.0.0)让我的 FCM 网络通知包含指向我的网站的可点击链接。据我所知,我正在关注文档到 T,但我无法使链接正常工作。澄清一下,否则我的通知工作正常,只是我没有工作的链接。

documentation 声明:

对于从应用服务器发送的通知消息,FCM JavaScript API 支持 fcm_options.link 键。通常这被设置为您的网络应用程序中的一个页面

我已将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'
};

这是我用来发送消息的函数:

const admin = require('firebase-admin')

const sendMessage = message => {
    admin
        .messaging()
        .send(message)
        .then(response => {
            console.log(response)
        })
        .catch(error => {
            console.log(error)
        });
};

link 属性应该根据文档工作:我的 url 包含 https 并且我的通知是从应用服务器发送的,并且包含显式通知负载。目前,点击通知只是让它消失,没有其他任何事情发生。

【问题讨论】:

  • 您能否更新您的问题以包含您用于发送消息的 Admin SDK 功能?
  • @JenPerson 已编辑,谢谢!
  • 嗯......这看起来都是正确的。我想确保您使用的是新的 FCM API,并且看起来您正在使用。您使用的是哪个版本的管理员?在此期间,我会尝试从团队中了解更多信息
  • @JenPerson 几天前使用7.1.1,是的,我正在使用 v1 api。非常感谢您的帮助!
  • 能否告诉您您使用的是哪个版本的 Firebase 客户端 SDK?

标签: node.js firebase push-notification firebase-cloud-messaging


【解决方案1】:

更新:我找出了问题所在 - 我的服务人员正在使用 importScripts 函数,但我使用的是不支持 fcm_options.link 的过期版本的 firebase 脚本。我将它更改为我当前版本的 firebase (5.8.5) 并且它可以工作。全部排序!

【讨论】:

  • 遇到了同样的问题,结果是同样的问题,感谢更新。
  • @camargue92 谢谢。那是为我做的。猜猜我们从firebase guide 复制了代码。您应该将此标记为已接受。
  • 我当前的版本是7.6.2,已经和sw.js匹配但是fcm在发送Messaging payload contains an invalid "webpush" property. Valid properties are "data" and "notification"的时候抛出错误还有其他线索吗?
  • 我最终使用FCM Data type 并处理来自服务人员notificationclick 的显示通知(和点击事件)
【解决方案2】:

在通知中试试这个

"notification":{
"title":"IssA",
"body":"Lafi",
"icon": "Icon URL",
"click_action": "Your URL here"
}

【讨论】:

  • 这是javascript SDK 7.1.0的当前解决方案
  • 这是用于 Firebase FCM
【解决方案3】:

在上一个版本中,在 node js 中使用 firebase admin,这是正确的配置:

        var message = {
          notification: {
            title: "",
            body: ""                
          },
          webpush: {
            fcmOptions: {
              link: "https://yourlink.web.app"
            }
          }
        };

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-28
    • 1970-01-01
    相关资源
    最近更新 更多