diff --git a/handlers/meta/whataspp_test.go b/handlers/meta/whataspp_test.go index 32c40aa1b..7393a8125 100644 --- a/handlers/meta/whataspp_test.go +++ b/handlers/meta/whataspp_test.go @@ -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"}, @@ -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"}, }, diff --git a/handlers/meta/whatsapp/templates.go b/handlers/meta/whatsapp/templates.go index b22d00379..1a9eb03ae 100644 --- a/handlers/meta/whatsapp/templates.go +++ b/handlers/meta/whatsapp/templates.go @@ -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" { @@ -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})