Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace relying on variables to generate new templating #1205

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion flows/actions/send_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,18 @@ func (a *SendMsgAction) Execute(run flows.Run, step flows.Step, logModifier flow
}

evaluatedText = translation.Substitute(evaluatedVariables)
templating = flows.NewMsgTemplating(a.Templating.Template, evaluatedVariables, translation.Namespace())

params := make(map[string][]flows.TemplateParam, 1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moved building the params here and pass that to the flows.NewMsgTemplating instead of passing a list of variables


// TODO add support for params in other components besides body
if len(evaluatedVariables) > 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here is the right place since we can have access to the param types in the template translations once we support other components and parameter types

params["body"] = make([]flows.TemplateParam, len(evaluatedVariables))
for i, v := range evaluatedVariables {
params["body"][i] = flows.TemplateParam{Type: "text", Value: v}
}
}

templating = flows.NewMsgTemplating(a.Templating.Template, params, translation.Namespace())
locale = translation.Locale()
}
}
Expand Down
11 changes: 1 addition & 10 deletions flows/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,7 @@ func (t MsgTemplating) Namespace() string { return t.Namespace_ }
func (t MsgTemplating) Params() map[string][]TemplateParam { return t.Params_ }

// NewMsgTemplating creates and returns a new msg template
func NewMsgTemplating(template *assets.TemplateReference, variables []string, namespace string) *MsgTemplating {
params := make(map[string][]TemplateParam, 1)

// TODO add support for params in other components besides body
if len(variables) > 0 {
params["body"] = make([]TemplateParam, len(variables))
for i, v := range variables {
params["body"][i] = TemplateParam{Type: "text", Value: v}
}
}
func NewMsgTemplating(template *assets.TemplateReference, params map[string][]TemplateParam, namespace string) *MsgTemplating {

return &MsgTemplating{Template_: template, Namespace_: namespace, Params_: params}
}
Expand Down
2 changes: 1 addition & 1 deletion flows/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestMsgTemplating(t *testing.T) {

templateRef := assets.NewTemplateReference("61602f3e-f603-4c70-8a8f-c477505bf4bf", "Affirmation")

msgTemplating := flows.NewMsgTemplating(templateRef, []string{"Ryan Lewis", "boy"}, "0162a7f4_dfe4_4c96_be07_854d5dba3b2b")
msgTemplating := flows.NewMsgTemplating(templateRef, map[string][]flows.TemplateParam{"body": {{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())
Expand Down
Loading