Codebase list golang-github-nlopes-slack / 17d746b
Remove JSONTimeString The Slack API docs explicitly states that their funny timestamps are to be treated as a sort of message IDs and are guaranteed to be unique in the channel. In update and delete calls it is necessary to know the timestamp-string or the call will fail. Client code will use these timestamp-strings for things like checking for duplicate messages. Instead of casting incoming timestamp-strings to (english speaking) human-readable strings like "Sun Jan 31" I think it's wise to let the client do its own formatting and leave the timestamp-strings be. David Palm 8 years ago
8 changed file(s) with 40 addition(s) and 69 deletion(s). Raw diff Collapse all Expand all
33 type ChannelCreatedEvent struct {
44 Type string `json:"type"`
55 Channel ChannelCreatedInfo `json:"channel"`
6 EventTimestamp JSONTimeString `json:"event_ts"`
6 EventTimestamp string `json:"event_ts"`
77 }
88
99 // ChannelCreatedInfo represents the information associated with the Channel created event
2727 // channel_deleted
2828 // channel_archive
2929 // channel_unarchive
30 Type string `json:"type"`
31 Channel string `json:"channel"`
32 User string `json:"user,omitempty"`
33 Timestamp *JSONTimeString `json:"ts,omitempty"`
30 Type string `json:"type"`
31 Channel string `json:"channel"`
32 User string `json:"user,omitempty"`
33 Timestamp string `json:"ts,omitempty"`
3434 }
3535
3636 // ChannelRenameEvent represents the Channel rename event
4242
4343 // ChannelRenameInfo represents the information associated with a Channel rename event
4444 type ChannelRenameInfo struct {
45 ID string `json:"id"`
46 Name string `json:"name"`
47 Created *JSONTimeString `json:"created"`
45 ID string `json:"id"`
46 Name string `json:"name"`
47 Created string `json:"created"`
4848 }
4949
5050 // ChannelHistoryChangedEvent represents the Channel history changed event
5151 type ChannelHistoryChangedEvent struct {
52 Type string `json:"type"`
53 Latest JSONTimeString `json:"latest"`
54 Timestamp JSONTimeString `json:"ts"`
55 EventTimestamp JSONTimeString `json:"event_ts"`
52 Type string `json:"type"`
53 Latest string `json:"latest"`
54 Timestamp string `json:"ts"`
55 EventTimestamp string `json:"event_ts"`
5656 }
5757
5858 // ChannelMarkedEvent represents the Channel marked event
11
22 // FileActionEvent represents the File action event
33 type fileActionEvent struct {
4 Type string `json:"type"`
5 EventTimestamp JSONTimeString `json:"event_ts"`
6 File File `json:"file"`
4 Type string `json:"type"`
5 EventTimestamp string `json:"event_ts"`
6 File File `json:"file"`
77 // FileID is used for FileDeletedEvent
88 FileID string `json:"file_id,omitempty"`
99 }
7575
7676 // EmojiChangedEvent represents the emoji changed event
7777 type EmojiChangedEvent struct {
78 Type string `json:"type"`
79 EventTimestamp JSONTimeString `json:"event_ts"`
78 Type string `json:"type"`
79 EventTimestamp string `json:"event_ts"`
8080 }
8181
8282 // CommandsChangedEvent represents the commands changed event
8383 type CommandsChangedEvent struct {
84 Type string `json:"type"`
85 EventTimestamp JSONTimeString `json:"event_ts"`
84 Type string `json:"type"`
85 EventTimestamp string `json:"event_ts"`
8686 }
8787
8888 // EmailDomainChangedEvent represents the email domain changed event
8989 type EmailDomainChangedEvent struct {
90 Type string `json:"type"`
91 EventTimestamp JSONTimeString `json:"event_ts"`
92 EmailDomain string `json:"email_domain"`
90 Type string `json:"type"`
91 EventTimestamp string `json:"event_ts"`
92 EmailDomain string `json:"email_domain"`
9393 }
9494
9595 // BotAddedEvent represents the bot added event
00 package slack
11
22 type pinEvent struct {
3 Type string `json:"type"`
4 User string `json:"user"`
5 Item Item `json:"item"`
6 Channel string `json:"channel_id"`
7 EventTimestamp JSONTimeString `json:"event_ts"`
8 HasPins bool `json:"has_pins,omitempty"`
3 Type string `json:"type"`
4 User string `json:"user"`
5 Item Item `json:"item"`
6 Channel string `json:"channel_id"`
7 EventTimestamp string `json:"event_ts"`
8 HasPins bool `json:"has_pins,omitempty"`
99 }
1010
1111 // PinAddedEvent represents the Pin added event
00 package slack
11
22 type reactionEvent struct {
3 Type string `json:"type"`
4 User string `json:"user"`
5 Item ReactedItem `json:"item"`
6 Reaction string `json:"reaction"`
7 EventTimestamp JSONTimeString `json:"event_ts"`
3 Type string `json:"type"`
4 User string `json:"user"`
5 Item ReactedItem `json:"item"`
6 Reaction string `json:"reaction"`
7 EventTimestamp string `json:"event_ts"`
88 }
99
1010 // ReactionAddedEvent represents the Reaction added event
00 package slack
11
22 type starEvent struct {
3 Type string `json:"type"`
4 User string `json:"user"`
5 Item StarredItem `json:"item"`
6 EventTimestamp JSONTimeString `json:"event_ts"`
3 Type string `json:"type"`
4 User string `json:"user"`
5 Item StarredItem `json:"item"`
6 EventTimestamp string `json:"event_ts"`
77 }
88
99 // StarAddedEvent represents the Star added event
77
88 // TeamRenameEvent represents the Team rename event
99 type TeamRenameEvent struct {
10 Type string `json:"type"`
11 Name string `json:"name,omitempty"`
12 EventTimestamp *JSONTimeString `json:"event_ts,omitempty"`
10 Type string `json:"type"`
11 Name string `json:"name,omitempty"`
12 EventTimestamp string `json:"event_ts,omitempty"`
1313 }
1414
1515 // TeamPrefChangeEvent represents the Team preference change event
00 package slack
11
22 import (
3 "fmt"
4 "log"
53 "net"
64 "net/url"
7 "strconv"
8 "time"
95 )
10
11 // JSONTimeString is an auxiliary type to allow us to format the time as we wish
12 type JSONTimeString string
13
14 // String converts the unix timestamp into a string
15 func (t JSONTimeString) String() string {
16 tm := t.Time()
17 if tm.IsZero() {
18 return ""
19 }
20 return fmt.Sprintf("\"%s\"", tm.Format("Mon Jan _2"))
21 }
22
23 // Time converts the timestamp string to time.Time
24 func (t JSONTimeString) Time() time.Time {
25 if t == "" {
26 return time.Time{}
27 }
28 floatN, err := strconv.ParseFloat(string(t), 64)
29 if err != nil {
30 log.Println("ERROR parsing a JSONTimeString!", err)
31 return time.Time{}
32 }
33 return time.Unix(int64(floatN), 0)
34 }
356
367 var portMapping = map[string]string{"ws": "80", "wss": "443"}
378