Skip to content

Commit d4455f4

Browse files
committed
Use component name to find button index
1 parent f76d1c2 commit d4455f4

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package whatsapp
22

33
import (
44
"encoding/json"
5-
"fmt"
65
"strings"
76

87
"github.com/nyaruka/courier"
@@ -18,6 +17,7 @@ type MsgTemplating struct {
1817
Namespace string `json:"namespace"`
1918
Components []struct {
2019
Type string `json:"type"`
20+
Name string `json:"name"`
2121
Params []struct {
2222
Type string `json:"type"`
2323
Value string `json:"value"`
@@ -56,7 +56,6 @@ func GetTemplatePayload(templating *MsgTemplating) *Template {
5656
Components: []*Component{},
5757
}
5858

59-
buttonIndex := -1
6059
for _, comp := range templating.Components {
6160
var component *Component
6261

@@ -87,9 +86,7 @@ func GetTemplatePayload(templating *MsgTemplating) *Template {
8786
component.Params = append(component.Params, &Param{Type: p.Type, Text: p.Value})
8887
}
8988
} else if strings.HasPrefix(comp.Type, "button/") {
90-
buttonIndex += 1
91-
92-
component = &Component{Type: "button", Index: fmt.Sprint(buttonIndex), SubType: strings.TrimPrefix(comp.Type, "button/"), Params: []*Param{}}
89+
component = &Component{Type: "button", Index: strings.TrimPrefix(comp.Name, "button."), SubType: strings.TrimPrefix(comp.Type, "button/"), Params: []*Param{}}
9390

9491
for _, p := range comp.Params {
9592
if comp.Type == "button/url" {

0 commit comments

Comments
 (0)