Skip to content

Commit 00fd2c4

Browse files
committed
Make processing of template components deterministic
1 parent ce71e14 commit 00fd2c4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: handlers/meta/whatsapp/templates.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package whatsapp
22

33
import (
44
"encoding/json"
5+
"sort"
56
"strings"
67

78
"github.com/nyaruka/courier"
89
"github.com/nyaruka/courier/utils"
910
"github.com/pkg/errors"
11+
"golang.org/x/exp/maps"
1012
)
1113

1214
type MsgTemplating struct {
@@ -48,7 +50,12 @@ func GetTemplating(msg courier.MsgOut) (*MsgTemplating, error) {
4850
func GetTemplatePayload(templating MsgTemplating) *Template {
4951
template := &Template{Name: templating.Template.Name, Language: &Language{Policy: "deterministic", Code: templating.Language}}
5052

51-
for k, v := range templating.Params {
53+
compKeys := maps.Keys(templating.Params)
54+
sort.Strings(compKeys) // so that final component order is deterministic
55+
56+
for _, k := range compKeys {
57+
v := templating.Params[k]
58+
5259
if strings.HasPrefix(k, "button.") {
5360

5461
for _, p := range v {

0 commit comments

Comments
 (0)