fix(whatsapp): answer 503 when the inbox cannot take an event, so Meta redelivers
The webhook answered 200 whatever happened downstream, and Meta only redelivers on a non-2xx answer, so an event that reached a stopped service, or a just-started one that had not resolved its companies yet, was lost. mobile-api now answers 503 on an unreachable service or a 5xx (a 4xx refusal still gets 200), and the service answers 503 for a configured number whose company is not resolved yet. wamid uniqueness makes the redelivery safe. Owner decision 2026-12-02; design D3 and the spec updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
1 parent
8984c7c1ae
commit
3e610e0f88
8 files changed
+80
-7
No files matched your search
+22
-2
@@ -27,6 +27,8 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.HttpServerErrorException;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
@@ -251,7 +253,7 @@ class WhatsAppWebhookTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void forwardFailureStillAnswers200AndLogsNoContent() throws Exception {
|
||||
void forwardFailureAnswers503SoMetaRetriesAndLogsNoContent() throws Exception {
|
||||
ListAppender<ILoggingEvent> logs = new ListAppender<>();
|
||||
logs.start();
|
||||
Logger logger = (Logger) LoggerFactory.getLogger(WhatsAppWebhookService.class);
|
||||
@@ -261,7 +263,7 @@ class WhatsAppWebhookTest {
|
||||
byte[] body = BODY.getBytes(StandardCharsets.UTF_8);
|
||||
String sig = sign("ins-secret", body);
|
||||
mvc().perform(post("/api/public/whatsapp/webhook").contentType(MediaType.APPLICATION_JSON).content(body)
|
||||
.header("X-Hub-Signature-256", sig)).andExpect(status().isOk());
|
||||
.header("X-Hub-Signature-256", sig)).andExpect(status().isServiceUnavailable());
|
||||
assertThat(logs.list).isNotEmpty();
|
||||
for (ILoggingEvent e : logs.list) {
|
||||
assertThat(e.getFormattedMessage()).doesNotContain("hello").doesNotContain("secret").doesNotContain(sig).doesNotContain("verify-me");
|
||||
@@ -272,6 +274,24 @@ class WhatsAppWebhookTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void serviceErrorAnswers503SoMetaRetries() throws Exception {
|
||||
when(rest.postForEntity(eq(INGEST), eq(Void.class), any()))
|
||||
.thenThrow(HttpServerErrorException.create(HttpStatus.SERVICE_UNAVAILABLE, "x", null, null, null));
|
||||
byte[] body = BODY.getBytes(StandardCharsets.UTF_8);
|
||||
mvc().perform(post("/api/public/whatsapp/webhook").contentType(MediaType.APPLICATION_JSON).content(body)
|
||||
.header("X-Hub-Signature-256", sign("ins-secret", body))).andExpect(status().isServiceUnavailable());
|
||||
}
|
||||
|
||||
@Test
|
||||
void serviceRefusalStillAnswers200BecauseARetryCannotHelp() throws Exception {
|
||||
when(rest.postForEntity(eq(INGEST), eq(Void.class), any()))
|
||||
.thenThrow(HttpClientErrorException.create(HttpStatus.BAD_REQUEST, "x", null, null, null));
|
||||
byte[] body = BODY.getBytes(StandardCharsets.UTF_8);
|
||||
mvc().perform(post("/api/public/whatsapp/webhook").contentType(MediaType.APPLICATION_JSON).content(body)
|
||||
.header("X-Hub-Signature-256", sign("ins-secret", body))).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rateLimitedByIp() throws Exception {
|
||||
mvc().perform(get("/api/public/whatsapp/webhook").param("hub.mode", "subscribe").param("hub.verify_token", "verify-me").param("hub.challenge", "1"))
|
||||
|
||||
Reference in new issue
Block a user