1
0
mirror of synced 2024-11-25 06:26:03 +03:00

Update template information schema in the message webhook

This commit is contained in:
Pavel 2023-12-28 10:16:51 +03:00 committed by GitHub
commit 7bcf82d114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 124 additions and 34 deletions

View File

@ -499,7 +499,7 @@ func (t *MGClientTest) Test_TextMessages() {
ExternalID: "external_id", ExternalID: "external_id",
Type: MsgTypeText, Type: MsgTypeText,
Text: "hello!", Text: "hello!",
PageLink: "https://example.loca/catalog/1", PageLink: "https://example.loca/catalog/1",
}, },
Originator: OriginatorCustomer, Originator: OriginatorCustomer,
Customer: Customer{ Customer: Customer{

View File

@ -448,14 +448,29 @@ type Suggestion struct {
type TemplateInfo struct { type TemplateInfo struct {
Code string `json:"code"` Code string `json:"code"`
Variables TemplateVariables `json:"variables,omitempty"` Variables TemplateArguments `json:"variables,omitempty"`
} }
type TemplateVariables struct { type TemplateArguments struct {
Header []string `json:"header,omitempty"` Header *TemplateHeaderArguments `json:"header,omitempty"`
Attachments []TemplateAttachment `json:"attachments,omitempty"` Body TemplateBodyArguments `json:"body"`
Body []string `json:"body,omitempty"` Buttons []TemplateButtonArguments `json:"buttons,omitempty"`
Buttons [][]string `json:"buttons,omitempty"` }
type TemplateHeaderArguments struct {
Type string `json:"type"`
Args []string `json:"args,omitempty"` // for type="text" only
Attachments []TemplateAttachment `json:"attachments,omitempty"` // for media templates only
}
type TemplateBodyArguments struct {
Args []string `json:"args"`
}
type TemplateButtonArguments struct {
Type string `json:"type"`
Title string `json:"title"`
Args []string `json:"args,omitempty"`
} }
type TemplateAttachment struct { type TemplateAttachment struct {

View File

@ -173,33 +173,108 @@ func TestTransportErrorResponse(t *testing.T) {
func TestTemplateInfoUnmarshal(t *testing.T) { func TestTemplateInfoUnmarshal(t *testing.T) {
tmplJSON := `{ tmplJSON := `{
"code": "namespace#BABA_JABA#ru", "type": "message_sent",
"variables": { "meta": {
"header": [ "timestamp": 1703686050
"header1", },
"header2" "data": {
], "external_user_id": "79998887766",
"attachments": [ "external_chat_id": "",
{"caption":"test-caption", "id":"550e8400-e29b-41d4-a716-446655440000"} "channel_id": 83,
], "type": "image",
"body": [ "content": "Thank you for your order\n\nYou have placed order No. 8061C in the amount of 17400. We have already started working on it and will soon notify you of a change in status.\n\nStay with us",
"BABA", "quote_external_id": null,
"JABA" "quote_content": null,
], "in_app_id": 999,
"buttons": [ "user": {
["button1"], "id": 222,
[], "first_name": "Alex",
["button2"] "last_name": "",
] "avatar": ""
} },
}` "customer": {
"first_name": "",
"last_name": "",
"avatar": ""
},
"items": [
{
"id": "aa4ff988-bafb-43a0-9551-b8e00f677e34",
"size": 71984,
"caption": "test.png",
"height": 742,
"width": 305
}
],
"template": {
"code": "namespace#BABA_JABA#ru",
"args": [
"var0",
"var1"
],
"variables": {
"header": {
"type": "image",
"attachments": [
{
"id": "aa4ff988-bafb-43a0-9551-b8e00f677e34",
"caption": "test.png"
}
]
},
"body": {
"args": [
"var0",
"var1"
]
},
"buttons": [
{
"type": "plain",
"title": "OK"
},
{
"type": "url",
"title": "Our site",
"args": [
"id0"
]
},
{
"type": "phone",
"title": "Our phone"
}
]
}
}
}
}`
var tmpl TemplateInfo var wh struct {
assert.NoError(t, json.Unmarshal([]byte(tmplJSON), &tmpl)) Data struct {
Template TemplateInfo `json:"template"`
} `json:"data"`
}
assert.NoError(t, json.Unmarshal([]byte(tmplJSON), &wh))
tmpl := wh.Data.Template
assert.Equal(t, "namespace#BABA_JABA#ru", tmpl.Code) assert.Equal(t, "namespace#BABA_JABA#ru", tmpl.Code)
assert.Equal(t, []string{"header1", "header2"}, tmpl.Variables.Header)
assert.Equal(t, "550e8400-e29b-41d4-a716-446655440000", tmpl.Variables.Attachments[0].ID) assert.NotNil(t, tmpl.Variables.Header)
assert.Equal(t, "test-caption", tmpl.Variables.Attachments[0].Caption) assert.Empty(t, tmpl.Variables.Header.Args)
assert.Equal(t, []string{"BABA", "JABA"}, tmpl.Variables.Body) assert.Equal(t, "aa4ff988-bafb-43a0-9551-b8e00f677e34", tmpl.Variables.Header.Attachments[0].ID)
assert.Equal(t, [][]string{{"button1"}, {}, {"button2"}}, tmpl.Variables.Buttons) assert.Equal(t, "test.png", tmpl.Variables.Header.Attachments[0].Caption)
assert.Equal(t, []string{"var0", "var1"}, tmpl.Variables.Body.Args)
assert.Len(t, tmpl.Variables.Buttons, 3)
assert.Equal(t, "plain", tmpl.Variables.Buttons[0].Type)
assert.Equal(t, "OK", tmpl.Variables.Buttons[0].Title)
assert.Empty(t, tmpl.Variables.Buttons[0].Args)
assert.Equal(t, "url", tmpl.Variables.Buttons[1].Type)
assert.Equal(t, "Our site", tmpl.Variables.Buttons[1].Title)
assert.Equal(t, []string{"id0"}, tmpl.Variables.Buttons[1].Args)
assert.Equal(t, "phone", tmpl.Variables.Buttons[2].Type)
assert.Equal(t, "Our phone", tmpl.Variables.Buttons[2].Title)
assert.Empty(t, tmpl.Variables.Buttons[2].Args)
} }