Skip to content

Commit

Permalink
Include component name on templating
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Mar 20, 2024
1 parent e0847a2 commit f1f42d5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion flows/actions/send_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
37 changes: 21 additions & 16 deletions flows/actions/testdata/send_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@
},
"components": [
{
"type": "body",
"name": "body",
"params": [
{
"type": "text",
Expand All @@ -481,8 +483,7 @@
"type": "text",
"value": "boy"
}
],
"type": "body"
]
}
],
"namespace": ""
Expand Down Expand Up @@ -580,6 +581,8 @@
},
"components": [
{
"type": "body",
"name": "body",
"params": [
{
"type": "text",
Expand All @@ -589,8 +592,7 @@
"type": "text",
"value": "niño"
}
],
"type": "body"
]
}
],
"namespace": ""
Expand Down Expand Up @@ -921,12 +923,6 @@
"name": "gender_update"
},
"params": {
"header": [
{
"type": "image",
"value": "http://templates.com/rojo.jpg"
}
],
"body": [
{
"type": "text",
Expand All @@ -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",
Expand All @@ -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": ""
Expand Down
1 change: 1 addition & 0 deletions flows/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ type TemplatingParam struct {

type TemplatingComponent struct {
Type string `json:"type"`
Name string `json:"name"`
Params []TemplatingParam `json:"params"`
}

Expand Down
5 changes: 3 additions & 2 deletions flows/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -195,6 +195,7 @@ func TestMsgTemplating(t *testing.T) {
"components":[
{
"type": "body",
"name": "body",
"params":[
{
"type": "text",
Expand Down

0 comments on commit f1f42d5

Please sign in to comment.