1
0
mirror of synced 2024-11-25 14:36:03 +03:00

Added attachments field to template model

This commit is contained in:
Pavel 2023-12-22 15:45:17 +03:00 committed by GitHub
commit d2dac5c774
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 75 additions and 3 deletions

View File

@ -57,6 +57,7 @@ type TemplateExample struct {
Body []string `json:"body,omitempty"` Body []string `json:"body,omitempty"`
Header []string `json:"header,omitempty"` Header []string `json:"header,omitempty"`
Buttons [][]string `json:"buttons,omitempty"` Buttons [][]string `json:"buttons,omitempty"`
Attachments []TemplateExampleAttachment `json:"attachments,omitempty"`
} }
type TemplateButtons struct { type TemplateButtons struct {
@ -353,3 +354,8 @@ func (t *TemplateItem) UnmarshalJSON(b []byte) error {
return nil return nil
} }
type TemplateExampleAttachment struct {
ID string `json:"id"`
Caption string `json:"caption"`
}

View File

@ -254,3 +254,69 @@ func TestUnmarshalInteractiveTemplate_VideoHeader(t *testing.T) {
assert.Nil(t, template.Header) assert.Nil(t, template.Header)
assert.Empty(t, template.Buttons) assert.Empty(t, template.Buttons)
} }
func TestUnmarshalInteractiveTemplate_Examples(t *testing.T) {
var template Template
input := `{
"code":"aaa#bbb#ru",
"phone": "79252223456",
"channel_id": 1,
"header": {
"content": {
"type": "text",
"body": "Hello, {{1}}!"
}
},
"body": "Order {{1}} successfully delivered",
"buttons": {
"items": [
{
"type": "url",
"label": "Go to website",
"url": "https://test.com/{{1}}"
},
{
"type": "plain",
"label": "OK"
}
]
},
"verification_status": "approved",
"example": {
"header": ["Alex"],
"body": ["ORDER-111"],
"buttons": [["id123"], []]
}
}`
assert.NoError(t, json.Unmarshal([]byte(input), &template))
assert.NotNil(t, template.Example)
assert.Equal(t, []string{"Alex"}, template.Example.Header)
assert.Equal(t, []string{"ORDER-111"}, template.Example.Body)
assert.Equal(t, [][]string{{"id123"}, {}}, template.Example.Buttons)
}
func TestUnmarshalInteractiveTemplate_Attachments(t *testing.T) {
var template Template
input := `{
"code":"aaa#bbb#ru",
"phone": "79252223456",
"channel_id": 1,
"header": {
"content": {
"type": "image"
}
},
"body": "Welcome to new delivery point",
"verification_status": "approved",
"example": {
"attachments": [{"id": "a6cf882e-6915-410a-8672-ed3a28a7875d", "caption": "test-cats.png"}]
}
}`
assert.NoError(t, json.Unmarshal([]byte(input), &template))
assert.NotNil(t, template.Example)
assert.Len(t, template.Example.Attachments, 1)
assert.Equal(t, "a6cf882e-6915-410a-8672-ed3a28a7875d", template.Example.Attachments[0].ID)
assert.Equal(t, "test-cats.png", template.Example.Attachments[0].Caption)
}