1package slack
2
3// OutgoingMessage is used for the realtime API, and seems incomplete.
4type OutgoingMessage struct {
5	ID int `json:"id"`
6	// channel ID
7	Channel         string   `json:"channel,omitempty"`
8	Text            string   `json:"text,omitempty"`
9	Type            string   `json:"type,omitempty"`
10	ThreadTimestamp string   `json:"thread_ts,omitempty"`
11	ThreadBroadcast bool     `json:"reply_broadcast,omitempty"`
12	IDs             []string `json:"ids,omitempty"`
13}
14
15// Message is an auxiliary type to allow us to have a message containing sub messages
16type Message struct {
17	Msg
18	SubMessage      *Msg `json:"message,omitempty"`
19	PreviousMessage *Msg `json:"previous_message,omitempty"`
20}
21
22// Msg contains information about a slack message
23type Msg struct {
24	// Basic Message
25	ClientMsgID     string       `json:"client_msg_id,omitempty"`
26	Type            string       `json:"type,omitempty"`
27	Channel         string       `json:"channel,omitempty"`
28	User            string       `json:"user,omitempty"`
29	Text            string       `json:"text,omitempty"`
30	Timestamp       string       `json:"ts,omitempty"`
31	ThreadTimestamp string       `json:"thread_ts,omitempty"`
32	IsStarred       bool         `json:"is_starred,omitempty"`
33	PinnedTo        []string     `json:"pinned_to,omitempty"`
34	Attachments     []Attachment `json:"attachments,omitempty"`
35	Edited          *Edited      `json:"edited,omitempty"`
36	LastRead        string       `json:"last_read,omitempty"`
37	Subscribed      bool         `json:"subscribed,omitempty"`
38	UnreadCount     int          `json:"unread_count,omitempty"`
39
40	// Message Subtypes
41	SubType string `json:"subtype,omitempty"`
42
43	// Hidden Subtypes
44	Hidden           bool   `json:"hidden,omitempty"`     // message_changed, message_deleted, unpinned_item
45	DeletedTimestamp string `json:"deleted_ts,omitempty"` // message_deleted
46	EventTimestamp   string `json:"event_ts,omitempty"`
47
48	// bot_message (https://api.slack.com/events/message/bot_message)
49	BotID      string      `json:"bot_id,omitempty"`
50	Username   string      `json:"username,omitempty"`
51	Icons      *Icon       `json:"icons,omitempty"`
52	BotProfile *BotProfile `json:"bot_profile,omitempty"`
53
54	// channel_join, group_join
55	Inviter string `json:"inviter,omitempty"`
56
57	// channel_topic, group_topic
58	Topic string `json:"topic,omitempty"`
59
60	// channel_purpose, group_purpose
61	Purpose string `json:"purpose,omitempty"`
62
63	// channel_name, group_name
64	Name    string `json:"name,omitempty"`
65	OldName string `json:"old_name,omitempty"`
66
67	// channel_archive, group_archive
68	Members []string `json:"members,omitempty"`
69
70	// channels.replies, groups.replies, im.replies, mpim.replies
71	ReplyCount   int     `json:"reply_count,omitempty"`
72	Replies      []Reply `json:"replies,omitempty"`
73	ParentUserId string  `json:"parent_user_id,omitempty"`
74
75	// file_share, file_comment, file_mention
76	Files []File `json:"files,omitempty"`
77
78	// file_share
79	Upload bool `json:"upload,omitempty"`
80
81	// file_comment
82	Comment *Comment `json:"comment,omitempty"`
83
84	// pinned_item
85	ItemType string `json:"item_type,omitempty"`
86
87	// https://api.slack.com/rtm
88	ReplyTo int    `json:"reply_to,omitempty"`
89	Team    string `json:"team,omitempty"`
90
91	// reactions
92	Reactions []ItemReaction `json:"reactions,omitempty"`
93
94	// slash commands and interactive messages
95	ResponseType    string `json:"response_type,omitempty"`
96	ReplaceOriginal bool   `json:"replace_original"`
97	DeleteOriginal  bool   `json:"delete_original"`
98
99	// Block type Message
100	Blocks Blocks `json:"blocks,omitempty"`
101}
102
103const (
104	// ResponseTypeInChannel in channel response for slash commands.
105	ResponseTypeInChannel = "in_channel"
106	// ResponseTypeEphemeral ephemeral response for slash commands.
107	ResponseTypeEphemeral = "ephemeral"
108)
109
110// ScheduledMessage contains information about a slack scheduled message
111type ScheduledMessage struct {
112	ID          string `json:"id"`
113	Channel     string `json:"channel_id"`
114	PostAt      int    `json:"post_at"`
115	DateCreated int    `json:"date_created"`
116	Text        string `json:"text"`
117}
118
119// Icon is used for bot messages
120type Icon struct {
121	IconURL   string `json:"icon_url,omitempty"`
122	IconEmoji string `json:"icon_emoji,omitempty"`
123}
124
125// BotProfile contains information about a bot
126type BotProfile struct {
127	AppID   string `json:"app_id,omitempty"`
128	Deleted bool   `json:"deleted,omitempty"`
129	Icons   *Icons `json:"icons,omitempty"`
130	ID      string `json:"id,omitempty"`
131	Name    string `json:"name,omitempty"`
132	TeamID  string `json:"team_id,omitempty"`
133	Updated int64  `json:"updated,omitempty"`
134}
135
136// Edited indicates that a message has been edited.
137type Edited struct {
138	User      string `json:"user,omitempty"`
139	Timestamp string `json:"ts,omitempty"`
140}
141
142// Reply contains information about a reply for a thread
143type Reply struct {
144	User      string `json:"user,omitempty"`
145	Timestamp string `json:"ts,omitempty"`
146}
147
148// Event contains the event type
149type Event struct {
150	Type string `json:"type,omitempty"`
151}
152
153// Ping contains information about a Ping Event
154type Ping struct {
155	ID        int    `json:"id"`
156	Type      string `json:"type"`
157	Timestamp int64  `json:"timestamp"`
158}
159
160// Pong contains information about a Pong Event
161type Pong struct {
162	Type      string `json:"type"`
163	ReplyTo   int    `json:"reply_to"`
164	Timestamp int64  `json:"timestamp"`
165}
166
167// NewOutgoingMessage prepares an OutgoingMessage that the user can
168// use to send a message. Use this function to properly set the
169// messageID.
170func (rtm *RTM) NewOutgoingMessage(text string, channelID string, options ...RTMsgOption) *OutgoingMessage {
171	id := rtm.idGen.Next()
172	msg := OutgoingMessage{
173		ID:      id,
174		Type:    "message",
175		Channel: channelID,
176		Text:    text,
177	}
178	for _, option := range options {
179		option(&msg)
180	}
181	return &msg
182}
183
184// NewSubscribeUserPresence prepares an OutgoingMessage that the user can
185// use to subscribe presence events for the specified users.
186func (rtm *RTM) NewSubscribeUserPresence(ids []string) *OutgoingMessage {
187	return &OutgoingMessage{
188		Type: "presence_sub",
189		IDs:  ids,
190	}
191}
192
193// NewTypingMessage prepares an OutgoingMessage that the user can
194// use to send as a typing indicator. Use this function to properly set the
195// messageID.
196func (rtm *RTM) NewTypingMessage(channelID string) *OutgoingMessage {
197	id := rtm.idGen.Next()
198	return &OutgoingMessage{
199		ID:      id,
200		Type:    "typing",
201		Channel: channelID,
202	}
203}
204
205// RTMsgOption allows configuration of various options available for sending an RTM message
206type RTMsgOption func(*OutgoingMessage)
207
208// RTMsgOptionTS sets thead timestamp of an outgoing message in order to respond to a thread
209func RTMsgOptionTS(threadTimestamp string) RTMsgOption {
210	return func(msg *OutgoingMessage) {
211		msg.ThreadTimestamp = threadTimestamp
212	}
213}
214
215// RTMsgOptionBroadcast sets broadcast reply to channel to "true"
216func RTMsgOptionBroadcast() RTMsgOption {
217	return func(msg *OutgoingMessage) {
218		msg.ThreadBroadcast = true
219	}
220}
221