Firebase云功能"admin.messaging(...).send不是功能"

enf*_*fix 5 firebase google-cloud-functions firebase-cloud-messaging firebase-admin

我在Firebase Functions服务中有一个发送任何FCM的功能.我会使用admin.messaging().send()函数,就像这个参考指南一样,但是在触发函数时我得到了这个错误,而不是在部署期间:

TypeError: admin.messaging(...).send is not a function
   at exports.sendChatNotification.functions.database.ref.onCreate.event (/user_code/lib/index.js:113:30)
   at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:59:27)
   at next (native)
   at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
   at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
   at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:53:36)
   at /var/tmp/worker/worker.js:700:26
   at process._tickDomainCallback (internal/process/next_tick.js:135:7)
Run Code Online (Sandbox Code Playgroud)

我可以在功能 - >登录Firebase控制台中看到此错误.
那是我的功能代码:

 exports.sendChatNotification = functions.database.ref('/messages').onCreate(event => {

 var message = {
    data: {
        title: 'title',
        body: 'body',
    },
    apns: {
        header: {
            'apns-priority': '10',
            'apns-expiration':'0'
          },
        payload: {
            aps: {
                sound: 'default',
                'content-available':'1'
              }
        }
    },
    android: {
        ttl: 60*1000,
        priority: 'high'
      },
    topic: 'mytopic'
};

return admin.messaging().send(message);

});
Run Code Online (Sandbox Code Playgroud)

如果我使用admin.messaging().sendToTopic()和(更改消息结构),它可以正常工作.Firebase似乎不支持自己的API.

我使用Firebase工具部署它,命令行"firebase deploy".
我在我的函数项目中更新了firebase-tools和firebase-functions以及firebase-admin.

Dou*_*son 9

send()函数已添加到firebase-admin 5.9.0中.如果要使用它,则应npm install firebase-admin@latest在函数文件夹中运行以安装最新版本.在撰写本文时,最新版本是5.9.1.

  • 我有同样的问题:运行此命令不能解决错误. (2认同)