fix for template api methods

This commit is contained in:
Pavel 2023-05-29 15:08:31 +03:00 committed by GitHub
commit 076ce77bdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 3 deletions

View File

@ -6563,12 +6563,20 @@ func (c *Client) EditMGChannelTemplate(req EditMGChannelTemplateRequest) (int, e
return 0, err
}
if string(templates) == "null" {
templates = []byte(`[]`)
}
removed, err := json.Marshal(req.Removed)
if err != nil {
return 0, err
}
if string(removed) == "null" {
removed = []byte(`[]`)
}
values := url.Values{
"templates": {string(templates)},
"removed": {string(removed)},

View File

@ -7896,4 +7896,19 @@ func TestClient_EditMGChannelTemplate(t *testing.T) {
code, err := client().EditMGChannelTemplate(request)
assert.NoError(t, err)
assert.True(t, statuses[code])
reqValue = url.Values{
"templates": {tmplsJSON},
"removed": {"[]"},
}
gock.New(crmURL).
Post("reference/mg-channels/templates/edit").
Body(strings.NewReader(reqValue.Encode())).
Reply(http.StatusOK)
request = EditMGChannelTemplateRequest{Templates: tmpls}
code, err = client().EditMGChannelTemplate(request)
assert.NoError(t, err)
assert.True(t, statuses[code])
}

View File

@ -517,5 +517,5 @@ func getMGTemplatesResponse() string {
}
func getMGTemplatesForEdit() string {
return `[{"header":{"text":{"parts":["Hello,",{"var":"custom"}],"example":["Henry"]},"document":{"example":"https://example.com/file/123.pdf"},"image":{"example":"https://example.com/file/123.png"},"video":{"example":"https://example.com/file/123.mp4"}},"lang":"en","category":"test_0","code":"namespace#name_0#ru","name":"name_0","namespace":"namespace","footer":"footer_0","verificationStatus":"REJECTED","template":["Text_0",{"var":"custom"}],"templateExample":["WIU"],"buttons":[{"type":"PHONE_NUMBER","text":"your-phone-button-text","phoneNumber":"+79895553535"},{"type":"QUICK_REPLY","text":"Yes"},{"type":"URL","url":"https://example.com/file/{{1}}","text":"button","example":["https://www.website.com/dynamic-url-example"]}],"channel":{"type":"fbmessenger","name":"JABAAAAAAAAAA","id":1,"externalId":1,"allowedSendByPhone":false,"active":true},"id":1,"externalId":10,"active":true}]`
return `[{"header":{"text":{"parts":["Hello,",{"var":"custom"}],"example":["Henry"]},"document":{"example":"https://example.com/file/123.pdf"},"image":{"example":"https://example.com/file/123.png"},"video":{"example":"https://example.com/file/123.mp4"}},"lang":"en","category":"test_0","code":"namespace#name_0#ru","name":"name_0","namespace":"namespace","footer":"footer_0","verificationStatus":"REJECTED","template":["Text_0",{"var":"custom"}],"buttons":[{"type":"PHONE_NUMBER","text":"your-phone-button-text","phoneNumber":"+79895553535"},{"type":"QUICK_REPLY","text":"Yes"},{"type":"URL","url":"https://example.com/file/{{1}}","text":"button","example":["https://www.website.com/dynamic-url-example"]}],"templateExample":["WIU"],"id":1,"externalId":10,"mgChannelId":110,"active":true}]`
}

View File

@ -1474,6 +1474,7 @@ type MGChannel struct {
}
type MGChannelTemplate struct {
Channel *MGChannel `json:"channel,omitempty"`
Header *Header `json:"header"`
Lang string `json:"lang"`
Category string `json:"category"`
@ -1483,10 +1484,10 @@ type MGChannelTemplate struct {
Footer string `json:"footer,omitempty"`
VerificationStatus string `json:"verificationStatus,omitempty"`
BodyTemplate TemplateItemList `json:"template"`
BodyTemplateExample []string `json:"templateExample"`
Buttons []Button `json:"buttons,omitempty"`
Channel MGChannel `json:"channel"`
BodyTemplateExample []string `json:"templateExample"`
ID int `json:"id,omitempty"`
ExternalID int `json:"externalId,omitempty"`
MGChannelID int `json:"mgChannelId"`
Active bool `json:"active"`
}