1package slack
2
3import (
4	"fmt"
5	"time"
6)
7
8/**
9 * Internal events, created by this lib and not mapped to Slack APIs.
10 */
11
12// ConnectedEvent is used for when we connect to Slack
13type ConnectedEvent struct {
14	ConnectionCount int // 1 = first time, 2 = second time
15	Info            *Info
16}
17
18// ConnectionErrorEvent contains information about a connection error
19type ConnectionErrorEvent struct {
20	Attempt  int
21	Backoff  time.Duration // how long we'll wait before the next attempt
22	ErrorObj error
23}
24
25func (c *ConnectionErrorEvent) Error() string {
26	return c.ErrorObj.Error()
27}
28
29// ConnectingEvent contains information about our connection attempt
30type ConnectingEvent struct {
31	Attempt         int // 1 = first attempt, 2 = second attempt
32	ConnectionCount int
33}
34
35// DisconnectedEvent contains information about how we disconnected
36type DisconnectedEvent struct {
37	Intentional bool
38	Cause       error
39}
40
41// LatencyReport contains information about connection latency
42type LatencyReport struct {
43	Value time.Duration
44}
45
46// InvalidAuthEvent is used in case we can't even authenticate with the API
47type InvalidAuthEvent struct{}
48
49// UnmarshallingErrorEvent is used when there are issues deconstructing a response
50type UnmarshallingErrorEvent struct {
51	ErrorObj error
52}
53
54func (u UnmarshallingErrorEvent) Error() string {
55	return u.ErrorObj.Error()
56}
57
58// MessageTooLongEvent is used when sending a message that is too long
59type MessageTooLongEvent struct {
60	Message   OutgoingMessage
61	MaxLength int
62}
63
64func (m *MessageTooLongEvent) Error() string {
65	return fmt.Sprintf("Message too long (max %d characters)", m.MaxLength)
66}
67
68// RateLimitEvent is used when Slack warns that rate-limits are being hit.
69type RateLimitEvent struct{}
70
71func (e *RateLimitEvent) Error() string {
72	return "Messages are being sent too fast."
73}
74
75// OutgoingErrorEvent contains information in case there were errors sending messages
76type OutgoingErrorEvent struct {
77	Message  OutgoingMessage
78	ErrorObj error
79}
80
81func (o OutgoingErrorEvent) Error() string {
82	return o.ErrorObj.Error()
83}
84
85// IncomingEventError contains information about an unexpected error receiving a websocket event
86type IncomingEventError struct {
87	ErrorObj error
88}
89
90func (i *IncomingEventError) Error() string {
91	return i.ErrorObj.Error()
92}
93
94// AckErrorEvent i
95type AckErrorEvent struct {
96	ErrorObj error
97	ReplyTo  int
98}
99
100func (a *AckErrorEvent) Error() string {
101	return a.ErrorObj.Error()
102}
103