Package list golang-github-nlopes-slack / b8c4312
Fix error handling Errors now also get passed to the user as *slack.SlackWSError Norberto Lopes 6 years ago
3 changed file(s) with 13 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
4242 case slack.LatencyReport:
4343 a := msg.Data.(slack.LatencyReport)
4444 fmt.Printf("Current latency: %v\n", a.Value)
45 case *slack.SlackWSError:
46 error := msg.Data.(*slack.SlackWSError)
47 fmt.Printf("Error: %d - %s\n", error.Code, error.Msg)
4548 default:
4649 fmt.Printf("Unexpected: %v\n", msg.Data)
4750 }
5959 ReplyTo int `json:"reply_to"`
6060 }
6161
62 // AckMessage is used for messages received in reply to other messages
63 type AckMessage struct {
64 ReplyTo int `json:"reply_to"`
65 Timestamp string `json:"ts"`
66 Text string `json:"text"`
67 SlackResponse
68 }
69
7062 // NewOutGoingMessage prepares an OutgoingMessage that the user can use to send a message
7163 func (api *SlackWS) NewOutgoingMessage(text string, channel string) *OutgoingMessage {
7264 api.mutex.Lock()
2121 mutex sync.Mutex
2222 pings map[int]time.Time
2323 Slack
24 }
25
26 // AckMessage is used for messages received in reply to other messages
27 type AckMessage struct {
28 ReplyTo int `json:"reply_to"`
29 Timestamp string `json:"ts"`
30 Text string `json:"text"`
31 SlackWSResponse
2432 }
2533
2634 type SlackWSResponse struct {
190198 return
191199 }
192200
193 // TODO: errors end up in this bucket. They shouldn't.
194 log.Printf("Got error(?): %s", event)
201 // Send the error to the user
202 ch <- SlackEvent{Data: ack.Error}
195203 case "hello":
196204 ch <- SlackEvent{Data: HelloEvent{}}
197205 case "pong":