Skip to content

Commit

Permalink
fix: template message config params (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthakjdev authored Nov 20, 2024
1 parent e75734f commit 8091fd6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/sarthakjdev/wapi.go
go 1.21.3

require (
github.com/go-playground/validator/v10 v10.22.1
github.com/go-playground/validator/v10 v10.23.0
github.com/labstack/echo/v4 v4.12.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-playground/validator/v10 v10.23.0 h1:/PwmTwZhS0dPkav3cdK9kV1FsAmrL8sThn8IHr/sO+o=
github.com/go-playground/validator/v10 v10.23.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0=
github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
Expand Down
28 changes: 21 additions & 7 deletions pkg/components/template_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@ func (t TemplateMessageButtonParameter) GetParameterType() string {
return string(t.Type)
}

type TemplateMessageLanguage struct {
Code string `json:"code" validate:"required"`
Policy string `json:"policy" validate:"required"`
}

// TemplateMessage represents a template message.
type TemplateMessage struct {
Name string `json:"name" validate:"required"` // Name of the template message.
Language struct {
Code string `json:"code" validate:"required"`
Policy string `json:"policy" validate:"required"` // default is "deterministic"
} `json:"language" validate:"required"`
Name string `json:"name" validate:"required"` // Name of the template message.
Language TemplateMessageLanguage `json:"language" validate:"required"`
Components []TemplateMessageComponent `json:"components" validate:"required"` // Components of the template message.
}

Expand All @@ -144,9 +146,21 @@ type TemplateMessageApiPayload struct {
Template TemplateMessage `json:"template" validate:"required"`
}

// TemplateMessageConfigs represents the configurations for a template message.
type TemplateMessageConfigs struct {
Name string `json:"name" validate:"required"` // Name of the template message.
Language string `json:"language" validate:"required"` // Language of the template message.
}

// NewTemplateMessage creates a new instance of TemplateMessage.
func NewTemplateMessage() (*TemplateMessage, error) {
return &TemplateMessage{}, nil
func NewTemplateMessage(params *TemplateMessageConfigs) (*TemplateMessage, error) {
return &TemplateMessage{
Name: params.Name,
Language: TemplateMessageLanguage{
Code: params.Language,
Policy: "deterministic",
},
}, nil
}

// AddHeader adds a header to the template message.
Expand Down

0 comments on commit 8091fd6

Please sign in to comment.