【发布时间】:2020-03-03 13:33:42
【问题描述】:
我有一个 webhook 可以在云功能中接收 facebook messenger 事件,如下所示:
export const facebookMessengerHook = functions.https.onRequest(async (req: express.Request, res: express.Response) => {
console.log(req);
console.log(req.method);
console.log(req.body);
if (req.method == "POST") {
const body = req.body;
console.log(body);
// Checks this is an event from a page subscription
if (body.object === 'page') {
res.status(200).send('EVENT_RECEIVED');
// Iterates over each entry - there may be multiple if batched
for (const entry of body.entry) {
// will only ever contain one message, so we get index 0
const webhook_data = entry.messaging[0];
console.log(webhook_data);
try {
// v THAT PART HERE v
const user = await admin.firestore().collection('users')
.where('facebookMessengerId', '==', webhook_data.sender.id)
.get();
// ^ THAT PART HERE ^
console.log(user);
} catch (e) {
console.log('No user');
}
}
}
else {
// Returns a '404 Not Found' if event is not from a page subscription
res.sendStatus(404);
}
}
});
它不会记录任何东西,除非我在 sn-p 中注释掉标记的部分。
有人可以向我解释一下为什么以及如何解决这个问题,因为我需要调用 firestore 并且还需要 console.log 用于调试目的?
感谢您的帮助!
【问题讨论】:
-
这很奇怪。我了解您通常会获取其他所有内容的日志。所以不只记录您在
try语句中得到的user? -
@PabloAlmécijaRodríguez 不,这不会改变任何事情。
标签: node.js typescript firebase google-cloud-firestore google-cloud-functions