-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage.go
85 lines (75 loc) · 2.55 KB
/
message.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
package rc
import (
"time"
)
type msgEnv struct {
Message Message `json:"message"`
Success bool `json:"success"`
}
type Message struct {
Alias string `json:"alias,omitempty"`
Avatar string `json:"avatar,omitempty"`
Channel string `json:"channel,omitempty"`
Emoji string `json:"emoji,omitempty"`
RoomID string `json:"room_id,omitempty"`
Text string `json:"text,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
}
type Attachment struct {
AudioURL string `json:"audio_url,omitempty"`
AuthorName string `json:"author_name,omitempty"`
AuthorLink string `json:"author_link,omitempty"`
AuthorIcon string `json:"author_icon,omitempty"`
Collapsed bool `json:"collapsed,omitempty"`
Color string `json:"color,omitempty"`
Fields []Field `json:"fields,omitempty"`
ImageURL string `json:"image_url,omitempty"`
MessageLink string `json:"message_link,omitempty"`
Text string `json:"text,omitempty"`
ThumbURL string `json:"thumb_url,omitempty"`
Title string `json:"title,omitempty"`
TitleLink string `json:"title_link,omitempty"`
TitleLinkDownload bool `json:"title_link_download,omitempty"`
Timestamp time.Time `json:"ts,omitempty"`
VideoURL string `json:"video_url,omitempty"`
}
type Field struct {
Title string `json:"title"`
Value string `json:"value"`
Short bool `json:"short"`
}
// Generated by https://quicktype.io
type MessageResult struct {
Message Message `json:"message"`
Success bool `json:"success"`
}
type MessageInfo struct {
Rid string `json:"rid"`
Msg string `json:"msg"`
Ts string `json:"ts"`
User User `json:"u"`
Unread bool `json:"unread"`
Mentions []interface{} `json:"mentions"`
Channels []interface{} `json:"channels"`
UpdatedAt string `json:"_updatedAt"`
ID string `json:"_id"`
}
func (c *Client) GetMessage(msgID string) (*MessageResult, error) {
msg := &MessageResult{}
q := query("msgId", msgID)
if err := c.c.get("chat.getMessage", q.Q()).JSON(msg); err != nil {
return nil, err
}
return msg, nil
}
func (c *Client) SendMessage(msg Message) (*MessageResult, error) {
res := c.c.postJSON("/chat.sendMessage", msg)
if res.Error() != nil {
return nil, res.Error()
}
mres := &MessageResult{}
if err := res.JSON(mres); err != nil {
return nil, err
}
return mres, nil
}