Skip to content

Commit

Permalink
Merge pull request #755 from nyaruka/template_fmt_tweak
Browse files Browse the repository at this point in the history
Support template component types `header/*` and `body/*`
  • Loading branch information
rowanseymour authored Jun 10, 2024
2 parents 4192fd8 + 6ccff12 commit 533866c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions handlers/meta/whataspp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,13 @@ var whatsappOutgoingTests = []OutgoingTestCase{
MsgTemplating: `{
"template": {"uuid": "171f8a4d-f725-46d7-85a6-11aceff0bfe3", "name": "revive_issue"},
"components": [
{"type": "body", "name": "body", "variables": {"1": 0, "2": 1}},
{"type": "button/quick_reply", "name": "button.0", "variables": {"1": 2}},
{"type": "button/url", "name": "button.1", "variables": {"1": 3}}
{"name": "header", "type": "header/image", "variables": {"1": 0}},
{"name": "body", "type": "body/text", "variables": {"1": 1, "2": 2}},
{"name": "button.0", "type": "button/quick_reply", "variables": {"1": 3}},
{"name": "button.1", "type": "button/url", "variables": {"1": 4}}
],
"variables": [
{"type": "image", "value": "image/jpeg:https://foo.bar/image.jpg"},
{"type": "text", "value": "Ryan Lewis"},
{"type": "text", "value": "niño"},
{"type": "text", "value": "Sip"},
Expand All @@ -459,7 +461,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":"url","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":"header","parameters":[{"type":"image","image":{"link":"https://foo.bar/image.jpg"}}]},{"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
8 changes: 4 additions & 4 deletions handlers/meta/whatsapp/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func GetTemplatePayload(templating *courier.Templating) *Template {

var component *Component

if comp.Type == "header" {
component = &Component{Type: comp.Type}
if comp.Type == "header" || strings.HasPrefix(comp.Type, "header/") {
component = &Component{Type: "header"}

for _, p := range compParams {
if p.Type != "text" {
Expand All @@ -52,8 +52,8 @@ func GetTemplatePayload(templating *courier.Templating) *Template {
component.Params = append(component.Params, &Param{Type: p.Type, Text: p.Value})
}
}
} else if comp.Type == "body" {
component = &Component{Type: comp.Type}
} else if comp.Type == "body" || strings.HasPrefix(comp.Type, "body/") {
component = &Component{Type: "body"}

for _, p := range compParams {
component.Params = append(component.Params, &Param{Type: p.Type, Text: p.Value})
Expand Down

0 comments on commit 533866c

Please sign in to comment.