From d55ff291ba7e0c01d71a9054e88edf16bebe4278 Mon Sep 17 00:00:00 2001 From: Norbert Kwizera Date: Fri, 15 Mar 2024 16:52:18 +0200 Subject: [PATCH 1/2] Order components in template and fix max length for D3C --- handlers/dialog360/handler.go | 2 +- handlers/dialog360/handler_test.go | 2 +- handlers/meta/whataspp_test.go | 4 ++-- handlers/meta/whatsapp/api.go | 4 ++-- handlers/meta/whatsapp/templates.go | 4 ++++ 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/handlers/dialog360/handler.go b/handlers/dialog360/handler.go index 29fc0b07f..8f946f525 100644 --- a/handlers/dialog360/handler.go +++ b/handlers/dialog360/handler.go @@ -27,7 +27,7 @@ const ( var ( // max for the body - maxMsgLength = 1000 + maxMsgLength = 4096 ) func init() { diff --git a/handlers/dialog360/handler_test.go b/handlers/dialog360/handler_test.go index d949d5898..b2e8083ed 100644 --- a/handlers/dialog360/handler_test.go +++ b/handlers/dialog360/handler_test.go @@ -432,7 +432,7 @@ var SendTestCasesD3C = []OutgoingTestCase{ }, }, ExpectedRequests: []ExpectedRequest{{ - Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","sub_type":"","index":"","parameters":[{"type":"text","text":"Chef"},{"type":"text","text":"tomorrow"}]}]}}`, + Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","parameters":[{"type":"text","text":"Chef"},{"type":"text","text":"tomorrow"}]}]}}`, }}, ExpectedExtIDs: []string{"157b5e14568e8"}, }, diff --git a/handlers/meta/whataspp_test.go b/handlers/meta/whataspp_test.go index 1baf97a94..e55b50c7f 100644 --- a/handlers/meta/whataspp_test.go +++ b/handlers/meta/whataspp_test.go @@ -401,7 +401,7 @@ var whatsappOutgoingTests = []OutgoingTestCase{ }, }, ExpectedRequests: []ExpectedRequest{{ - Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","sub_type":"","index":"","parameters":[{"type":"text","text":"Chef"},{"type":"text","text":"tomorrow"}]}]}}`, + Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","parameters":[{"type":"text","text":"Chef"},{"type":"text","text":"tomorrow"}]}]}}`, }}, ExpectedExtIDs: []string{"157b5e14568e8"}, }, @@ -456,7 +456,7 @@ var whatsappOutgoingTests = []OutgoingTestCase{ }, }, ExpectedRequests: []ExpectedRequest{{ - Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","sub_type":"","index":"","parameters":[{"type":"text","text":"Ryan Lewis"},{"type":"text","text":"niño"}]},{"type":"button","sub_type":"quick_reply","index":"0","parameters":[{"type":"payload","payload":"Sip"}]},{"type":"button","sub_type":"quick_reply","index":"1","parameters":[{"type":"text","text":"id00231"}]}]}}`, + Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","parameters":[{"type":"text","text":"Ryan Lewis"},{"type":"text","text":"niño"}]},{"type":"button","sub_type":"quick_reply","index":"0","parameters":[{"type":"payload","payload":"Sip"}]},{"type":"button","sub_type":"quick_reply","index":"1","parameters":[{"type":"text","text":"id00231"}]}]}}`, }}, ExpectedExtIDs: []string{"157b5e14568e8"}, }, diff --git a/handlers/meta/whatsapp/api.go b/handlers/meta/whatsapp/api.go index 2bca2a0b1..5a36d008b 100644 --- a/handlers/meta/whatsapp/api.go +++ b/handlers/meta/whatsapp/api.go @@ -155,8 +155,8 @@ type Param struct { type Component struct { Type string `json:"type"` - SubType string `json:"sub_type"` - Index string `json:"index"` + SubType string `json:"sub_type,omitempty"` + Index string `json:"index,omitempty"` Params []*Param `json:"parameters"` } diff --git a/handlers/meta/whatsapp/templates.go b/handlers/meta/whatsapp/templates.go index afe776daf..cb1ae0de7 100644 --- a/handlers/meta/whatsapp/templates.go +++ b/handlers/meta/whatsapp/templates.go @@ -102,5 +102,9 @@ func GetTemplatePayload(templating MsgTemplating) *Template { } + sort.SliceStable(template.Components, func(i, j int) bool { + return template.Components[i].Index < template.Components[j].Index + }) + return template } From 9956f200f34090df5127e5f8efde6dbddaae3dde Mon Sep 17 00:00:00 2001 From: Norbert Kwizera Date: Fri, 15 Mar 2024 17:15:57 +0200 Subject: [PATCH 2/2] Remove sorting components --- handlers/meta/whatsapp/templates.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/handlers/meta/whatsapp/templates.go b/handlers/meta/whatsapp/templates.go index cb1ae0de7..afe776daf 100644 --- a/handlers/meta/whatsapp/templates.go +++ b/handlers/meta/whatsapp/templates.go @@ -102,9 +102,5 @@ func GetTemplatePayload(templating MsgTemplating) *Template { } - sort.SliceStable(template.Components, func(i, j int) bool { - return template.Components[i].Index < template.Components[j].Index - }) - return template }