diff --git a/flows/actions/send_msg.go b/flows/actions/send_msg.go index fe53115aa..da3297a6c 100644 --- a/flows/actions/send_msg.go +++ b/flows/actions/send_msg.go @@ -174,7 +174,7 @@ func (a *SendMsgAction) getTemplateMsg(run flows.Run, urn urns.URN, channelRef * } } - compTemplating := &flows.TemplatingComponent{Type: comp.Type(), Params: params} + compTemplating := &flows.TemplatingComponent{Type: comp.Type(), Name: comp.Name(), Params: params} previewContent := compTemplating.Preview(comp) if previewContent != "" { diff --git a/flows/actions/testdata/send_msg.json b/flows/actions/testdata/send_msg.json index 93bad0668..b2957e707 100644 --- a/flows/actions/testdata/send_msg.json +++ b/flows/actions/testdata/send_msg.json @@ -472,6 +472,8 @@ }, "components": [ { + "type": "body", + "name": "body", "params": [ { "type": "text", @@ -481,8 +483,7 @@ "type": "text", "value": "boy" } - ], - "type": "body" + ] } ], "namespace": "" @@ -580,6 +581,8 @@ }, "components": [ { + "type": "body", + "name": "body", "params": [ { "type": "text", @@ -589,8 +592,7 @@ "type": "text", "value": "niño" } - ], - "type": "body" + ] } ], "namespace": "" @@ -921,12 +923,6 @@ "name": "gender_update" }, "params": { - "header": [ - { - "type": "image", - "value": "http://templates.com/rojo.jpg" - } - ], "body": [ { "type": "text", @@ -942,19 +938,28 @@ "type": "text", "value": "Sip" } + ], + "header": [ + { + "type": "image", + "value": "http://templates.com/rojo.jpg" + } ] }, "components": [ { + "type": "header", + "name": "header", "params": [ { "type": "image", "value": "http://templates.com/rojo.jpg" } - ], - "type": "header" + ] }, { + "type": "body", + "name": "body", "params": [ { "type": "text", @@ -964,17 +969,17 @@ "type": "text", "value": "niño" } - ], - "type": "body" + ] }, { + "type": "button/quick_reply", + "name": "button.0", "params": [ { "type": "text", "value": "Sip" } - ], - "type": "button/quick_reply" + ] } ], "namespace": "" diff --git a/flows/msg.go b/flows/msg.go index 330f94929..fab381773 100644 --- a/flows/msg.go +++ b/flows/msg.go @@ -177,6 +177,7 @@ type TemplatingParam struct { type TemplatingComponent struct { Type string `json:"type"` + Name string `json:"name"` Params []TemplatingParam `json:"params"` } diff --git a/flows/msg_test.go b/flows/msg_test.go index b088c8423..a0cf2ea98 100644 --- a/flows/msg_test.go +++ b/flows/msg_test.go @@ -163,12 +163,12 @@ func TestMsgTemplating(t *testing.T) { templateRef := assets.NewTemplateReference("61602f3e-f603-4c70-8a8f-c477505bf4bf", "Affirmation") - msgTemplating := flows.NewMsgTemplating(templateRef, map[string][]flows.TemplatingParam{"body": {{Type: "text", Value: "Ryan Lewis"}, {Type: "text", Value: "boy"}}}, []*flows.TemplatingComponent{{Type: "body", Params: []flows.TemplatingParam{{Type: "text", Value: "Ryan Lewis"}, {Type: "text", Value: "boy"}}}}, "0162a7f4_dfe4_4c96_be07_854d5dba3b2b") + msgTemplating := flows.NewMsgTemplating(templateRef, map[string][]flows.TemplatingParam{"body": {{Type: "text", Value: "Ryan Lewis"}, {Type: "text", Value: "boy"}}}, []*flows.TemplatingComponent{{Type: "body", Name: "body", Params: []flows.TemplatingParam{{Type: "text", Value: "Ryan Lewis"}, {Type: "text", Value: "boy"}}}}, "0162a7f4_dfe4_4c96_be07_854d5dba3b2b") assert.Equal(t, templateRef, msgTemplating.Template()) assert.Equal(t, "0162a7f4_dfe4_4c96_be07_854d5dba3b2b", msgTemplating.Namespace()) assert.Equal(t, map[string][]flows.TemplatingParam{"body": {{Type: "text", Value: "Ryan Lewis"}, {Type: "text", Value: "boy"}}}, msgTemplating.Params()) - assert.Equal(t, []*flows.TemplatingComponent{{Type: "body", Params: []flows.TemplatingParam{{Type: "text", Value: "Ryan Lewis"}, {Type: "text", Value: "boy"}}}}, msgTemplating.Components()) + assert.Equal(t, []*flows.TemplatingComponent{{Type: "body", Name: "body", Params: []flows.TemplatingParam{{Type: "text", Value: "Ryan Lewis"}, {Type: "text", Value: "boy"}}}}, msgTemplating.Components()) // test marshaling our msg marshaled, err := jsonx.Marshal(msgTemplating) @@ -195,6 +195,7 @@ func TestMsgTemplating(t *testing.T) { "components":[ { "type": "body", + "name": "body", "params":[ { "type": "text",