diff options
author | Wim <wim@42.be> | 2016-09-05 16:34:37 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2016-09-05 16:34:37 +0200 |
commit | b30e85836e575974bac1b2ea91e9b6c2dd39fe44 (patch) | |
tree | b3aa5d148e436cacd6c737ad56ba3fc0b9369e26 /vendor/github.com/nlopes/slack/rtm.go | |
parent | e449a97bd0114e55c2a73aa79b061b55d755aa16 (diff) | |
download | matterbridge-msglm-b30e85836e575974bac1b2ea91e9b6c2dd39fe44.tar.gz matterbridge-msglm-b30e85836e575974bac1b2ea91e9b6c2dd39fe44.tar.bz2 matterbridge-msglm-b30e85836e575974bac1b2ea91e9b6c2dd39fe44.zip |
Add Slack support
Diffstat (limited to 'vendor/github.com/nlopes/slack/rtm.go')
-rw-r--r-- | vendor/github.com/nlopes/slack/rtm.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/github.com/nlopes/slack/rtm.go b/vendor/github.com/nlopes/slack/rtm.go new file mode 100644 index 00000000..f3552c53 --- /dev/null +++ b/vendor/github.com/nlopes/slack/rtm.go @@ -0,0 +1,39 @@ +package slack + +import ( + "fmt" + "net/url" +) + +// StartRTM calls the "rtm.start" endpoint and returns the provided URL and the full Info +// block. +// +// To have a fully managed Websocket connection, use `NewRTM`, and call `ManageConnection()` +// on it. +func (api *Client) StartRTM() (info *Info, websocketURL string, err error) { + response := &infoResponseFull{} + err = post("rtm.start", url.Values{"token": {api.config.token}}, response, api.debug) + if err != nil { + return nil, "", fmt.Errorf("post: %s", err) + } + if !response.Ok { + return nil, "", response.Error + } + + // websocket.Dial does not accept url without the port (yet) + // Fixed by: https://github.com/golang/net/commit/5058c78c3627b31e484a81463acd51c7cecc06f3 + // but slack returns the address with no port, so we have to fix it + api.Debugln("Using URL:", response.Info.URL) + websocketURL, err = websocketizeURLPort(response.Info.URL) + if err != nil { + return nil, "", fmt.Errorf("parsing response URL: %s", err) + } + + return &response.Info, websocketURL, nil +} + +// NewRTM returns a RTM, which provides a fully managed connection to +// Slack's websocket-based Real-Time Messaging protocol./ +func (api *Client) NewRTM() *RTM { + return newRTM(api) +} |