Skip to content

Commit

Permalink
Merge pull request #717 from nyaruka/template_tweak
Browse files Browse the repository at this point in the history
Make processing of template components deterministic
  • Loading branch information
rowanseymour authored Mar 15, 2024
2 parents ce71e14 + 00fd2c4 commit 9ba8161
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion handlers/meta/whatsapp/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9ba8161

Please sign in to comment.