我有一个从 Whatsapp Webhook 获取消息的端点。 然后,此端点调用 async 到另一个端点,并向 Whatsapp Webhook 返回 200。
在我的本地计算机中,这工作完美且快速,但在我的 vercel 部署项目中,它仅到达第一个端点,但只有当我 ping 端点时,它才会被最后一次调用触发。
我尝试添加一些日志,但在 vercel 生产中调试很困难而且不是很有效。 这是我所说的其他端点 这是我的 Whatsapp webhook.ts
const conversation = await prisma.conversation.findFirst({
where: {
senderId: message.senderId,
},
});
console.log(
`${process.env.BASE_URL}/api/whatsapp/services/preValidation`
);
if (!conversation?.verify || !conversation) {
console.log("member is not verified yet");
axios.post(
`${process.env.BASE_URL}/api/whatsapp/services/preValidation`,
{
conversation: conversation,
message: message,
recipientId: teamId,
source: "whatsapp",
}
);
return new Response("message is not verified yet", {
status: 200,
});
}
axios.post(
`${process.env.BASE_URL}/api/facebook/services/handleMessages`,
{
conversation: conversation,
message: message,
recipientId: teamId,
}
);
return new Response("EVENT_RECEIVED", { status: 200 });
我也有类似的问题。主要问题是我们本地开发环境和 Vercel 平台之间的差异。在我们本地,即使我们发送了响应,Axios 调用也会得到解决。在 Vercel 无服务器函数或边缘函数中,一旦返回响应,所有后台任务都会终止,除非您正在流式传输响应或使用类似 https://vercel.com/docs/functions/edge-functions/edge- 的函数functions-api#waituntil; 这就是为什么你看不到日志。
如果您在 Axios 调用之前添加
await
,一切都应该按预期工作。
供参考: