Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add send error for channel and contact pair limit hit that allow retr… #805

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions handlers/meta/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"net/http"
"net/url"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1090,6 +1093,10 @@ func (h *handler) requestWAC(payload whatsapp.SendRequest, accessToken string, r
return courier.ErrResponseUnparseable
}

if slices.Contains(wacThrottlingErrorCodes, respPayload.Error.Code) {
return courier.ErrConnectionThrottled
}

if respPayload.Error.Code != 0 {
return courier.ErrFailedWithReason(strconv.Itoa(respPayload.Error.Code), respPayload.Error.Message)
}
Expand Down
26 changes: 24 additions & 2 deletions handlers/meta/whataspp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,15 +679,37 @@ var whatsappOutgoingTests = []OutgoingTestCase{
ExpectedError: courier.ErrResponseUnparseable,
},
{
Label: "Error",
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 Throttled",
MsgText: "Error",
MsgURN: "whatsapp:250788123123",
MockResponses: map[string][]*httpx.MockResponse{
"*/12345_ID/messages": {
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",
Expand Down
Loading