如何检查FCM消息状态



如何通过FCM收到消息的确认?我有一个渐进式Web应用程序,该应用程序检查用户是否保存在DB中的FCM令牌,如果他们这样做,则使用FCM,如果他们不这样做,则使用SMS(通过Twilio(。问题是即使关闭浏览器,"成功发送的FCM消息"也已记录,因为邮件已排队直到重新打开浏览器。

我该如何说出用户实际收到的消息,并且不会卡住在队列中?如果关闭Chrome,我希望SMS立即发送。

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);
    }
  })
}

当前没有FCM的API或一部分FCM的响应,它告诉您Queue 中的消息是当前是还是已发送的。

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

最新更新