Skip to content

Fix button URLs for WA templates #720

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
1 change: 1 addition & 0 deletions handlers/meta/whatsapp/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func GetTemplatePayload(templating *MsgTemplating) *Template {

for _, p := range v {
if p.Type == "url" {
component.SubType = "url"
Copy link
Member

Choose a reason for hiding this comment

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

Not convinced we've modeled this correctly since we now need to infer component type from param type... and these params should be just type text.. param type was just supposed to tell the editor what kinda of widget to display. Maybe templating should include component type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we could add the component type to the components we save? in addition to the content and params keys?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At least that is needed for the buttons

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 tied adding the type to components nyaruka/rapidpro#5111 however that will require we change the

https://github.com/nyaruka/goflow/blob/545576482f9968644052b66f00544c972aa1cc33/flows/msg.go#L177

instead of

Params_    map[string][]TemplateParam `json:"params,omitempty"`

We have a array of components

Components_ []TemplateComponen

type TemplateComponen struct {
   Name string // what was used as key in the previous map
   Type string
   Params []TemplateParam
}

And that could make the loop

for _, k := range compKeys {
easier as well

component.Params = append(component.Params, &Param{Type: "text", Text: p.Value})
} else {
component.Params = append(component.Params, &Param{Type: "payload", Payload: p.Value})
Expand Down
4 changes: 3 additions & 1 deletion handlers/meta/whatsapp/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func TestGetTemplatePayload(t *testing.T) {
"language": "en",
"params": {
"button.1": [{"type": "text", "value": "No"}],
"button.0": [{"type": "text", "value": "Yes"}, {"type": "text", "value": "Bob"}]
"button.0": [{"type": "text", "value": "Yes"}, {"type": "text", "value": "Bob"}],
"button.2": [{"type": "url", "value": "id0023"}]
}
}`,
expected: &whatsapp.Template{
Expand All @@ -93,6 +94,7 @@ func TestGetTemplatePayload(t *testing.T) {
Components: []*whatsapp.Component{
{Type: "button", SubType: "quick_reply", Index: "0", Params: []*whatsapp.Param{{Type: "payload", Payload: "Yes"}, {Type: "payload", Payload: "Bob"}}},
{Type: "button", SubType: "quick_reply", Index: "1", Params: []*whatsapp.Param{{Type: "payload", Payload: "No"}}},
{Type: "button", SubType: "url", Index: "2", Params: []*whatsapp.Param{{Type: "text", Text: "id0023"}}},
},
},
},
Expand Down
Loading