Codebase list golang-github-nlopes-slack / 46797b2
Add ConnectRTM call to use the rtm.connect endpoint David Palm 6 years ago
1 changed file(s) with 27 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
3131 return &response.Info, websocketURL, nil
3232 }
3333
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
3461 // NewRTM returns a RTM, which provides a fully managed connection to
3562 // Slack's websocket-based Real-Time Messaging protocol./
3663 func (api *Client) NewRTM() *RTM {