From 411c508d5e9c43cd3385b0a88695243ef3d2f15a Mon Sep 17 00:00:00 2001 From: Norbert Kwizera Date: Mon, 25 Nov 2024 14:31:03 +0200 Subject: [PATCH 1/2] Add send error for channel and contact pair limit hit to allow retrying the message --- handlers/meta/handlers.go | 4 ++++ handlers/meta/whataspp_test.go | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/handlers/meta/handlers.go b/handlers/meta/handlers.go index baa9bc880..8ea413d91 100644 --- a/handlers/meta/handlers.go +++ b/handlers/meta/handlers.go @@ -1090,6 +1090,10 @@ func (h *handler) requestWAC(payload whatsapp.SendRequest, accessToken string, r return courier.ErrResponseUnparseable } + if respPayload.Error.Code == 131056 { + return courier.ErrConnectionThrottled + } + if respPayload.Error.Code != 0 { return courier.ErrFailedWithReason(strconv.Itoa(respPayload.Error.Code), respPayload.Error.Message) } diff --git a/handlers/meta/whataspp_test.go b/handlers/meta/whataspp_test.go index 6484e0f48..24bac9b36 100644 --- a/handlers/meta/whataspp_test.go +++ b/handlers/meta/whataspp_test.go @@ -678,6 +678,17 @@ var whatsappOutgoingTests = []OutgoingTestCase{ }, ExpectedError: courier.ErrResponseUnparseable, }, + { + Label: "Error Channel Contact Pair limit hit", + MsgText: "Pair limit", + MsgURN: "whatsapp:250788123123", + MockResponses: map[string][]*httpx.MockResponse{ + "*/12345_ID/messages": { + httpx.NewMockResponse(403, nil, []byte(`{ "error": {"message": "(#131056) (Business Account, Consumer Account) pair rate limit hit","code": 131056 }}`)), + }, + }, + ExpectedError: courier.ErrConnectionThrottled, + }, { Label: "Error", MsgText: "Error", From 3693fe4d541a6cfe7d34f8f1849d640466f07ae3 Mon Sep 17 00:00:00 2001 From: Norbert Kwizera Date: Mon, 25 Nov 2024 15:12:26 +0200 Subject: [PATCH 2/2] Make all WAC Throttling Errors return courier.ErrConnectionThrottled --- handlers/meta/handlers.go | 5 ++++- handlers/meta/whataspp_test.go | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/handlers/meta/handlers.go b/handlers/meta/handlers.go index 8ea413d91..be3b69d7e 100644 --- a/handlers/meta/handlers.go +++ b/handlers/meta/handlers.go @@ -11,6 +11,7 @@ import ( "fmt" "net/http" "net/url" + "slices" "strconv" "strings" "time" @@ -51,6 +52,8 @@ var ( "account": "ACCOUNT_UPDATE", "agent": "HUMAN_AGENT", } + + wacThrottlingErrorCodes = []int{4, 80007, 130429, 131048, 131056, 133016} ) // keys for extra in channel events @@ -1090,7 +1093,7 @@ func (h *handler) requestWAC(payload whatsapp.SendRequest, accessToken string, r return courier.ErrResponseUnparseable } - if respPayload.Error.Code == 131056 { + if slices.Contains(wacThrottlingErrorCodes, respPayload.Error.Code) { return courier.ErrConnectionThrottled } diff --git a/handlers/meta/whataspp_test.go b/handlers/meta/whataspp_test.go index 24bac9b36..810054896 100644 --- a/handlers/meta/whataspp_test.go +++ b/handlers/meta/whataspp_test.go @@ -690,7 +690,7 @@ var whatsappOutgoingTests = []OutgoingTestCase{ ExpectedError: courier.ErrConnectionThrottled, }, { - Label: "Error", + Label: "Error Throttled", MsgText: "Error", MsgURN: "whatsapp:250788123123", MockResponses: map[string][]*httpx.MockResponse{ @@ -698,7 +698,18 @@ var whatsappOutgoingTests = []OutgoingTestCase{ httpx.NewMockResponse(403, nil, []byte(`{ "error": {"message": "(#130429) Rate limit hit","code": 130429 }}`)), }, }, - ExpectedError: courier.ErrFailedWithReason("130429", "(#130429) Rate limit hit"), + ExpectedError: courier.ErrConnectionThrottled, + }, + { + Label: "Error", + MsgText: "Error", + MsgURN: "whatsapp:250788123123", + MockResponses: map[string][]*httpx.MockResponse{ + "*/12345_ID/messages": { + httpx.NewMockResponse(403, nil, []byte(`{ "error": {"message": "(#368) Temporarily blocked for policies violations","code": 368 }}`)), + }, + }, + ExpectedError: courier.ErrFailedWithReason("368", "(#368) Temporarily blocked for policies violations"), }, { Label: "Error Connection",