Skip to content

Use component name to find button index #722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions handlers/meta/whataspp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ var whatsappOutgoingTests = []OutgoingTestCase{
MsgMetadata: json.RawMessage(`{ "templating": { "template": { "name": "revive_issue", "uuid": "171f8a4d-f725-46d7-85a6-11aceff0bfe3" },"components": [
{
"type": "body",
"name": "body",
"params": [
{
"type": "text",
Expand All @@ -442,6 +443,7 @@ var whatsappOutgoingTests = []OutgoingTestCase{
},
{
"type": "button/quick_reply",
"name": "button.0",
"params": [
{
"type": "text",
Expand All @@ -451,6 +453,7 @@ var whatsappOutgoingTests = []OutgoingTestCase{
},
{
"type": "button/url",
"name": "button.1",
"params": [
{
"type": "url",
Expand Down
7 changes: 2 additions & 5 deletions handlers/meta/whatsapp/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package whatsapp

import (
"encoding/json"
"fmt"
"strings"

"github.com/nyaruka/courier"
Expand All @@ -18,6 +17,7 @@ type MsgTemplating struct {
Namespace string `json:"namespace"`
Components []struct {
Type string `json:"type"`
Name string `json:"name"`
Params []struct {
Type string `json:"type"`
Value string `json:"value"`
Expand Down Expand Up @@ -56,7 +56,6 @@ func GetTemplatePayload(templating *MsgTemplating) *Template {
Components: []*Component{},
}

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

Expand Down Expand Up @@ -87,9 +86,7 @@ func GetTemplatePayload(templating *MsgTemplating) *Template {
component.Params = append(component.Params, &Param{Type: p.Type, Text: p.Value})
}
} else if strings.HasPrefix(comp.Type, "button/") {
buttonIndex += 1

component = &Component{Type: "button", Index: fmt.Sprint(buttonIndex), SubType: strings.TrimPrefix(comp.Type, "button/"), Params: []*Param{}}
component = &Component{Type: "button", Index: strings.TrimPrefix(comp.Name, "button."), SubType: strings.TrimPrefix(comp.Type, "button/"), Params: []*Param{}}

for _, p := range comp.Params {
if comp.Type == "button/url" {
Expand Down
Loading