Skip to content

Fix URL parameter for buttons #719

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion handlers/meta/whataspp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ var whatsappOutgoingTests = []OutgoingTestCase{
},
},
ExpectedRequests: []ExpectedRequest{{
Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","parameters":[{"type":"text","text":"Ryan Lewis"},{"type":"text","text":"niño"}]},{"type":"button","sub_type":"quick_reply","index":"0","parameters":[{"type":"payload","payload":"Sip"}]},{"type":"button","sub_type":"quick_reply","index":"1","parameters":[{"type":"text","text":"id00231"}]}]}}`,
Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","parameters":[{"type":"text","text":"Ryan Lewis"},{"type":"text","text":"niño"}]},{"type":"button","sub_type":"quick_reply","index":"0","parameters":[{"type":"payload","payload":"Sip"}]},{"type":"button","sub_type":"url","index":"1","parameters":[{"type":"text","text":"id00231"}]}]}}`,
}},
ExpectedExtIDs: []string{"157b5e14568e8"},
},
Expand Down
14 changes: 14 additions & 0 deletions handlers/meta/whatsapp/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ func GetTemplatePayload(templating *MsgTemplating) *Template {
if k == "header" {
component = &Component{Type: "header"}

for _, p := range v {
if p.Type == "url" {
component := &Component{Type: "button", Index: strings.TrimPrefix(k, "button."), SubType: "url"}
component.Params = append(component.Params, &Param{Type: "text", Text: p.Value})
template.Components = append(template.Components, component)
} else {
component := &Component{Type: "button", Index: strings.TrimPrefix(k, "button."), SubType: "quick_reply"}
component.Params = append(component.Params, &Param{Type: "payload", Payload: p.Value})
template.Components = append(template.Components, component)
}
}

} else if k == "header" {
component := &Component{Type: "header"}
for _, p := range v {
if p.Type == "image" {
component.Params = append(component.Params, &Param{Type: p.Type, Image: &struct {
Expand Down
Loading