1
0
mirror of synced 2024-11-22 13:06:05 +03:00

improve file and image elem in channel settings struct, minor fixes

This commit is contained in:
DmitryZagorulko 2018-11-13 12:52:01 +03:00
parent 62bbbcade9
commit 21fe8dcaac
2 changed files with 73 additions and 4 deletions

View File

@ -57,6 +57,12 @@ func TestMgClient_ActivateTransportChannel(t *testing.T) {
Creating: ChannelFeatureBoth,
Deleting: ChannelFeatureSend,
},
Image: ChannelSettingsFilesBase{
Creating: ChannelFeatureBoth,
},
File: ChannelSettingsFilesBase{
Creating: ChannelFeatureBoth,
},
},
}
@ -94,6 +100,12 @@ func TestMgClient_ActivateNewTransportChannel(t *testing.T) {
Creating: ChannelFeatureBoth,
Deleting: ChannelFeatureSend,
},
Image: ChannelSettingsFilesBase{
Creating: ChannelFeatureBoth,
},
File: ChannelSettingsFilesBase{
Creating: ChannelFeatureBoth,
},
},
}
@ -143,6 +155,12 @@ func TestMgClient_UpdateTransportChannel(t *testing.T) {
Creating: ChannelFeatureBoth,
Deleting: ChannelFeatureSend,
},
Image: ChannelSettingsFilesBase{
Creating: ChannelFeatureBoth,
},
File: ChannelSettingsFilesBase{
Creating: ChannelFeatureBoth,
},
},
}
@ -155,7 +173,7 @@ func TestMgClient_UpdateTransportChannel(t *testing.T) {
t.Logf("Update selected channel: %v", data.ChannelID)
}
func TestMgClient_Messages(t *testing.T) {
func TestMgClient_TextMessages(t *testing.T) {
c := client()
t.Logf("%v", ext)
@ -187,6 +205,46 @@ func TestMgClient_Messages(t *testing.T) {
t.Logf("Message %v is sent", data.MessageID)
}
func TestMgClient_ImageMessages(t *testing.T) {
c := client()
t.Logf("%v", ext)
uploadFileResponse, st, err := c.UploadFileByURL(UploadFileByUrlRequest{
Url: "https://via.placeholder.com/300",
})
if st != http.StatusOK {
t.Errorf("%v", err)
}
snd := SendData{
Message: Message{
ExternalID: ext,
Type: MsgTypeImage,
Items: []Item{{ID: uploadFileResponse.ID}},
},
User: User{
ExternalID: "6",
Nickname: "octopus",
Firstname: "Joe",
},
Channel: channelID,
ExternalChatID: "24798237492374",
}
data, status, err := c.Messages(snd)
if status != http.StatusOK {
t.Errorf("%v", err)
}
if data.Time.String() == "" {
t.Errorf("%v", err)
}
t.Logf("Message %v is sent", data.MessageID)
}
func TestMgClient_UpdateMessages(t *testing.T) {
c := client()
t.Logf("%v", ext)

View File

@ -26,6 +26,10 @@ const (
MsgTypeOrder string = "order"
// MsgTypeProduct product card
MsgTypeProduct string = "product"
// MsgTypeFile file card
MsgTypeFile string = "file"
// MsgTypeImage image card
MsgTypeImage string = "image"
// MsgOrderStatusCodeNew order status group new
MsgOrderStatusCodeNew = "new"
@ -66,8 +70,8 @@ type ChannelSettings struct {
Text ChannelSettingsText `json:"text"`
Product Product `json:"product"`
Order Order `json:"order"`
Files ChannelSettingsFilesBase `json:"files"`
Images ChannelSettingsFilesBase `json:"images"`
File ChannelSettingsFilesBase `json:"file"`
Image ChannelSettingsFilesBase `json:"image"`
}
// Product type
@ -115,7 +119,7 @@ type FullFileResponse struct {
// UploadFileResponse uploaded file data
type UploadFileResponse struct {
ID []byte `json:"id"`
ID string `json:"id"`
Hash string `json:"hash"`
Type string `json:"type"`
Meta FileMeta `json:"meta"`
@ -198,6 +202,7 @@ type Message struct {
ExternalID string `json:"external_id"`
Type string `json:"type,omitempty"`
Text string `json:"text,omitempty"`
Items []Item `json:"items,omitempty"`
}
// SendMessage struct
@ -228,6 +233,12 @@ type SendData struct {
Quote *SendMessageRequestQuote `json:"quote,omitempty"`
}
// Item struct
type Item struct {
ID string `json:"id"`
Caption string `json:"caption"`
}
// SendMessageRequestQuote type
type SendMessageRequestQuote struct {
ExternalID string `json:"external_id"`