Skip to content

Commit

Permalink
Merge pull request #1236 from nyaruka/rem_templating_params
Browse files Browse the repository at this point in the history
Remove no longer used templating.params
  • Loading branch information
rowanseymour authored Mar 20, 2024
2 parents 5c1d910 + 7597a76 commit 3aa1619
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 74 deletions.
4 changes: 1 addition & 3 deletions flows/actions/send_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ func (a *SendMsgAction) getTemplateMsg(run flows.Run, urn urns.URN, channelRef *

// next we cross reference with params defined in the template translation to get types
components := make([]*flows.TemplatingComponent, 0, len(translation.Components()))
legacy := make(map[string][]flows.TemplatingParam, len(translation.Components())) // TODO deprecated

// the message we return is an approximate preview of what the channel will send using the template
var previewParts []string
Expand Down Expand Up @@ -187,14 +186,13 @@ func (a *SendMsgAction) getTemplateMsg(run flows.Run, urn urns.URN, channelRef *

if len(params) > 0 {
components = append(components, compTemplating)
legacy[comp.Name()] = params
}
}

previewText := strings.Join(previewParts, "\n\n")

locale := translation.Locale()
templating := flows.NewMsgTemplating(a.Templating.Template, legacy, components, translation.Namespace())
templating := flows.NewMsgTemplating(a.Templating.Template, translation.Namespace(), components)

return flows.NewMsgOut(urn, channelRef, previewText, nil, previewQRs, templating, flows.NilMsgTopic, locale, unsendableReason)
}
48 changes: 0 additions & 48 deletions flows/actions/testdata/send_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -458,18 +458,6 @@
"uuid": "5722e1fd-fe32-4e74-ac78-3cf41a6adb7e",
"name": "affirmation"
},
"params": {
"body": [
{
"type": "text",
"value": "Ryan Lewis"
},
{
"type": "text",
"value": "boy"
}
]
},
"components": [
{
"type": "body",
Expand Down Expand Up @@ -567,18 +555,6 @@
"uuid": "5722e1fd-fe32-4e74-ac78-3cf41a6adb7e",
"name": "affirmation"
},
"params": {
"body": [
{
"type": "text",
"value": "Ryan Lewis"
},
{
"type": "text",
"value": "niño"
}
]
},
"components": [
{
"type": "body",
Expand Down Expand Up @@ -922,30 +898,6 @@
"uuid": "ce00c80e-991a-4c03-b373-3273c23ee042",
"name": "gender_update"
},
"params": {
"body": [
{
"type": "text",
"value": "Ryan Lewis"
},
{
"type": "text",
"value": "niño"
}
],
"button.0": [
{
"type": "text",
"value": "Sip"
}
],
"header": [
{
"type": "image",
"value": "http://templates.com/rojo.jpg"
}
]
},
"components": [
{
"type": "header",
Expand Down
14 changes: 5 additions & 9 deletions flows/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,14 @@ func (tc *TemplatingComponent) Preview(c assets.TemplateComponent) string {

// MsgTemplating represents any substituted message template that should be applied when sending this message
type MsgTemplating struct {
Template_ *assets.TemplateReference `json:"template"`
Params_ map[string][]TemplatingParam `json:"params,omitempty"`
Components_ []*TemplatingComponent `json:"components,omitempty"`
Namespace_ string `json:"namespace"`
Template_ *assets.TemplateReference `json:"template"`
Namespace_ string `json:"namespace"`
Components_ []*TemplatingComponent `json:"components,omitempty"`
}

// NewMsgTemplating creates and returns a new msg template
func NewMsgTemplating(template *assets.TemplateReference, params map[string][]TemplatingParam, components []*TemplatingComponent, namespace string) *MsgTemplating {
return &MsgTemplating{Template_: template, Namespace_: namespace, Components_: components, Params_: params}
func NewMsgTemplating(template *assets.TemplateReference, namespace string, components []*TemplatingComponent) *MsgTemplating {
return &MsgTemplating{Template_: template, Namespace_: namespace, Components_: components}
}

// Template returns the template this msg template is for
Expand All @@ -218,9 +217,6 @@ func (t *MsgTemplating) Namespace() string { return t.Namespace_ }
// Components returns the components that should be used for the templates
func (t *MsgTemplating) Components() []*TemplatingComponent { return t.Components_ }

// Params returns the params that should be used for the template
func (t *MsgTemplating) Params() map[string][]TemplatingParam { return t.Params_ }

// BroadcastTranslation is the broadcast content in a particular language
type BroadcastTranslation struct {
Text string `json:"text"`
Expand Down
15 changes: 1 addition & 14 deletions flows/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,10 @@ 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", Name: "body", Params: []flows.TemplatingParam{{Type: "text", Value: "Ryan Lewis"}, {Type: "text", Value: "boy"}}}}, "0162a7f4_dfe4_4c96_be07_854d5dba3b2b")
msgTemplating := flows.NewMsgTemplating(templateRef, "0162a7f4_dfe4_4c96_be07_854d5dba3b2b", []*flows.TemplatingComponent{{Type: "body", Name: "body", Params: []flows.TemplatingParam{{Type: "text", Value: "Ryan Lewis"}, {Type: "text", Value: "boy"}}}})

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", Name: "body", Params: []flows.TemplatingParam{{Type: "text", Value: "Ryan Lewis"}, {Type: "text", Value: "boy"}}}}, msgTemplating.Components())

// test marshaling our msg
Expand All @@ -180,18 +179,6 @@ func TestMsgTemplating(t *testing.T) {
"uuid":"61602f3e-f603-4c70-8a8f-c477505bf4bf"
},
"namespace":"0162a7f4_dfe4_4c96_be07_854d5dba3b2b",
"params": {
"body": [
{
"type": "text",
"value": "Ryan Lewis"
},
{
"type": "text",
"value": "boy"
}
]
},
"components":[
{
"type": "body",
Expand Down

0 comments on commit 3aa1619

Please sign in to comment.