Added Example field to templates
This commit is contained in:
parent
9f3cda8be6
commit
3cd25ddc88
4 changed files with 50 additions and 22 deletions
|
@ -322,6 +322,11 @@ func (t *MGClientTest) Test_TransportTemplates() {
|
|||
Text: "! We're glad to see you back in our store.",
|
||||
},
|
||||
},
|
||||
Lang: "ru",
|
||||
Category: "marketing",
|
||||
Example: &TemplateExample{Body: []string{"Alex", "Emily"}},
|
||||
RejectionReason: "spam",
|
||||
VerificationStatus: "rejected",
|
||||
},
|
||||
},
|
||||
)
|
||||
|
@ -344,6 +349,12 @@ func (t *MGClientTest) Test_TransportTemplates() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
t.Assert().Equal("ru", item.Lang)
|
||||
t.Assert().Equal("marketing", item.Category)
|
||||
t.Assert().Equal("spam", item.RejectionReason)
|
||||
t.Assert().Equal("rejected", item.VerificationStatus)
|
||||
t.Assert().Equal(&TemplateExample{Body: []string{"Alex", "Emily"}}, item.Example)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -369,6 +380,9 @@ func (t *MGClientTest) Test_ActivateTemplate() {
|
|||
},
|
||||
RejectionReason: "",
|
||||
VerificationStatus: "approved",
|
||||
Example: &TemplateExample{Body: []string{"Alex", "Emily"}},
|
||||
Lang: "en",
|
||||
Category: "marketing",
|
||||
}
|
||||
|
||||
defer gock.Off()
|
||||
|
|
|
@ -37,19 +37,20 @@ var templateVarAssoc = map[string]interface{}{
|
|||
|
||||
// Template struct.
|
||||
type Template struct {
|
||||
Code string `json:"code"`
|
||||
ChannelID uint64 `json:"channel_id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Type string `json:"type"`
|
||||
Template []TemplateItem `json:"template"`
|
||||
HeaderParams *HeaderParams `json:"headerParams,omitempty"`
|
||||
Footer *string `json:"footer,omitempty"`
|
||||
ButtonParams []ButtonParam `json:"buttonParams,omitempty"`
|
||||
Lang string `json:"lang,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
RejectionReason string `json:"rejection_reason,omitempty"`
|
||||
VerificationStatus string `json:"verification_status,omitempty"`
|
||||
Code string `json:"code"`
|
||||
ChannelID uint64 `json:"channel_id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Type string `json:"type"`
|
||||
Template []TemplateItem `json:"template"`
|
||||
HeaderParams *HeaderParams `json:"headerParams,omitempty"`
|
||||
Footer *string `json:"footer,omitempty"`
|
||||
ButtonParams []ButtonParam `json:"buttonParams,omitempty"`
|
||||
Lang string `json:"lang,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
RejectionReason string `json:"rejection_reason,omitempty"`
|
||||
VerificationStatus string `json:"verification_status,omitempty"`
|
||||
Example *TemplateExample `json:"example,omitempty"`
|
||||
}
|
||||
|
||||
// TemplateItem is a part of template.
|
||||
|
@ -59,6 +60,10 @@ type TemplateItem struct {
|
|||
VarType string
|
||||
}
|
||||
|
||||
type TemplateExample struct {
|
||||
Body []string `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// MarshalJSON controls how TemplateItem will be marshaled into JSON.
|
||||
func (t TemplateItem) MarshalJSON() ([]byte, error) {
|
||||
switch t.Type {
|
||||
|
|
|
@ -90,7 +90,13 @@ func TestUnmarshalMediaInteractiveTemplate(t *testing.T) {
|
|||
"text": "Yes"
|
||||
}
|
||||
],
|
||||
"verification_status": "approved"
|
||||
"verification_status": "approved",
|
||||
"example": {
|
||||
"body": [
|
||||
"Alex",
|
||||
"Emily"
|
||||
]
|
||||
}
|
||||
}`
|
||||
assert.NoError(t, json.Unmarshal([]byte(input), &template))
|
||||
|
||||
|
@ -105,6 +111,8 @@ func TestUnmarshalMediaInteractiveTemplate(t *testing.T) {
|
|||
assert.Equal(t, "222ddd", template.ButtonParams[0].URLParameter)
|
||||
assert.Equal(t, QuickReplyButton, template.ButtonParams[1].ButtonType)
|
||||
assert.Equal(t, "Yes", template.ButtonParams[1].Text)
|
||||
assert.NotNil(t, template.Example)
|
||||
assert.Equal(t, &TemplateExample{Body: []string{"Alex", "Emily"}}, template.Example)
|
||||
|
||||
input = `{"footer": "Scooter"}`
|
||||
template = Template{}
|
||||
|
|
17
v1/types.go
17
v1/types.go
|
@ -558,14 +558,15 @@ type TransportRequestMeta struct {
|
|||
}
|
||||
|
||||
type ActivateTemplateRequest struct {
|
||||
Code string `binding:"required,min=1,max=512" json:"code"`
|
||||
Name string `binding:"required,min=1,max=512" json:"name"`
|
||||
Type string `binding:"required" json:"type"`
|
||||
Template []TemplateItem `json:"template"`
|
||||
Lang string `json:"lang,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
RejectionReason string `json:"rejection_reason,omitempty"`
|
||||
VerificationStatus string `json:"verification_status,omitempty"`
|
||||
Code string `binding:"required,min=1,max=512" json:"code"`
|
||||
Name string `binding:"required,min=1,max=512" json:"name"`
|
||||
Type string `binding:"required" json:"type"`
|
||||
Template []TemplateItem `json:"template"`
|
||||
Lang string `json:"lang,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
RejectionReason string `json:"rejection_reason,omitempty"`
|
||||
VerificationStatus string `json:"verification_status,omitempty"`
|
||||
Example *TemplateExample `json:"example,omitempty"`
|
||||
}
|
||||
|
||||
var ErrInvalidOriginator = errors.New("invalid originator")
|
||||
|
|
Loading…
Add table
Reference in a new issue