简体   繁体   English

WhatsApp 云 API 在我的 webhook 上多次发送旧消息入站通知

[英]WhatsApp cloud API sending old message inbound notification multiple time on my webhook

I'm new in using WhatsApp cloud API, I've set up one webhook with my WhatsApp cloud API.but the problem is that after some time it sends an inbound notification of an old message again to my webhook.我是使用 WhatsApp 云 API 的新手,我已经使用我的 WhatsApp 云 API 设置了一个 webhook。但问题是一段时间后它再次向我的 webhook 发送一条旧消息的入站通知。

It is called an Idempotence problem.它被称为幂等问题。 Here's what I've done to avoid it.这是我为避免它所做的。

  1. Store each payload in a database when your webhook gets hit.当您的 webhook 被命中时,将每个有效负载存储在数据库中。
  2. Before processing your logic, check whether or not the current payload is already received.在处理您的逻辑之前,请检查是否已收到当前有效负载。
  3. Delete more than three days old records from your database.从您的数据库中删除超过三天的记录。

If a notification isn't delivered for any reason or if the webhook request returns a HTTP status code other than 200, we retry delivery.如果由于任何原因未发送通知,或者如果 webhook 请求返回 HTTP 状态代码不是 200,我们将重试发送。 We continue retrying delivery with increasing delays up to a certain timeout (typically 24 hours, though this may vary), or until the delivery succeeds.我们会继续重试交付,延迟时间会增加,直至达到特定超时(通常为 24 小时,尽管这可能会有所不同),或者直到交付成功。

Whatsapp webhooks documentation Whatsapp 网络钩子文档

I will share my experience and maybe it can help some of you.我将分享我的经验,也许它可以帮助你们中的一些人。

I was returning the status code 200 from my server .从我的服务器返回状态代码 200 But W hatsapp Api Cloud still returned 15 notifications per message .但是Whatsapp Api Cloud 仍然每条消息返回 15 个通知

the problem was that in the past, maybe one month before.问题是过去,也许一个月前。 I had actived webhook messages notifications, but I didn't respond with the status 200 .我激活了 webhook 消息通知,但我没有以状态 200 响应 meanwhile I was building the sending messages backend logic.与此同时,我正在构建发送消息的后端逻辑。 so, there were thousands of webhooks no responded with the Status code 200. So my facebook app went crazy, and when I decided to respond with the status code 200. it didn't work.所以,有成千上万的 webhooks 没有响应状态代码 200。所以我的 facebook 应用程序发疯了,当我决定用状态代码 200 响应时。它没有用。

the solution was to create another facebook app.解决方案是创建另一个 facebook 应用程序。 and the webhooks worked well .并且 webhooks 运行良好

Had the same problem, tried to delete the app but didn't work, I was still receiving old messages from the old app.有同样的问题,尝试删除应用程序但没有用,我仍然收到来自旧应用程序的旧消息。

TLDR; TLDR; don't use the same test number with more than one Facebook App.请勿将同一个测试号用于多个Facebook App。

Even creating a new app, Phone Number ID and Account ID were still the same, my speculation is that the webhooks payloads are tied more to the test phone number rather than the Facebook App.即使创建一个新的应用程序,电话号码 ID 和帐户 ID 仍然相同,我的猜测是 webhooks 有效负载更多地与测试电话号码相关联,而不是 Facebook 应用程序。 For this reason, if you have another application with the same test number and a not working webhook, it keeps sending the same messages to both webhooks.出于这个原因,如果您有另一个应用程序具有相同的测试编号和不工作的 webhook,它会不断向两个 webhook 发送相同的消息。

Within the POST defined in your Webhook, you should always return HTTP Status 200, check that this happens even within your Promises在 Webhook 中定义的 POST 中,您应该始终返回 HTTP Status 200,检查即使在您的 Promises 中也会发生这种情况

Webhooks for WhatsApp Business Accounts WhatsApp 商业账户的 Webhooks

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM