diff --git a/handlers/dialog360/handler.go b/handlers/dialog360/handler.go index e2b14d522..29fc0b07f 100644 --- a/handlers/dialog360/handler.go +++ b/handlers/dialog360/handler.go @@ -337,6 +337,13 @@ func (h *handler) Send(ctx context.Context, msg courier.MsgOut, res *courier.Sen } else { if len(qrs) > 0 { payload.Type = "interactive" + + // if we have more than 10 quick replies, truncate and add channel error + if len(qrs) > 10 { + clog.Error(courier.NewChannelError("", "", "too many quick replies D3C supports only up to 10 quick replies")) + qrs = qrs[:10] + } + // We can use buttons if len(qrs) <= 3 { interactive := whatsapp.Interactive{Type: "button", Body: struct { @@ -357,7 +364,7 @@ func (h *handler) Send(ctx context.Context, msg courier.MsgOut, res *courier.Sen Buttons []whatsapp.Button "json:\"buttons,omitempty\"" }{Buttons: btns} payload.Interactive = &interactive - } else if len(qrs) <= 10 { + } else { interactive := whatsapp.Interactive{Type: "list", Body: struct { Text string "json:\"text\"" }{Text: msgParts[i-len(msg.Attachments())]}} @@ -381,8 +388,6 @@ func (h *handler) Send(ctx context.Context, msg courier.MsgOut, res *courier.Sen }} payload.Interactive = &interactive - } else { - return fmt.Errorf("too many quick replies WAC supports only up to 10 quick replies") } } else { // this is still a msg part @@ -430,6 +435,12 @@ func (h *handler) Send(ctx context.Context, msg courier.MsgOut, res *courier.Sen } else { if len(qrs) > 0 { payload.Type = "interactive" + // if we have more than 10 quick replies, truncate and add channel error + if len(qrs) > 10 { + clog.Error(courier.NewChannelError("", "", "too many quick replies D3C supports only up to 10 quick replies")) + qrs = qrs[:10] + } + // We can use buttons if len(qrs) <= 3 { interactive := whatsapp.Interactive{Type: "button", Body: struct { @@ -508,7 +519,7 @@ func (h *handler) Send(ctx context.Context, msg courier.MsgOut, res *courier.Sen }{Buttons: btns} payload.Interactive = &interactive - } else if len(qrs) <= 10 { + } else { interactive := whatsapp.Interactive{Type: "list", Body: struct { Text string "json:\"text\"" }{Text: msgParts[i-len(msg.Attachments())]}} @@ -532,8 +543,6 @@ func (h *handler) Send(ctx context.Context, msg courier.MsgOut, res *courier.Sen }} payload.Interactive = &interactive - } else { - return fmt.Errorf("too many quick replies WAC supports only up to 10 quick replies") } } else { // this is still a msg part diff --git a/handlers/dialog360/handler_test.go b/handlers/dialog360/handler_test.go index 09b6af155..8d2d3af06 100644 --- a/handlers/dialog360/handler_test.go +++ b/handlers/dialog360/handler_test.go @@ -465,6 +465,22 @@ var SendTestCasesD3C = []OutgoingTestCase{ }}, ExpectedExtIDs: []string{"157b5e14568e8"}, }, + { + Label: "Interactive List Message Send more than 10 QRs", + MsgText: "Interactive List Msg", + MsgURN: "whatsapp:250788123123", + MsgQuickReplies: []string{"ROW1", "ROW2", "ROW3", "ROW4", "ROW5", "ROW6", "ROW7", "ROW8", "ROW9", "ROW10", "ROW11", "ROW12"}, + MockResponses: map[string][]*httpx.MockResponse{ + "https://waba-v2.360dialog.io/messages": { + httpx.NewMockResponse(201, nil, []byte(`{ "messages": [{"id": "157b5e14568e8"}] }`)), + }, + }, + ExpectedRequests: []ExpectedRequest{{ + Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"list","body":{"text":"Interactive List Msg"},"action":{"button":"Menu","sections":[{"rows":[{"id":"0","title":"ROW1"},{"id":"1","title":"ROW2"},{"id":"2","title":"ROW3"},{"id":"3","title":"ROW4"},{"id":"4","title":"ROW5"},{"id":"5","title":"ROW6"},{"id":"6","title":"ROW7"},{"id":"7","title":"ROW8"},{"id":"8","title":"ROW9"},{"id":"9","title":"ROW10"}]}]}}}`, + }}, + ExpectedExtIDs: []string{"157b5e14568e8"}, + ExpectedLogErrors: []*courier.ChannelError{courier.NewChannelError("", "", "too many quick replies D3C supports only up to 10 quick replies")}, + }, { Label: "Interactive List Message Send In Spanish", MsgText: "Hola",