-
Notifications
You must be signed in to change notification settings - Fork 13
/
messages.go
134 lines (115 loc) · 4.02 KB
/
messages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package mixin
import (
"context"
"encoding/json"
)
const (
MessageCategoryPlainText = "PLAIN_TEXT"
MessageCategoryPlainPost = "PLAIN_POST"
MessageCategoryPlainImage = "PLAIN_IMAGE"
MessageCategoryPlainData = "PLAIN_DATA"
MessageCategoryPlainSticker = "PLAIN_STICKER"
MessageCategoryPlainLive = "PLAIN_LIVE"
MessageCategoryPlainVideo = "PLAIN_VIDEO"
MessageCategoryPlainContact = "PLAIN_CONTACT"
MessageCategoryAppCard = "APP_CARD"
MessageCategoryAppButtonGroup = "APP_BUTTON_GROUP"
MessageCategoryMessageRecall = "MESSAGE_RECALL"
MessageCategorySystemConversation = "SYSTEM_CONVERSATION"
MessageCategorySystemAccountSnapshot = "SYSTEM_ACCOUNT_SNAPSHOT"
MessageStatusSent = "SENT"
MessageStatusRead = "READ"
)
type (
RecallMessage struct {
MessageID string `json:"message_id"`
}
ImageMessage struct {
AttachmentID string `json:"attachment_id,omitempty"`
MimeType string `json:"mime_type,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
Size int `json:"size,omitempty"`
Thumbnail []byte `json:"thumbnail,omitempty"`
}
DataMessage struct {
AttachmentID string `json:"attachment_id,omitempty"`
MimeType string `json:"mime_type,omitempty"`
Size int `json:"size,omitempty"`
Name string `json:"name,omitempty"`
}
StickerMessage struct {
Name string `json:"name,omitempty"`
AlbumID string `json:"album_id,omitempty"`
}
ContactMessage struct {
UserID string `json:"user_id,omitempty"`
}
AppCardMessage struct {
AppID string `json:"app_id,omitempty"`
IconURL string `json:"icon_url,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Action string `json:"action,omitempty"`
}
AudioMessage struct {
AttachmentID string `json:"attachment_id,omitempty"`
MimeType string `json:"mime_type,omitempty"`
WaveForm string `json:"wave_form,omitempty"`
Size int `json:"size,omitempty"`
Duration int `json:"duration,omitempty"`
}
LiveMessage struct {
Width int `json:"width"`
Height int `json:"height"`
ThumbUrl string `json:"thumb_url"`
URL string `json:"url"`
}
VideoMessage struct {
AttachmentID string `json:"attachment_id,omitempty"`
MimeType string `json:"mime_type,omitempty"`
WaveForm string `json:"wave_form,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
Size int `json:"size,omitempty"`
Duration int `json:"duration,omitempty"`
Thumbnail []byte `json:"thumbnail,omitempty"`
}
LocationMessage struct {
Name string `json:"name,omitempty"`
Address string `json:"address,omitempty"`
Longitude float64 `json:"longitude,omitempty"`
Latitude float64 `json:"latitude,omitempty"`
}
AppButtonMessage struct {
Label string `json:"label,omitempty"`
Action string `json:"action,omitempty"`
Color string `json:"color,omitempty"`
}
AppButtonGroupMessage []AppButtonMessage
)
type MessageRequest struct {
ConversationID string `json:"conversation_id"`
RecipientID string `json:"recipient_id"`
MessageID string `json:"message_id"`
Category string `json:"category"`
Data string `json:"data"`
RepresentativeID string `json:"representative_id,omitempty"`
QuoteMessageID string `json:"quote_message_id,omitempty"`
}
func (c *Client) SendMessages(ctx context.Context, messages []*MessageRequest) error {
switch len(messages) {
case 0:
return nil
case 1:
return c.SendMessage(ctx, messages[0])
default:
return c.Post(ctx, "/messages", messages, nil)
}
}
func (c *Client) SendMessage(ctx context.Context, message *MessageRequest) error {
return c.Post(ctx, "/messages", message, nil)
}
func (c *Client) SendRawMessages(ctx context.Context, messages []json.RawMessage) error {
return c.Post(ctx, "/messages", messages, nil)
}