Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added attachments field to template model #106

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions v1/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ type Template struct {
}

type TemplateExample struct {
Body []string `json:"body,omitempty"`
Header []string `json:"header,omitempty"`
Buttons [][]string `json:"buttons,omitempty"`
Body []string `json:"body,omitempty"`
Header []string `json:"header,omitempty"`
Buttons [][]string `json:"buttons,omitempty"`
Attachments []TemplateExampleAttachment `json:"attachments,omitempty"`
}

type TemplateButtons struct {
Expand Down Expand Up @@ -353,3 +354,8 @@ func (t *TemplateItem) UnmarshalJSON(b []byte) error {

return nil
}

type TemplateExampleAttachment struct {
ID string `json:"id"`
Caption string `json:"caption"`
}
66 changes: 66 additions & 0 deletions v1/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,69 @@ func TestUnmarshalInteractiveTemplate_VideoHeader(t *testing.T) {
assert.Nil(t, template.Header)
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)
}
Loading