Merge branch 'master' into add_lang_template_fields
This commit is contained in:
commit
56999eeff6
@ -8,11 +8,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const MB = 1 << 20
|
const MB = 1 << 20
|
||||||
|
const LimitResponse = 3 * MB
|
||||||
|
|
||||||
func buildLimitedRawResponse(resp *http.Response) ([]byte, error) {
|
func buildLimitedRawResponse(resp *http.Response) ([]byte, error) {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
limitReader := io.LimitReader(resp.Body, MB)
|
limitReader := io.LimitReader(resp.Body, LimitResponse)
|
||||||
body, err := ioutil.ReadAll(limitReader)
|
body, err := ioutil.ReadAll(limitReader)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -37,14 +37,17 @@ var templateVarAssoc = map[string]interface{}{
|
|||||||
|
|
||||||
// Template struct.
|
// Template struct.
|
||||||
type Template struct {
|
type Template struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
ChannelID uint64 `json:"channel_id,omitempty"`
|
ChannelID uint64 `json:"channel_id,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
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"`
|
||||||
Lang string `json:"lang,omitempty"`
|
HeaderParams *HeaderParams `json:"headerParams,omitempty"`
|
||||||
Category string `json:"category,omitempty"`
|
Footer *string `json:"footer,omitempty"`
|
||||||
|
ButtonParams []ButtonParam `json:"buttonParams,omitempty"`
|
||||||
|
Lang string `json:"lang,omitempty"`
|
||||||
|
Category string `json:"category,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)
|
||||||
|
}
|
||||||
|
50
v1/types.go
50
v1/types.go
@ -146,14 +146,16 @@ type ChannelSettingsFilesBase struct {
|
|||||||
Deleting string `json:"deleting,omitempty"`
|
Deleting string `json:"deleting,omitempty"`
|
||||||
Max uint64 `json:"max_items_count,omitempty"`
|
Max uint64 `json:"max_items_count,omitempty"`
|
||||||
NoteMaxCharsCount *uint16 `json:"note_max_chars_count,omitempty"`
|
NoteMaxCharsCount *uint16 `json:"note_max_chars_count,omitempty"`
|
||||||
|
MaxItemSize *uint64 `json:"max_item_size,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChannelSettingsAudio struct.
|
// ChannelSettingsAudio struct.
|
||||||
type ChannelSettingsAudio struct {
|
type ChannelSettingsAudio struct {
|
||||||
Creating string `json:"creating,omitempty"`
|
Creating string `json:"creating,omitempty"`
|
||||||
Quoting string `json:"quoting,omitempty"`
|
Quoting string `json:"quoting,omitempty"`
|
||||||
Deleting string `json:"deleting,omitempty"`
|
Deleting string `json:"deleting,omitempty"`
|
||||||
MaxItemsCount uint64 `json:"max_items_count,omitempty"`
|
MaxItemsCount uint64 `json:"max_items_count,omitempty"`
|
||||||
|
MaxItemSize *uint64 `json:"max_item_size,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SendingPolicy struct {
|
type SendingPolicy struct {
|
||||||
@ -170,10 +172,11 @@ type ChannelSettingsSuggestions struct {
|
|||||||
|
|
||||||
// FullFileResponse uploaded file data.
|
// FullFileResponse uploaded file data.
|
||||||
type FullFileResponse struct {
|
type FullFileResponse struct {
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
Size int `json:"size,omitempty"`
|
Size int `json:"size,omitempty"`
|
||||||
Url string `json:"url,omitempty"`
|
Url string `json:"url,omitempty"` //nolint:golint
|
||||||
|
MimeType string `json:"mime_type,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UploadFileResponse uploaded file data.
|
// UploadFileResponse uploaded file data.
|
||||||
@ -444,8 +447,14 @@ type Suggestion struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TemplateInfo struct {
|
type TemplateInfo struct {
|
||||||
Code string `json:"code,omitempty"`
|
Code string `json:"code"`
|
||||||
Args []string `json:"args,omitempty"`
|
Name string `json:"name"`
|
||||||
|
Namespace string `json:"namespace"`
|
||||||
|
Lang string `json:"lang"`
|
||||||
|
HeaderParams *HeaderParams `json:"headerParams,omitempty"`
|
||||||
|
Footer string `json:"footer,omitempty"`
|
||||||
|
ButtonParams []ButtonParam `json:"buttonParams,omitempty"`
|
||||||
|
Args []string `json:"args,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileItem struct.
|
// FileItem struct.
|
||||||
@ -629,3 +638,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"`
|
||||||
|
}
|
||||||
|
@ -170,3 +170,43 @@ func TestTransportErrorResponse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTemplateInfoUnmarshal(t *testing.T) {
|
||||||
|
tmplJSON := `{
|
||||||
|
"code": "namespace#BABA_JABA#ru",
|
||||||
|
"name": "BABA_JABA",
|
||||||
|
"lang": "ru",
|
||||||
|
"namespace": "namespace",
|
||||||
|
"args": ["BABA", "JABA"],
|
||||||
|
"headerParams": {
|
||||||
|
"textVars": ["Hey", "Jony"],
|
||||||
|
"imageUrl": "https://example.com/intaro/ddd22",
|
||||||
|
"videoUrl": "https://example.com/intaro/ddd23",
|
||||||
|
"documentUrl": "https://example.com/intaro/ddd24"
|
||||||
|
},
|
||||||
|
"footer": "Scooter",
|
||||||
|
"buttonParams": [
|
||||||
|
{
|
||||||
|
"urlParameter": "ququq",
|
||||||
|
"type": "URL",
|
||||||
|
"text": "CHUCHUH"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}`
|
||||||
|
|
||||||
|
var tmpl TemplateInfo
|
||||||
|
assert.NoError(t, json.Unmarshal([]byte(tmplJSON), &tmpl))
|
||||||
|
assert.Equal(t, "namespace#BABA_JABA#ru", tmpl.Code)
|
||||||
|
assert.Equal(t, "namespace", tmpl.Namespace)
|
||||||
|
assert.Equal(t, "BABA_JABA", tmpl.Name)
|
||||||
|
assert.Equal(t, "ru", tmpl.Lang)
|
||||||
|
assert.Equal(t, []string{"BABA", "JABA"}, tmpl.Args)
|
||||||
|
assert.Equal(t, []string{"Hey", "Jony"}, tmpl.HeaderParams.TextVars)
|
||||||
|
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