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 2 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" || strings.HasPrefix(p.Value, "http") {

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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I update to have the url type for the param on rapidpro when syncing the templates
nyaruka/rapidpro#5107

and the engine will pass that without changing it https://github.com/nyaruka/goflow/blob/b07f34a76065cea43070b0b0a2c509772a346ad8/flows/actions/send_msg.go#L168

Copy link
Member

Choose a reason for hiding this comment

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

Why do we need || strings.HasPrefix(p.Value, "http") ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is what was there, so I did not want to remove that since the docs are not clear for every case,
I think that was added from trials and errors too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But also I doubt that has ever worked since the we used payload and not text

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I can remove that since the type url is an invalid value there

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