can some one explain me this..
in My messenger bot I have following code:
entry.messaging.forEach(async function (webhookEvent) {
// Discard uninteresting events
if ("read" in webhookEvent) {
console.log("Got a read event");
return;
} else if ("delivery" in webhookEvent) {
console.log("Got a delivery event");
return;
} else if (webhookEvent.message && webhookEvent.message.is_echo) {
console.log(
"Got an echo of our send, mid = " webhookEvent.message.mid
);
return;
}
The error I get:
entry.messaging.forEach( /*#__PURE__*/function () {
TypeError: Cannot read properties of undefined (reading 'forEach')
CodePudding user response:
You should check the existing of entry.messaging at first then create a forEach loop for it. Like below:
entry.messaging && entry.messaging.forEach(...)