Skip to content

Fix WA button url #715

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 3 commits into from
Mar 15, 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
39 changes: 39 additions & 0 deletions handlers/meta/whataspp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,45 @@ var whatsappOutgoingTests = []OutgoingTestCase{
}},
ExpectedExtIDs: []string{"157b5e14568e8"},
},
{
Label: "Template Send, buttons params",
MsgText: "templated message",
MsgURN: "whatsapp:250788123123",
MsgLocale: "eng",
MsgMetadata: json.RawMessage(`{ "templating": { "template": { "name": "revive_issue", "uuid": "171f8a4d-f725-46d7-85a6-11aceff0bfe3" }, "params": {
"body": [
{
"type": "text",
"value": "Ryan Lewis"
},
{
"type": "text",
"value": "niño"
}
],
"button.0": [
{
"type": "text",
"value": "Sip"
}
],
"button.1": [
{
"type": "url",
"value": "id00231"
}
]
}, "language": "en_US"}}`),
MockResponses: map[string][]*httpx.MockResponse{
"*/12345_ID/messages": {
httpx.NewMockResponse(201, nil, []byte(`{ "messages": [{"id": "157b5e14568e8"}] }`)),
},
},
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","sub_type":"","index":"","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"}]}]}}`,
}},
ExpectedExtIDs: []string{"157b5e14568e8"},
},
{
Label: "Interactive Button Message Send",
MsgText: "Interactive Button Msg",
Expand Down
4 changes: 2 additions & 2 deletions handlers/meta/whatsapp/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
if strings.HasPrefix(k, "button.") {

for _, p := range v {
if strings.HasPrefix(p.Value, "http") {
if p.Type == "url" {

Check warning on line 55 in handlers/meta/whatsapp/templates.go

View check run for this annotation

Codecov / codecov/patch

handlers/meta/whatsapp/templates.go#L55

Added line #L55 was not covered by tests
component := &Component{Type: "button", Index: strings.TrimPrefix(k, "button."), SubType: "quick_reply"}
component.Params = append(component.Params, &Param{Type: "url", Text: p.Value})
component.Params = append(component.Params, &Param{Type: "text", Text: p.Value})

Check warning on line 57 in handlers/meta/whatsapp/templates.go

View check run for this annotation

Codecov / codecov/patch

handlers/meta/whatsapp/templates.go#L57

Added line #L57 was not covered by tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

template.Components = append(template.Components, component)
} else {
component := &Component{Type: "button", Index: strings.TrimPrefix(k, "button."), SubType: "quick_reply"}
Expand Down
2 changes: 1 addition & 1 deletion handlers/meta/whatsapp/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestGetTemplating(t *testing.T) {

msg.WithMetadata(json.RawMessage(`{"templating": {"template": {"uuid": "4ed5000f-5c94-4143-9697-b7cbd230a381", "name": "Update"}}}`))

// invalid templating in metadata, error
// valid templating, no error
tpl, err = whatsapp.GetTemplating(msg)
assert.NoError(t, err)
assert.Equal(t, "4ed5000f-5c94-4143-9697-b7cbd230a381", tpl.Template.UUID)
Expand Down
Loading