如何 运行 Firebase 函数中的 Pub-Sub 函数 shell

How to run Pub-Sub functions in Firebase Functions shell

我无法 运行 我在本地 Cloud Functions Shell 中的发布-订阅触发器。我通过以下方式创建了 Cloud Functions:

export const sendNotifications = functions.pubsub.schedule('0 10 * * *').timeZone('Asia/Kolkata').onRun(async (context) => {
    console.log('running sendNotificationForActivities');
    await sendMessages();
    return 0;
}

如前所述 here,我尝试从我的系统 运行 firebase functions:shell 然后是:

> sendNotifications({data: new Buffer('{"hello":"world"}'), attributes: {foo: 'bar'}})

> sendNotifications({})

和其他变体。以下是我收到的错误堆栈跟踪:

firebase > sendNotificationForActivities({})
'Successfully invoked function.'
firebase > ⚠  TypeError: Cannot read property 'params' of undefined
    at cloudFunction (/Users/mayurdhurpate/code/pruoo_app/backend_admin/functions/node_modules/firebase-functions/lib/cloud-functions.js:109:38)
    at Run (/Users/mayurdhurpate/.npm-global/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:458:20)
    at /Users/mayurdhurpate/.npm-global/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:442:19
    at Generator.next (<anonymous>)
    at /Users/mayurdhurpate/.npm-global/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/mayurdhurpate/.npm-global/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:3:12)
    at Run (/Users/mayurdhurpate/.npm-global/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:435:12)
    at /Users/mayurdhurpate/.npm-global/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:457:15
    at Generator.next (<anonymous>)
⚠  Your function was killed because it raised an unhandled error.

我想我可能缺少必填的 params 字段,但我找不到输入参数的正确方法。我在 MacOS 上使用 firebase-tools@7.1.1

我有同样的错误。 错误位于cloud-functions.js:117:28.

他正在尝试访问上下文的键,即使上下文不存在。

我已经更新到最新版本,但错误仍然存​​在。

作为解决方法,我在 cloud-functions.js 的第 89 行添加了这段代码:context = context || {};

这解决了错误,我可以使用 firebase shell。

我希望这个令人讨厌的 hack 有所帮助。 直到 Google 修复他们的代码或更新文档。

多米尼克