Add Variables
field to the TemplateInfo
struct
This commit is contained in:
parent
edc20d1e9a
commit
bf27310b25
22
v1/types.go
22
v1/types.go
@ -447,14 +447,20 @@ type Suggestion struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TemplateInfo struct {
|
type TemplateInfo struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Name string `json:"name"`
|
Variables TemplateVariables `json:"variables,omitempty"`
|
||||||
Namespace string `json:"namespace"`
|
}
|
||||||
Lang string `json:"lang"`
|
|
||||||
HeaderParams *HeaderParams `json:"headerParams,omitempty"`
|
type TemplateVariables struct {
|
||||||
Footer string `json:"footer,omitempty"`
|
Header []string `json:"header,omitempty"`
|
||||||
ButtonParams []ButtonParam `json:"buttonParams,omitempty"`
|
Attachments []TemplateAttachment `json:"attachments,omitempty"`
|
||||||
Args []string `json:"args,omitempty"`
|
Body []string `json:"body,omitempty"`
|
||||||
|
Buttons [][]string `json:"buttons,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TemplateAttachment struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Caption string `json:"caption"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileItem struct.
|
// FileItem struct.
|
||||||
|
@ -174,39 +174,32 @@ func TestTransportErrorResponse(t *testing.T) {
|
|||||||
func TestTemplateInfoUnmarshal(t *testing.T) {
|
func TestTemplateInfoUnmarshal(t *testing.T) {
|
||||||
tmplJSON := `{
|
tmplJSON := `{
|
||||||
"code": "namespace#BABA_JABA#ru",
|
"code": "namespace#BABA_JABA#ru",
|
||||||
"name": "BABA_JABA",
|
"variables": {
|
||||||
"lang": "ru",
|
"header": [
|
||||||
"namespace": "namespace",
|
"header1",
|
||||||
"args": ["BABA", "JABA"],
|
"header2"
|
||||||
"headerParams": {
|
],
|
||||||
"textVars": ["Hey", "Jony"],
|
"attachments": [
|
||||||
"imageUrl": "https://example.com/intaro/ddd22",
|
{"caption":"test-caption", "id":"550e8400-e29b-41d4-a716-446655440000"}
|
||||||
"videoUrl": "https://example.com/intaro/ddd23",
|
],
|
||||||
"documentUrl": "https://example.com/intaro/ddd24"
|
"body": [
|
||||||
},
|
"BABA",
|
||||||
"footer": "Scooter",
|
"JABA"
|
||||||
"buttonParams": [
|
],
|
||||||
{
|
"buttons": [
|
||||||
"urlParameter": "ququq",
|
["button1"],
|
||||||
"type": "URL",
|
[],
|
||||||
"text": "CHUCHUH"
|
["button2"]
|
||||||
}
|
]
|
||||||
]
|
}
|
||||||
}`
|
}`
|
||||||
|
|
||||||
var tmpl TemplateInfo
|
var tmpl TemplateInfo
|
||||||
assert.NoError(t, json.Unmarshal([]byte(tmplJSON), &tmpl))
|
assert.NoError(t, json.Unmarshal([]byte(tmplJSON), &tmpl))
|
||||||
assert.Equal(t, "namespace#BABA_JABA#ru", tmpl.Code)
|
assert.Equal(t, "namespace#BABA_JABA#ru", tmpl.Code)
|
||||||
assert.Equal(t, "namespace", tmpl.Namespace)
|
assert.Equal(t, []string{"header1", "header2"}, tmpl.Variables.Header)
|
||||||
assert.Equal(t, "BABA_JABA", tmpl.Name)
|
assert.Equal(t, "550e8400-e29b-41d4-a716-446655440000", tmpl.Variables.Attachments[0].ID)
|
||||||
assert.Equal(t, "ru", tmpl.Lang)
|
assert.Equal(t, "test-caption", tmpl.Variables.Attachments[0].Caption)
|
||||||
assert.Equal(t, []string{"BABA", "JABA"}, tmpl.Args)
|
assert.Equal(t, []string{"BABA", "JABA"}, tmpl.Variables.Body)
|
||||||
assert.Equal(t, []string{"Hey", "Jony"}, tmpl.HeaderParams.TextVars)
|
assert.Equal(t, [][]string{{"button1"}, {}, {"button2"}}, tmpl.Variables.Buttons)
|
||||||
assert.Equal(t, "https://example.com/intaro/ddd22", tmpl.HeaderParams.ImageURL)
|
|
||||||
assert.Equal(t, "https://example.com/intaro/ddd23", tmpl.HeaderParams.VideoURL)
|
|
||||||
assert.Equal(t, "https://example.com/intaro/ddd24", tmpl.HeaderParams.DocumentURL)
|
|
||||||
assert.Equal(t, "Scooter", tmpl.Footer)
|
|
||||||
assert.Equal(t, "URL", string(tmpl.ButtonParams[0].ButtonType))
|
|
||||||
assert.Equal(t, "ququq", tmpl.ButtonParams[0].URLParameter)
|
|
||||||
assert.Equal(t, "CHUCHUH", tmpl.ButtonParams[0].Text)
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user