From 8091fd6d2bf00a02faac38159a972896b44a66b4 Mon Sep 17 00:00:00 2001 From: Sarthak Date: Wed, 20 Nov 2024 11:50:31 +0530 Subject: [PATCH] fix: template message config params (#6) --- go.mod | 2 +- go.sum | 2 ++ pkg/components/template_message.go | 28 +++++++++++++++++++++------- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index b9ce656..8a72093 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 5935f1f..60f5dc1 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/components/template_message.go b/pkg/components/template_message.go index d6b9d74..d6b133d 100644 --- a/pkg/components/template_message.go +++ b/pkg/components/template_message.go @@ -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. } @@ -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.