Add ConnectRTM call to use the rtm.connect endpoint
David Palm
6 years ago
31 | 31 | return &response.Info, websocketURL, nil |
32 | 32 | } |
33 | 33 | |
34 | // ConnectRTM calls the "rtm.connect" endpoint and returns the provided URL and the compact Info | |
35 | // block. | |
36 | // | |
37 | // To have a fully managed Websocket connection, use `NewRTM`, and call `ManageConnection()` | |
38 | // on it. | |
39 | func (api *Client) ConnectRTM() (info *Info, websocketURL string, slackResponse WebResponse, err error) { | |
40 | response := &infoResponseFull{} | |
41 | err = post("rtm.connect", url.Values{"token": {api.config.token}}, response, api.debug) | |
42 | if err != nil { | |
43 | return nil, "", response.WebResponse, fmt.Errorf("post: %s", err) | |
44 | } | |
45 | if !response.Ok { | |
46 | return nil, "", response.WebResponse, response.Error | |
47 | } | |
48 | ||
49 | // websocket.Dial does not accept url without the port (yet) | |
50 | // Fixed by: https://github.com/golang/net/commit/5058c78c3627b31e484a81463acd51c7cecc06f3 | |
51 | // but slack returns the address with no port, so we have to fix it | |
52 | api.Debugln("Using URL:", response.Info.URL) | |
53 | websocketURL, err = websocketizeURLPort(response.Info.URL) | |
54 | if err != nil { | |
55 | return nil, "", response.WebResponse, fmt.Errorf("parsing response URL: %s", err) | |
56 | } | |
57 | ||
58 | return &response.Info, websocketURL, response.WebResponse, nil | |
59 | } | |
60 | ||
34 | 61 | // NewRTM returns a RTM, which provides a fully managed connection to |
35 | 62 | // Slack's websocket-based Real-Time Messaging protocol./ |
36 | 63 | func (api *Client) NewRTM() *RTM { |