Skip to content

Commit

Permalink
Rename TemplateParam to ComponentVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Jan 17, 2024
1 parent 25d01c8 commit a388b6d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions flows/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ func (m *MsgOut) Locale() i18n.Locale { return m.Locale_ }
// UnsendableReason returns the reason this message can't be sent (if any)
func (m *MsgOut) UnsendableReason() UnsendableReason { return m.UnsendableReason_ }

type TemplateParam struct {
type ComponentVariable struct {
Type string `json:"type"`
Value string `json:"value"`
}

// 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][]TemplateParam `json:"params,omitempty"`
Namespace_ string `json:"namespace"`
Template_ *assets.TemplateReference `json:"template"`
Params_ map[string][]ComponentVariable `json:"params,omitempty"`
Namespace_ string `json:"namespace"`
}

// Template returns the template this msg template is for
Expand All @@ -187,15 +187,15 @@ func (t MsgTemplating) Template() *assets.TemplateReference { return t.Template_
func (t MsgTemplating) Namespace() string { return t.Namespace_ }

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

// NewMsgTemplating creates and returns a new msg template
func NewMsgTemplating(template *assets.TemplateReference, variables []string, namespace string) *MsgTemplating {
params := map[string][]TemplateParam{}
params := map[string][]ComponentVariable{}
if len(variables) > 0 {
params = map[string][]TemplateParam{"body": make([]TemplateParam, len(variables))}
params = map[string][]ComponentVariable{"body": make([]ComponentVariable, len(variables))}
for i, v := range variables {
params["body"][i] = TemplateParam{Type: "text", Value: v}
params["body"][i] = ComponentVariable{Type: "text", Value: v}
}
}

Expand Down
2 changes: 1 addition & 1 deletion flows/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestMsgTemplating(t *testing.T) {

assert.Equal(t, templateRef, msgTemplating.Template())
assert.Equal(t, "0162a7f4_dfe4_4c96_be07_854d5dba3b2b", msgTemplating.Namespace())
assert.Equal(t, map[string][]flows.TemplateParam{"body": {{Type: "text", Value: "Ryan Lewis"}, {Type: "text", Value: "boy"}}}, msgTemplating.Params())
assert.Equal(t, map[string][]flows.ComponentVariable{"body": {{Type: "text", Value: "Ryan Lewis"}, {Type: "text", Value: "boy"}}}, msgTemplating.Params())

// test marshaling our msg
marshaled, err := jsonx.Marshal(msgTemplating)
Expand Down

0 comments on commit a388b6d

Please sign in to comment.