Skip to content

Commit ba9225b

Browse files
authored
Merge pull request #722 from nyaruka/fix-component-index
Use component name to find button index
2 parents f76d1c2 + 2a5ca0f commit ba9225b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Diff for: handlers/meta/whataspp_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ var whatsappOutgoingTests = []OutgoingTestCase{
429429
MsgMetadata: json.RawMessage(`{ "templating": { "template": { "name": "revive_issue", "uuid": "171f8a4d-f725-46d7-85a6-11aceff0bfe3" },"components": [
430430
{
431431
"type": "body",
432+
"name": "body",
432433
"params": [
433434
{
434435
"type": "text",
@@ -442,6 +443,7 @@ var whatsappOutgoingTests = []OutgoingTestCase{
442443
},
443444
{
444445
"type": "button/quick_reply",
446+
"name": "button.0",
445447
"params": [
446448
{
447449
"type": "text",
@@ -451,6 +453,7 @@ var whatsappOutgoingTests = []OutgoingTestCase{
451453
},
452454
{
453455
"type": "button/url",
456+
"name": "button.1",
454457
"params": [
455458
{
456459
"type": "url",

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)