1

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

如何判断消息是否真的被用户接收,并且isn “T卡在队列中等待?如果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); 
    } 
    }) 
} 

回答

1

目前还没有API或FCM,告诉您该响应的一部分,如果消息是目前在排队或已经发送

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