Firebase云功能错误:超过了截止日期(颤动推送通知)

时间:2019-09-18 02:42:17

标签: node.js firebase google-cloud-firestore firebase-cloud-messaging google-cloud-functions

因此,我正在尝试使用Firebase-cloud-functions在我的Flutter应用中实现自动推送通知功能。

我的Firebase控制台出现此错误:

Error: Deadline exceeded
    at Http2CallStream.call.on (/srv/node_modules/@grpc/grpc-js/build/src/call.js:68:41)
    at emitOne (events.js:121:20)
    at Http2CallStream.emit (events.js:211:7)
    at process.nextTick (/srv/node_modules/@grpc/grpc-js/build/src/call-stream.js:71:22)
    at _combinedTickCallback (internal/process/next_tick.js:132:7)
    at process._tickDomainCallback (internal/process/next_tick.js:219:9)

这是我的Firebase函数的index.js:

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

admin.initializeApp(functions.config().firebase);

var msgData

exports.offerTrigger = functions.firestore.document(
    'message/{messageID}'
).onCreate((snapshot, context) => {
    msgData = snapshot.data();

    admin.firestore().collection('pushtokens').get().then(async (snapshots) => {
        var tokens = [];
        if (snapshots.empty) {
            console.log('No Devies');
        } else {
            for (var token of snapshots.docs) {
                tokens.push(token.data().devtoken);
            }

            var payload = {
                "notification": {
                    "title": msgData.buissnessName,
                    "body": msgData.messageValue,
                    "sound": "default"
                },
                "data": {
                    "sendername": msgData.buissnessName,
                    "message": msgData.messageValue,
                }
            }
            try {
                const response = await admin.messaging().sendToDevice(tokens, payload);
                console.log('Pushed them all');
            }
            catch (err) {
                console.log(err);
            }
        }
    })
})

这就是令牌保存在Firestore中的方式:

enter image description here

这是我尝试发送推送通知的方式。但是没有用户收到它。

enter image description here

0 个答案:

没有答案