add models for media and interactive templates
This commit is contained in:
parent
f9ebf631ba
commit
afd5571188
@ -43,6 +43,9 @@ type Template struct {
|
|||||||
Enabled bool `json:"enabled,omitempty"`
|
Enabled bool `json:"enabled,omitempty"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Template []TemplateItem `json:"template"`
|
Template []TemplateItem `json:"template"`
|
||||||
|
HeaderParams *HeaderParams `json:"headerParams,omitempty"`
|
||||||
|
Footer *string `json:"footer,omitempty"`
|
||||||
|
ButtonParams []ButtonParam `json:"buttonParams,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TemplateItem is a part of template.
|
// TemplateItem is a part of template.
|
||||||
|
@ -63,3 +63,50 @@ func TestTemplateItem_UnmarshalJSON(t *testing.T) {
|
|||||||
assert.Equal(t, TemplateVarCustom, emptyVariableResult.VarType)
|
assert.Equal(t, TemplateVarCustom, emptyVariableResult.VarType)
|
||||||
assert.Empty(t, emptyVariableResult.Text)
|
assert.Empty(t, emptyVariableResult.Text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnmarshalMediaInteractiveTemplate(t *testing.T) {
|
||||||
|
var template Template
|
||||||
|
input := `{
|
||||||
|
"code":"aaa#bbb#ru",
|
||||||
|
"phone": "79252223456",
|
||||||
|
"channel_id": 1,
|
||||||
|
"headerParams": {
|
||||||
|
"textVars": [
|
||||||
|
"Johny",
|
||||||
|
"1234C"
|
||||||
|
],
|
||||||
|
"imageUrl": "http://example.com/intaro/d2354125",
|
||||||
|
"videoUrl": "http://example.com/intaro/d2222",
|
||||||
|
"documentUrl": "http://example.com/intaro/d4444"
|
||||||
|
},
|
||||||
|
"footer": "Scooter",
|
||||||
|
"buttonParams": [
|
||||||
|
{
|
||||||
|
"type": "URL",
|
||||||
|
"urlParameter": "222ddd"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "QUICK_REPLY",
|
||||||
|
"text": "Yes"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}`
|
||||||
|
assert.NoError(t, json.Unmarshal([]byte(input), &template))
|
||||||
|
|
||||||
|
assert.Equal(t, "aaa#bbb#ru", template.Code)
|
||||||
|
assert.Equal(t, []string{"Johny", "1234C"}, template.HeaderParams.TextVars)
|
||||||
|
assert.Equal(t, "http://example.com/intaro/d2354125", template.HeaderParams.ImageURL)
|
||||||
|
assert.Equal(t, "http://example.com/intaro/d2222", template.HeaderParams.VideoURL)
|
||||||
|
assert.Equal(t, "http://example.com/intaro/d4444", template.HeaderParams.DocumentURL)
|
||||||
|
assert.Equal(t, "Scooter", *template.Footer)
|
||||||
|
assert.Equal(t, URLButton, template.ButtonParams[0].ButtonType)
|
||||||
|
assert.Equal(t, "222ddd", template.ButtonParams[0].URLParameter)
|
||||||
|
assert.Equal(t, QuickReplyButton, template.ButtonParams[1].ButtonType)
|
||||||
|
assert.Equal(t, "Yes", template.ButtonParams[1].Text)
|
||||||
|
|
||||||
|
input = `{"footer": "Scooter"}`
|
||||||
|
template = Template{}
|
||||||
|
assert.NoError(t, json.Unmarshal([]byte(input), &template))
|
||||||
|
assert.Nil(t, template.HeaderParams)
|
||||||
|
assert.Empty(t, template.ButtonParams)
|
||||||
|
}
|
21
v1/types.go
21
v1/types.go
@ -629,3 +629,24 @@ func NewTransportErrorResponse(code TransportErrorCode, message string) Transpor
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HeaderParams struct {
|
||||||
|
TextVars []string `json:"textVars,omitempty"`
|
||||||
|
ImageURL string `json:"imageUrl,omitempty"`
|
||||||
|
VideoURL string `json:"videoUrl,omitempty"`
|
||||||
|
DocumentURL string `json:"documentUrl,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
QuickReplyButton ButtonType = "QUICK_REPLY"
|
||||||
|
PhoneNumberButton ButtonType = "PHONE_NUMBER"
|
||||||
|
URLButton ButtonType = "URL"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ButtonType string
|
||||||
|
|
||||||
|
type ButtonParam struct {
|
||||||
|
ButtonType ButtonType `json:"type"`
|
||||||
|
Text string `json:"text,omitempty"`
|
||||||
|
URLParameter string `json:"urlParameter,omitempty"`
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user