diff --git a/channels.go b/channels.go index dfab0f0..ba2d58d 100644 --- a/channels.go +++ b/channels.go @@ -32,23 +32,24 @@ // Channel contains information about the channel type Channel struct { - Id string `json:"id"` - Name string `json:"name"` - IsChannel bool `json:"is_channel"` - Created JSONTime `json:"created"` - Creator string `json:"creator"` - IsArchived bool `json:"is_archived"` - IsGeneral bool `json:"is_general"` - IsGroup bool `json:"is_group"` - IsStarred bool `json:"is_starred"` - Members []string `json:"members"` - Topic ChannelTopic `json:"topic"` - Purpose ChannelPurpose `json:"purpose"` - IsMember bool `json:"is_member"` - LastRead string `json:"last_read,omitempty"` - Latest Message `json:"latest,omitempty"` - UnreadCount int `json:"unread_count,omitempty"` - NumMembers int `json:"num_members,omitempty"` + Id string `json:"id"` + Name string `json:"name"` + IsChannel bool `json:"is_channel"` + Created JSONTime `json:"created"` + Creator string `json:"creator"` + IsArchived bool `json:"is_archived"` + IsGeneral bool `json:"is_general"` + IsGroup bool `json:"is_group"` + IsStarred bool `json:"is_starred"` + Members []string `json:"members"` + Topic ChannelTopic `json:"topic"` + Purpose ChannelPurpose `json:"purpose"` + IsMember bool `json:"is_member"` + LastRead string `json:"last_read,omitempty"` + Latest Message `json:"latest,omitempty"` + UnreadCount int `json:"unread_count,omitempty"` + NumMembers int `json:"num_members,omitempty"` + UnreadCountDisplay int `json:"unread_count_display,omitempty"` } func channelRequest(path string, values url.Values, debug bool) (*channelResponseFull, error) { @@ -117,12 +118,18 @@ if params.Count != DEFAULT_HISTORY_COUNT { values.Add("count", strconv.Itoa(params.Count)) } + if params.Inclusive != DEFAULT_HISTORY_INCLUSIVE { + if params.Inclusive { + values.Add("inclusive", "1") + } else { + values.Add("inclusive", "0") + } + } response, err := channelRequest("channels.history", values, api.debug) if err != nil { return nil, err } - channelHistory := response.History - return &channelHistory, nil + return &response.History, nil } // GetChannelInfo retrieves the given channel diff --git a/chat.go b/chat.go index 5e6b3fb..1af66f1 100644 --- a/chat.go +++ b/chat.go @@ -116,6 +116,7 @@ } // PostMessage sends a message to a channel +// Message is automatically escaped according to https://api.slack.com/docs/formatting func (api *Slack) PostMessage(channelId string, text string, params PostMessageParameters) (channel string, timestamp string, err error) { values := url.Values{ "token": {api.config.token}, diff --git a/dm.go b/dm.go index 1edb5cf..e8f30b5 100644 --- a/dm.go +++ b/dm.go @@ -22,11 +22,13 @@ // IM contains information related to the Direct Message channel type IM struct { - Id string `json:"id"` - IsIM bool `json:"is_im"` - UserId string `json:"user"` - Created JSONTime `json:"created"` - IsUserDeleted bool `json:"is_user_deleted"` + Id string `json:"id"` + IsIM bool `json:"is_im"` + UserId string `json:"user"` + Created JSONTime `json:"created"` + IsUserDeleted bool `json:"is_user_deleted"` + UnreadCount int `json:"unread_count,omitempty"` + UnreadCountDisplay int `json:"unread_count_display,omitempty"` } func imRequest(path string, values url.Values, debug bool) (*imResponseFull, error) { @@ -97,6 +99,13 @@ if params.Count != DEFAULT_HISTORY_COUNT { values.Add("count", strconv.Itoa(params.Count)) } + if params.Inclusive != DEFAULT_HISTORY_INCLUSIVE { + if params.Inclusive { + values.Add("inclusive", "1") + } else { + values.Add("inclusive", "0") + } + } response, err := imRequest("im.history", values, api.debug) if err != nil { return nil, err diff --git a/examples/websocket/websocket.go b/examples/websocket/websocket.go index 15dd561..2d5406a 100644 --- a/examples/websocket/websocket.go +++ b/examples/websocket/websocket.go @@ -36,15 +36,15 @@ // Ignore hello case *slack.MessageEvent: a := msg.Data.(*slack.MessageEvent) - fmt.Printf("%v\n", a) + fmt.Printf("Message: %v\n", a) case *slack.PresenceChangeEvent: a := msg.Data.(*slack.PresenceChangeEvent) - fmt.Printf("%v\n", a) + fmt.Printf("Presence Change: %v\n", a) case slack.LatencyReport: a := msg.Data.(slack.LatencyReport) fmt.Printf("Current latency: %v\n", a.Value) default: - fmt.Printf("Unknown: %v\n", msg.Data) + fmt.Printf("Unexpected: %v\n", msg.Data) } } } diff --git a/groups.go b/groups.go index b927988..d10a72e 100644 --- a/groups.go +++ b/groups.go @@ -8,21 +8,22 @@ // Group contains all the information for a group type Group struct { - Id string `json:"id"` - Name string `json:"name"` - IsGroup bool `json:"is_group"` - Created JSONTime `json:"created"` - Creator string `json:"creator"` - IsArchived bool `json:"is_archived"` - IsGeneral bool `json:"is_general"` - IsOpen bool `json:"is_open,omitempty"` - Members []string `json:"members"` - Topic ChannelTopic `json:"topic"` - Purpose ChannelPurpose `json:"purpose"` - LastRead string `json:"last_read,omitempty"` - Latest Message `json:"latest,omitempty"` - UnreadCount int `json:"unread_count,omitempty"` - NumMembers int `json:"num_members,omitempty"` + Id string `json:"id"` + Name string `json:"name"` + IsGroup bool `json:"is_group"` + Created JSONTime `json:"created"` + Creator string `json:"creator"` + IsArchived bool `json:"is_archived"` + IsGeneral bool `json:"is_general"` + IsOpen bool `json:"is_open,omitempty"` + Members []string `json:"members"` + Topic ChannelTopic `json:"topic"` + Purpose ChannelPurpose `json:"purpose"` + LastRead string `json:"last_read,omitempty"` + Latest Message `json:"latest,omitempty"` + UnreadCount int `json:"unread_count,omitempty"` + NumMembers int `json:"num_members,omitempty"` + UnreadCountDisplay int `json:"unread_count_display,omitempty"` // XXX: does this exist for a group too? IsMember bool `json:"is_member"` @@ -140,12 +141,18 @@ if params.Count != DEFAULT_HISTORY_COUNT { values.Add("count", strconv.Itoa(params.Count)) } + if params.Inclusive != DEFAULT_HISTORY_INCLUSIVE { + if params.Inclusive { + values.Add("inclusive", "1") + } else { + values.Add("inclusive", "0") + } + } response, err := groupRequest("groups.history", values, api.debug) if err != nil { return nil, err } - groupHistory := response.History - return &groupHistory, nil + return &response.History, nil } // InviteUserToGroup invites a user to a group diff --git a/history.go b/history.go index 0a9f0e5..18467d0 100644 --- a/history.go +++ b/history.go @@ -1,16 +1,18 @@ package slack const ( - DEFAULT_HISTORY_LATEST = "" - DEFAULT_HISTORY_OLDEST = "0" - DEFAULT_HISTORY_COUNT = 100 + DEFAULT_HISTORY_LATEST = "" + DEFAULT_HISTORY_OLDEST = "0" + DEFAULT_HISTORY_COUNT = 100 + DEFAULT_HISTORY_INCLUSIVE = false ) // HistoryParameters contains all the necessary information to help in the retrieval of history for Channels/Groups/DMs type HistoryParameters struct { - Latest string - Oldest string - Count int + Latest string + Oldest string + Count int + Inclusive bool } // History contains message history information needed to navigate a Channel / Group / DM history @@ -23,8 +25,9 @@ // NewHistoryParameters provides an instance of HistoryParameters with all the sane default values set func NewHistoryParameters() HistoryParameters { return HistoryParameters{ - Latest: DEFAULT_HISTORY_LATEST, - Oldest: DEFAULT_HISTORY_OLDEST, - Count: DEFAULT_HISTORY_COUNT, + Latest: DEFAULT_HISTORY_LATEST, + Oldest: DEFAULT_HISTORY_OLDEST, + Count: DEFAULT_HISTORY_COUNT, + Inclusive: DEFAULT_HISTORY_INCLUSIVE, } }