-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection.go
46 lines (41 loc) · 1.12 KB
/
connection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package singularity
import (
"errors"
"golang.org/x/net/websocket"
)
const (
//SlackAPI is the slack API url. Hit it with SlackAPI + apiCall
SlackAPI = "slack.com/api/"
)
// func (singularity *Singularity) ConnectToTeam(token string) (*SlackInstance, error) {
// helper := HTTPHelper{Client: &http.Client{}, Transport: "https://"}
// var response RTMResp
// _, err := helper.post("rtm.start", &response, "token", token)
// if err != nil {
// return nil, err
// }
//
// //Connect to websocket.
// conn, err := singularity.startWebsocketStream(response.URL)
// if err != nil {
// return nil, err
// }
// return singularity.addTeam(conn, response)
// }
func (singularity *Singularity) startWebsocketStream(url string) (*websocket.Conn, error) {
conn, err := websocket.Dial(url, "", "http://api.slack.com") //TODO Don't hard code here.
if err != nil {
return nil, err
}
var hello struct {
Hello string `json:"type"`
}
err = websocket.JSON.Receive(conn, &hello)
if err != nil {
return nil, err
}
if hello.Hello != "hello" {
return nil, errors.New("Didn't recieve my hello message :C")
}
return conn, nil
}