云功能无法记录任何内容?

时间:2019-06-18 20:04:18

标签: reactjs react-native firebase-realtime-database firebase-cloud-messaging google-cloud-functions

我已经在StackOverflow上看到了本主题中的所有问题,但是我没有解决问题,

所以我正在编写一个向特定设备发送通知的函数,我获得了FCM令牌,并将它们作为变量手动写入函数中。关于此函数的想法,如果我创建了订单,就会触发实时数据库,我将发送一个简单的通知,并将其记录下来,但是尽管该命令保存在数据库中,但在Firebase控制台的“日志”中却没有看到任何内容,那又是什么问题呢?

这是我的功能:

const admin = require('firebase-admin');
const functions = require('firebase-functions');
// const serviceAccount = require('./service_account.json');
const serviceAccount = {
    "type": "service_account",
    "project_id": "kapp-42657",
    "private_key_id": ".................",
    "private_key": "-----BEGIN PRIVATE KEY----------END PRIVATE KEY-----\n",
    "client_email": ".........",
    "client_id": ".....",
    "auth_uri": "...............",
    "token_uri": "............",
    "auth_provider_x509_cert_url": "............": "....."
}

var registrationTokens = "d4QgBGV6HDM:APA91bE77aQBv9XsW5x2arnBYkk9LNZ8jrbn81Al00Z-HFXnJkgWc5dH3AyhWWvPGw7Y2ef4euo9iZPaHUSsviSaFWaQdnOT7XRRDsBzux53gboWkscxIO7DYbOp-wzjQ6Sq1wag3aQj";
// const registrationTokens = AsynStorage.getItem('deviceToken');

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://kapp-42657.firebaseio.com"
});

// admin.initializeApp(functions.config().firebase);
// Notification details.
const payload = {
    notification: {
        title: 'Hey Provider One',
        body: `You have Got new notity.`
    }
};

exports.onOrderCreateOrder = functions.database.ref('request/{providerId}/{userId}/order')
    .onCreate(async (snapshot, context) => {
        const providerId = context.params.providerId;
        const userId = context.params.userId;
        console.log(`New Order from ${userId} to ${providerId}`);
        //New Order from UID to PID
        const orderData = snapshot.val();
        console.log("@orderData", orderData);
        //@orderData { OrderID: { name: 'hey', price: 500, providerService: 'Plumber' } }
        try {
            const response = await admin.messaging().sendToDevice(registrationTokens, payload);
            console.log('Successfully sent message:', response);
        }
        catch (error) {
            console.log('Error sending message:', error);
        }

    });

0 个答案:

没有答案