From 00fd2c49ced8753b5fbd581eb542da916638cf55 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Fri, 15 Mar 2024 10:08:28 -0500 Subject: [PATCH] Make processing of template components deterministic --- handlers/meta/whatsapp/templates.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/handlers/meta/whatsapp/templates.go b/handlers/meta/whatsapp/templates.go index b366ec868..afe776daf 100644 --- a/handlers/meta/whatsapp/templates.go +++ b/handlers/meta/whatsapp/templates.go @@ -2,11 +2,13 @@ package whatsapp import ( "encoding/json" + "sort" "strings" "github.com/nyaruka/courier" "github.com/nyaruka/courier/utils" "github.com/pkg/errors" + "golang.org/x/exp/maps" ) type MsgTemplating struct { @@ -48,7 +50,12 @@ func GetTemplating(msg courier.MsgOut) (*MsgTemplating, error) { func GetTemplatePayload(templating MsgTemplating) *Template { template := &Template{Name: templating.Template.Name, Language: &Language{Policy: "deterministic", Code: templating.Language}} - for k, v := range templating.Params { + compKeys := maps.Keys(templating.Params) + sort.Strings(compKeys) // so that final component order is deterministic + + for _, k := range compKeys { + v := templating.Params[k] + if strings.HasPrefix(k, "button.") { for _, p := range v {