【问题标题】:How to check FCM Message status?如何检查 FCM 消息状态?
【发布时间】:2017-11-04 12:53:19
【问题描述】:

我如何通过 FCM 接收收到消息的确认?我有一个渐进式网络应用程序,它检查用户是否在数据库中保存了 fcm 令牌,如果有则使用 FCM,如果没有则使用 SMS(通过 twilio)。问题是即使关闭浏览器也会记录“成功发送 fcm 消息”,因为消息会排队等待重新打开浏览器。

如何判断用户实际收到了一条消息,并且没有在队列中等待?如果 Chrome 已关闭,我希望立即发送短信。

const functions = require('firebase-functions');
const admin = require('firebase-admin');

const serviceAccount = require('./service-account.json');
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: `https://${process.env.GCLOUD_PROJECT}.firebaseio.com`
});

function sendFCM(uid, title, body) {
  const payload = {
    notification: {
      title: title,
      body: body,
      click_action: "https://www.google.com"
    }
  };

  const payloadOptions = {
    timeToLive: 0
  };

  getUserDetails(uid).then((details) => {
    if (details.fcmToken !== undefined) {
      // send fcm message
      return admin.messaging().sendToDevice(details.fcmToken, payload, payloadOptions)
        .then(response => {
          console.log("Successfully sent fcm message");
        })
        .catch((err) => {
          console.log("Failed to send fcm message");
          return sendSMS(details.phone_number, body);
        });;
    } else {
      console.log("No fcm token found for uid", uid);
      return sendSMS(details.phone_number, body);
    }
  })
}

【问题讨论】:

    标签: node.js firebase web firebase-cloud-messaging service-worker


    【解决方案1】:

    目前没有 API 或 FCM 的响应的一部分可以告诉您消息当前是在队列中还是已经发送。

    但是,您可以使用Delivery Receipts注意:实施交付收据需要 XMPP 连接协议)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-03
      • 1970-01-01
      • 2015-03-07
      • 1970-01-01
      • 1970-01-01
      • 2021-05-25
      • 2019-06-19
      相关资源
      最近更新 更多