From 4c5201c4c1b9a53b3ff40ee2d786950c203e5f7c Mon Sep 17 00:00:00 2001 From: Vlasov Date: Thu, 6 Apr 2023 15:01:06 +0300 Subject: [PATCH 1/7] Added MaxItemSize field to channel settings --- v1/types.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/v1/types.go b/v1/types.go index 24c0972..cd2a6f3 100644 --- a/v1/types.go +++ b/v1/types.go @@ -146,14 +146,16 @@ type ChannelSettingsFilesBase struct { Deleting string `json:"deleting,omitempty"` Max uint64 `json:"max_items_count,omitempty"` NoteMaxCharsCount *uint16 `json:"note_max_chars_count,omitempty"` + MaxItemSize *uint64 `json:"max_item_size,omitempty"` } // ChannelSettingsAudio struct. type ChannelSettingsAudio struct { - Creating string `json:"creating,omitempty"` - Quoting string `json:"quoting,omitempty"` - Deleting string `json:"deleting,omitempty"` - MaxItemsCount uint64 `json:"max_items_count,omitempty"` + Creating string `json:"creating,omitempty"` + Quoting string `json:"quoting,omitempty"` + Deleting string `json:"deleting,omitempty"` + MaxItemsCount uint64 `json:"max_items_count,omitempty"` + MaxItemSize *uint64 `json:"max_item_size,omitempty"` } type SendingPolicy struct { From cd953438de2df8e9643df4853435af5cc4680732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D1=84=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=A0=D1=83=D1=81?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD?= Date: Wed, 3 May 2023 10:44:13 +0300 Subject: [PATCH 2/7] increase limit size for response from MG --- v1/helpers.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/v1/helpers.go b/v1/helpers.go index f7f7904..fc1ba4a 100644 --- a/v1/helpers.go +++ b/v1/helpers.go @@ -8,11 +8,12 @@ import ( ) const MB = 1 << 20 +const LimitResponse = 3 * MB func buildLimitedRawResponse(resp *http.Response) ([]byte, error) { defer resp.Body.Close() - limitReader := io.LimitReader(resp.Body, MB) + limitReader := io.LimitReader(resp.Body, LimitResponse) body, err := ioutil.ReadAll(limitReader) if err != nil { From afd5571188e46cdddfa08a6e97118ee9b785e336 Mon Sep 17 00:00:00 2001 From: Ruslan Efanov Date: Tue, 2 May 2023 14:38:03 +0300 Subject: [PATCH 3/7] add models for media and interactive templates --- v1/template.go | 3 +++ v1/template_test.go | 47 +++++++++++++++++++++++++++++++++++++++++++++ v1/types.go | 21 ++++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/v1/template.go b/v1/template.go index 7e37632..2034dd1 100644 --- a/v1/template.go +++ b/v1/template.go @@ -43,6 +43,9 @@ type Template struct { Enabled bool `json:"enabled,omitempty"` Type string `json:"type"` 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. diff --git a/v1/template_test.go b/v1/template_test.go index c9d9f26..0ebc8ca 100644 --- a/v1/template_test.go +++ b/v1/template_test.go @@ -63,3 +63,50 @@ func TestTemplateItem_UnmarshalJSON(t *testing.T) { assert.Equal(t, TemplateVarCustom, emptyVariableResult.VarType) 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) +} \ No newline at end of file diff --git a/v1/types.go b/v1/types.go index cd2a6f3..2a907af 100644 --- a/v1/types.go +++ b/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"` +} \ No newline at end of file From d2d285b3b24e421c812c0d2bdc3bffea21f5c07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D1=84=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=A0=D1=83=D1=81?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD?= Date: Fri, 5 May 2023 14:58:26 +0300 Subject: [PATCH 4/7] fixed code style --- v1/template.go | 18 +++++++++--------- v1/template_test.go | 2 +- v1/types.go | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/v1/template.go b/v1/template.go index 2034dd1..69b7370 100644 --- a/v1/template.go +++ b/v1/template.go @@ -37,15 +37,15 @@ var templateVarAssoc = map[string]interface{}{ // Template struct. type Template struct { - Code string `json:"code"` - ChannelID uint64 `json:"channel_id,omitempty"` - Name string `json:"name"` - Enabled bool `json:"enabled,omitempty"` - Type string `json:"type"` - Template []TemplateItem `json:"template"` - HeaderParams *HeaderParams `json:"headerParams,omitempty"` - Footer *string `json:"footer,omitempty"` - ButtonParams []ButtonParam `json:"buttonParams,omitempty"` + Code string `json:"code"` + ChannelID uint64 `json:"channel_id,omitempty"` + Name string `json:"name"` + Enabled bool `json:"enabled,omitempty"` + Type string `json:"type"` + 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. diff --git a/v1/template_test.go b/v1/template_test.go index 0ebc8ca..7303b8d 100644 --- a/v1/template_test.go +++ b/v1/template_test.go @@ -109,4 +109,4 @@ func TestUnmarshalMediaInteractiveTemplate(t *testing.T) { assert.NoError(t, json.Unmarshal([]byte(input), &template)) assert.Nil(t, template.HeaderParams) assert.Empty(t, template.ButtonParams) -} \ No newline at end of file +} diff --git a/v1/types.go b/v1/types.go index 2a907af..bb11a14 100644 --- a/v1/types.go +++ b/v1/types.go @@ -649,4 +649,4 @@ type ButtonParam struct { ButtonType ButtonType `json:"type"` Text string `json:"text,omitempty"` URLParameter string `json:"urlParameter,omitempty"` -} \ No newline at end of file +} From f586e58a3c9dd346e825b33dbf533d29e9027fd3 Mon Sep 17 00:00:00 2001 From: Ruslan Efanov Date: Thu, 29 Jun 2023 13:36:30 +0300 Subject: [PATCH 5/7] add field in model --- v1/types.go | 1 + 1 file changed, 1 insertion(+) diff --git a/v1/types.go b/v1/types.go index bb11a14..b2e3187 100644 --- a/v1/types.go +++ b/v1/types.go @@ -176,6 +176,7 @@ type FullFileResponse struct { Type string `json:"type,omitempty"` Size int `json:"size,omitempty"` Url string `json:"url,omitempty"` + MimeType string `json:"mime_type,omitempty"` } // UploadFileResponse uploaded file data. From 99d0e45ffd20a5ab9c9ca4e032da0be7960fe0ab Mon Sep 17 00:00:00 2001 From: Ruslan Efanov Date: Fri, 30 Jun 2023 16:01:07 +0300 Subject: [PATCH 6/7] add fields in TemplateInfo model for message with template --- v1/types.go | 18 ++++++++++++------ v1/types_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/v1/types.go b/v1/types.go index b2e3187..eb726d2 100644 --- a/v1/types.go +++ b/v1/types.go @@ -172,10 +172,10 @@ type ChannelSettingsSuggestions struct { // FullFileResponse uploaded file data. type FullFileResponse struct { - ID string `json:"id,omitempty"` - Type string `json:"type,omitempty"` - Size int `json:"size,omitempty"` - Url string `json:"url,omitempty"` + ID string `json:"id,omitempty"` + Type string `json:"type,omitempty"` + Size int `json:"size,omitempty"` + URL string `json:"url,omitempty"` MimeType string `json:"mime_type,omitempty"` } @@ -447,8 +447,14 @@ type Suggestion struct { } type TemplateInfo struct { - Code string `json:"code,omitempty"` - Args []string `json:"args,omitempty"` + Code string `json:"code"` + 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. diff --git a/v1/types_test.go b/v1/types_test.go index e504b7e..2d4d7f5 100644 --- a/v1/types_test.go +++ b/v1/types_test.go @@ -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) +} From b3230ea1c57a5ddee2d522394e6be9c50207abf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D1=84=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=A0=D1=83=D1=81?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD?= Date: Mon, 3 Jul 2023 18:02:45 +0300 Subject: [PATCH 7/7] correct field name url --- v1/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v1/types.go b/v1/types.go index eb726d2..3e9359d 100644 --- a/v1/types.go +++ b/v1/types.go @@ -175,7 +175,7 @@ type FullFileResponse struct { ID string `json:"id,omitempty"` Type string `json:"type,omitempty"` Size int `json:"size,omitempty"` - URL string `json:"url,omitempty"` + Url string `json:"url,omitempty"` //nolint:golint MimeType string `json:"mime_type,omitempty"` }