| 1 | package slackscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ |
| 2 | |
| 3 | import ( |
| 4 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/" |
| 6 | "ioscip-go gomod github.com/golang/go/src go1.16 io/" |
| 7 | "net/httpscip-go gomod github.com/golang/go/src go1.16 `net/http`/" |
| 8 | stdurlscip-go gomod github.com/golang/go/src go1.16 `net/url`/ "net/urlscip-go gomod github.com/golang/go/src go1.16 `net/url`/" |
| 9 | "reflectscip-go gomod github.com/golang/go/src go1.16 reflect/" |
| 10 | "timescip-go gomod github.com/golang/go/src go1.16 time/" |
| 11 | |
| 12 | "github.com/gorilla/websocketscip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/" |
| 13 | |
| 14 | "github.com/slack-go/slack/internal/backoffscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/internal/backoff`/" |
| 15 | "github.com/slack-go/slack/internal/errorsxscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/internal/errorsx`/" |
| 16 | "github.com/slack-go/slack/internal/timexscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/internal/timex`/" |
| 17 | ) |
| 18 | |
| 19 | // UnmappedError represents error occurred when there is no mapping between given event name |
| 20 | // and corresponding Go struct. |
| 21 | type UnmappedErrorscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmappedError# struct { |
| 22 | // EventType returns event type name. |
| 23 | EventTypescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmappedError#EventType. string |
| 24 | // RawEvent returns raw event body. |
| 25 | RawEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmappedError#RawEvent. jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage# |
| 26 | |
| 27 | ctxMsgscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmappedError#ctxMsg. string |
| 28 | } |
| 29 | |
| 30 | // NewUnmappedError returns new UnmappedError instance. |
| 31 | func NewUnmappedErrorscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/NewUnmappedError().(ctxMsg, eventType string, raw jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage#) *UnmappedErrorscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmappedError# { |
| 32 | return &UnmappedErrorscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmappedError#{ |
| 33 | ctxMsgscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmappedError#ctxMsg.: ctxMsg, |
| 34 | EventTypescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmappedError#EventType.: eventType, |
| 35 | RawEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmappedError#RawEvent.: raw, |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | // Error returns human-readable error message. |
| 40 | func (u UnmappedErrorscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmappedError#) Errorscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmappedError#Error().() string { |
| 41 | return fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("%s: Received unmapped event %q", u.ctxMsgscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmappedError#ctxMsg., u.EventTypescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmappedError#EventType.) |
| 42 | } |
| 43 | |
| 44 | // ManageConnection can be called on a Slack RTM instance returned by the |
| 45 | // NewRTM method. It will connect to the slack RTM API and handle all incoming |
| 46 | // and outgoing events. If a connection fails then it will attempt to reconnect |
| 47 | // and will notify any listeners through an error event on the IncomingEvents |
| 48 | // channel. |
| 49 | // |
| 50 | // If the connection ends and the disconnect was unintentional then this will |
| 51 | // attempt to reconnect. |
| 52 | // |
| 53 | // This should only be called once per slack API! Otherwise expect undefined |
| 54 | // behavior. |
| 55 | // |
| 56 | // The defined error events are located in websocket_internals.go. |
| 57 | func (rtm *RTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#) ManageConnectionscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#ManageConnection().() { |
| 58 | var ( |
| 59 | err error |
| 60 | info *Infoscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Info# |
| 61 | conn *websocketscip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/.Connscip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/Conn# |
| 62 | ) |
| 63 | |
| 64 | for connectionCount := 0; ; connectionCount++ { |
| 65 | // start trying to connect |
| 66 | // the returned err is already passed onto the IncomingEvents channel |
| 67 | if info, conn, err = rtm.connectscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#connect().(connectionCount, rtm.useRTMStartscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#useRTMStart.); err != nil { |
| 68 | // when the connection is unsuccessful its fatal, and we need to bail out. |
| 69 | rtm.Debugfscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugf().("Failed to connect with RTM on try %d: %s", connectionCount, err) |
| 70 | rtm.disconnectscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#disconnect().() |
| 71 | return |
| 72 | } |
| 73 | |
| 74 | // lock to prevent data races with Disconnect particularly around isConnected |
| 75 | // and conn. |
| 76 | rtm.muscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#mu..Lockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Lock().() |
| 77 | rtm.connscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#conn. = conn |
| 78 | rtm.infoscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#info. = info |
| 79 | rtm.muscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#mu..Unlockscip-go gomod github.com/golang/go/src go1.16 sync/Mutex#Unlock().() |
| 80 | |
| 81 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"connected", &ConnectedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ConnectedEvent#{ |
| 82 | ConnectionCountscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ConnectedEvent#ConnectionCount.: connectionCount, |
| 83 | Infoscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ConnectedEvent#Info.: info, |
| 84 | }} |
| 85 | |
| 86 | rtm.Debugfscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugf().("RTM connection succeeded on try %d", connectionCount) |
| 87 | |
| 88 | rawEvents := make(chan jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage#) |
| 89 | // we're now connected so we can set up listeners |
| 90 | go rtm.handleIncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#handleIncomingEvents().(rawEvents) |
| 91 | // this should be a blocking call until the connection has ended |
| 92 | rtm.handleEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#handleEvents().(rawEvents) |
| 93 | |
| 94 | select { |
| 95 | case <-rtm.disconnectedscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#disconnected.: |
| 96 | // after handle events returns we need to check if we're disconnected |
| 97 | // when this happens we need to cleanup the newly created connection. |
| 98 | if err = conn.Closescip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/Conn#Close().(); err != nil { |
| 99 | rtm.Debuglnscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugln().("failed to close conn on disconnected RTM", err) |
| 100 | } |
| 101 | return |
| 102 | default: |
| 103 | // otherwise continue and run the loop again to reconnect |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // connect attempts to connect to the slack websocket API. It handles any |
| 109 | // errors that occur while connecting and will return once a connection |
| 110 | // has been successfully opened. |
| 111 | // If useRTMStart is false then it uses rtm.connect to create the connection, |
| 112 | // otherwise it uses rtm.start. |
| 113 | func (rtm *RTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#) connectscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#connect().(connectionCount int, useRTMStart bool) (*Infoscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Info#, *websocketscip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/.Connscip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/Conn#, error) { |
| 114 | const ( |
| 115 | errInvalidAuth = "invalid_auth" |
| 116 | errInactiveAccount = "account_inactive" |
| 117 | errMissingAuthToken = "not_authed" |
| 118 | errTokenRevoked = "token_revoked" |
| 119 | ) |
| 120 | |
| 121 | // used to provide exponential backoff wait time with jitter before trying |
| 122 | // to connect to slack again |
| 123 | boff := &backoffscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/internal/backoff`/.Backoffscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/internal/backoff`/Backoff#{ |
| 124 | Maxscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/internal/backoff`/Backoff#Max.: 5 * timescip-go gomod github.com/golang/go/src go1.16 time/.Minutescip-go gomod github.com/golang/go/src go1.16 time/Minute., |
| 125 | } |
| 126 | |
| 127 | for { |
| 128 | var ( |
| 129 | backoff timescip-go gomod github.com/golang/go/src go1.16 time/.Durationscip-go gomod github.com/golang/go/src go1.16 time/Duration# |
| 130 | ) |
| 131 | |
| 132 | // send connecting event |
| 133 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"connecting", &ConnectingEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ConnectingEvent#{ |
| 134 | Attemptscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ConnectingEvent#Attempt.: boff.Attemptsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/internal/backoff`/Backoff#Attempts().() + 1, |
| 135 | ConnectionCountscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ConnectingEvent#ConnectionCount.: connectionCount, |
| 136 | }} |
| 137 | |
| 138 | // attempt to start the connection |
| 139 | info, conn, err := rtm.startRTMAndDialscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#startRTMAndDial().(useRTMStart) |
| 140 | if err == nil { |
| 141 | return info, conn, nil |
| 142 | } |
| 143 | |
| 144 | // check for fatal errors |
| 145 | switch err.Error() { |
| 146 | case errInvalidAuth, errInactiveAccount, errMissingAuthToken, errTokenRevoked: |
| 147 | rtm.Debugfscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugf().("invalid auth when connecting with RTM: %s", err) |
| 148 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"invalid_auth", &InvalidAuthEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/InvalidAuthEvent#{}} |
| 149 | return nil, nil, err |
| 150 | default: |
| 151 | } |
| 152 | |
| 153 | switch actual := err.(type) { |
| 154 | case StatusCodeErrorscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/StatusCodeError#: |
| 155 | if actual.Codescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/StatusCodeError#Code. == httpscip-go gomod github.com/golang/go/src go1.16 `net/http`/.StatusNotFoundscip-go gomod github.com/golang/go/src go1.16 `net/http`/StatusNotFound. { |
| 156 | rtm.Debugfscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugf().("invalid auth when connecting with RTM: %s", err) |
| 157 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"invalid_auth", &InvalidAuthEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/InvalidAuthEvent#{}} |
| 158 | return nil, nil, err |
| 159 | } |
| 160 | case *RateLimitedErrorscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RateLimitedError#: |
| 161 | backoff = actual.RetryAfterscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RateLimitedError#RetryAfter. |
| 162 | default: |
| 163 | } |
| 164 | |
| 165 | backoff = timexscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/internal/timex`/.Maxscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/internal/timex`/Max().(backoff, boff.Durationscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/internal/backoff`/Backoff#Duration().()) |
| 166 | // any other errors are treated as recoverable and we try again after |
| 167 | // sending the event along the IncomingEvents channel |
| 168 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"connection_error", &ConnectionErrorEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ConnectionErrorEvent#{ |
| 169 | Attemptscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ConnectionErrorEvent#Attempt.: boff.Attemptsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/internal/backoff`/Backoff#Attempts().(), |
| 170 | Backoffscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ConnectionErrorEvent#Backoff.: backoff, |
| 171 | ErrorObjscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ConnectionErrorEvent#ErrorObj.: err, |
| 172 | }} |
| 173 | |
| 174 | // get time we should wait before attempting to connect again |
| 175 | rtm.Debugfscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugf().("reconnection %d failed: %s reconnecting in %v\n", boff.Attemptsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/internal/backoff`/Backoff#Attempts().(), err, backoff) |
| 176 | |
| 177 | // wait for one of the following to occur, |
| 178 | // backoff duration has elapsed, killChannel is signalled, or |
| 179 | // the rtm finishes disconnecting. |
| 180 | select { |
| 181 | case <-timescip-go gomod github.com/golang/go/src go1.16 time/.Afterscip-go gomod github.com/golang/go/src go1.16 time/After().(backoff): // retry after the backoff. |
| 182 | case intentional := <-rtm.killChannelscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#killChannel.: |
| 183 | if intentional { |
| 184 | rtm.killConnectionscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#killConnection().(intentional, ErrRTMDisconnectedscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ErrRTMDisconnected.) |
| 185 | return nil, nil, ErrRTMDisconnectedscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ErrRTMDisconnected. |
| 186 | } |
| 187 | case <-rtm.disconnectedscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#disconnected.: |
| 188 | return nil, nil, ErrRTMDisconnectedscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ErrRTMDisconnected. |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | // startRTMAndDial attempts to connect to the slack websocket. If useRTMStart is true, |
| 194 | // then it returns the full information returned by the "rtm.start" method on the |
| 195 | // slack API. Else it uses the "rtm.connect" method to connect |
| 196 | func (rtm *RTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#) startRTMAndDialscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#startRTMAndDial().(useRTMStart bool) (info *Infoscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Info#, _ *websocketscip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/.Connscip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/Conn#, err error) { |
| 197 | var ( |
| 198 | url string |
| 199 | ) |
| 200 | |
| 201 | if useRTMStart { |
| 202 | rtm.Debugfscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugf().("Starting RTM") |
| 203 | info, url, err = rtm.StartRTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#StartRTM().() |
| 204 | } else { |
| 205 | rtm.Debugfscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugf().("Connecting to RTM") |
| 206 | info, url, err = rtm.ConnectRTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#ConnectRTM().() |
| 207 | } |
| 208 | if err != nil { |
| 209 | rtm.Debugfscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugf().("Failed to start or connect to RTM: %s", err) |
| 210 | return nil, nil, err |
| 211 | } |
| 212 | |
| 213 | // install connection parameters |
| 214 | u, err := stdurlscip-go gomod github.com/golang/go/src go1.16 `net/url`/.Parsescip-go gomod github.com/golang/go/src go1.16 `net/url`/Parse().(url) |
| 215 | if err != nil { |
| 216 | return nil, nil, err |
| 217 | } |
| 218 | u.RawQueryscip-go gomod github.com/golang/go/src go1.16 `net/url`/URL#RawQuery. = rtm.connParamsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#connParams..Encodescip-go gomod github.com/golang/go/src go1.16 `net/url`/Values#Encode().() |
| 219 | url = u.Stringscip-go gomod github.com/golang/go/src go1.16 `net/url`/URL#String().() |
| 220 | |
| 221 | rtm.Debugfscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugf().("Dialing to websocket on url %s", url) |
| 222 | // Only use HTTPS for connections to prevent MITM attacks on the connection. |
| 223 | upgradeHeader := httpscip-go gomod github.com/golang/go/src go1.16 `net/http`/.Headerscip-go gomod github.com/golang/go/src go1.16 `net/http`/Header#{} |
| 224 | upgradeHeader.Addscip-go gomod github.com/golang/go/src go1.16 `net/http`/Header#Add().("Origin", "https://api.slack.com") |
| 225 | dialer := websocketscip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/.DefaultDialerscip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/DefaultDialer. |
| 226 | if rtm.dialerscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#dialer. != nil { |
| 227 | dialer = rtm.dialerscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#dialer. |
| 228 | } |
| 229 | conn, _, err := dialer.Dialscip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/Dialer#Dial().(url, upgradeHeader) |
| 230 | if err != nil { |
| 231 | rtm.Debugfscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugf().("Failed to dial to the websocket: %s", err) |
| 232 | return nil, nil, err |
| 233 | } |
| 234 | return info, conn, err |
| 235 | } |
| 236 | |
| 237 | // killConnection stops the websocket connection and signals to all goroutines |
| 238 | // that they should cease listening to the connection for events. |
| 239 | // |
| 240 | // This should not be called directly! Instead a boolean value (true for |
| 241 | // intentional, false otherwise) should be sent to the killChannel on the RTM. |
| 242 | func (rtm *RTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#) killConnectionscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#killConnection().(intentional bool, cause error) (err error) { |
| 243 | rtm.Debuglnscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugln().("killing connection", cause) |
| 244 | |
| 245 | if rtm.connscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#conn. != nil { |
| 246 | err = rtm.connscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#conn..Closescip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/Conn#Close().() |
| 247 | } |
| 248 | |
| 249 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"disconnected", &DisconnectedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/DisconnectedEvent#{Intentionalscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/DisconnectedEvent#Intentional.: intentional, Causescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/DisconnectedEvent#Cause.: cause}} |
| 250 | |
| 251 | if intentional { |
| 252 | rtm.disconnectscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#disconnect().() |
| 253 | } |
| 254 | |
| 255 | return err |
| 256 | } |
| 257 | |
| 258 | // handleEvents is a blocking function that handles all events. This sends |
| 259 | // pings when asked to (on rtm.forcePing) and upon every given elapsed |
| 260 | // interval. This also sends outgoing messages that are received from the RTM's |
| 261 | // outgoingMessages channel. This also handles incoming raw events from the RTM |
| 262 | // rawEvents channel. |
| 263 | func (rtm *RTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#) handleEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#handleEvents().(events chan jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage#) { |
| 264 | ticker := timescip-go gomod github.com/golang/go/src go1.16 time/.NewTickerscip-go gomod github.com/golang/go/src go1.16 time/NewTicker().(rtm.pingIntervalscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#pingInterval.) |
| 265 | defer ticker.Stopscip-go gomod github.com/golang/go/src go1.16 time/Ticker#Stop().() |
| 266 | for { |
| 267 | select { |
| 268 | // catch "stop" signal on channel close |
| 269 | case intentional := <-rtm.killChannelscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#killChannel.: |
| 270 | _ = rtm.killConnectionscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#killConnection().(intentional, errorsxscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/internal/errorsx`/.Stringscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/internal/errorsx`/String#("signaled")) |
| 271 | return |
| 272 | // detect when the connection is dead. |
| 273 | case <-rtm.pingDeadmanscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#pingDeadman..Cscip-go gomod github.com/golang/go/src go1.16 time/Timer#C.: |
| 274 | _ = rtm.killConnectionscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#killConnection().(false, ErrRTMDeadmanscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ErrRTMDeadman.) |
| 275 | return |
| 276 | // send pings on ticker interval |
| 277 | case <-ticker.Cscip-go gomod github.com/golang/go/src go1.16 time/Ticker#C.: |
| 278 | if err := rtm.pingscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#ping().(); err != nil { |
| 279 | _ = rtm.killConnectionscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#killConnection().(false, err) |
| 280 | return |
| 281 | } |
| 282 | case <-rtm.forcePingscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#forcePing.: |
| 283 | if err := rtm.pingscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#ping().(); err != nil { |
| 284 | _ = rtm.killConnectionscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#killConnection().(false, err) |
| 285 | return |
| 286 | } |
| 287 | // listen for messages that need to be sent |
| 288 | case msg := <-rtm.outgoingMessagesscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#outgoingMessages.: |
| 289 | rtm.sendOutgoingMessagescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#sendOutgoingMessage().(msg) |
| 290 | // listen for incoming messages that need to be parsed |
| 291 | case rawEvent := <-events: |
| 292 | switch rtm.handleRawEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#handleRawEvent().(rawEvent) { |
| 293 | case rtmEventTypeGoodbyescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/rtmEventTypeGoodbye.: |
| 294 | // kill the connection, but DO NOT RETURN, a follow up kill signal will |
| 295 | // be sent that still needs to be processed. this duplication is because |
| 296 | // the event reader restarts once it emits the goodbye event. |
| 297 | // unlike the other cases in this function a final read will be triggered |
| 298 | // against the connection which will emit a kill signal. if we return early |
| 299 | // this kill signal will be processed by the next connection. |
| 300 | _ = rtm.killConnectionscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#killConnection().(false, ErrRTMGoodbyescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ErrRTMGoodbye.) |
| 301 | default: |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | // handleIncomingEvents monitors the RTM's opened websocket for any incoming |
| 308 | // events. It pushes the raw events into the channel. |
| 309 | // |
| 310 | // This will stop executing once the RTM's when a fatal error is detected, or |
| 311 | // a disconnect occurs. |
| 312 | func (rtm *RTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#) handleIncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#handleIncomingEvents().(events chan jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage#) { |
| 313 | for { |
| 314 | if err := rtm.receiveIncomingEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#receiveIncomingEvent().(events); err != nil { |
| 315 | select { |
| 316 | case rtm.killChannelscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#killChannel. <- false: |
| 317 | case <-rtm.disconnectedscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#disconnected.: |
| 318 | } |
| 319 | return |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | func (rtm *RTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#) sendWithDeadlinescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#sendWithDeadline().(msg interface{}) error { |
| 325 | // set a write deadline on the connection |
| 326 | if err := rtm.connscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#conn..SetWriteDeadlinescip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/Conn#SetWriteDeadline().(timescip-go gomod github.com/golang/go/src go1.16 time/.Nowscip-go gomod github.com/golang/go/src go1.16 time/Now().().Addscip-go gomod github.com/golang/go/src go1.16 time/Time#Add().(10 * timescip-go gomod github.com/golang/go/src go1.16 time/.Secondscip-go gomod github.com/golang/go/src go1.16 time/Second.)); err != nil { |
| 327 | return err |
| 328 | } |
| 329 | if err := rtm.connscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#conn..WriteJSONscip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/Conn#WriteJSON().(msg); err != nil { |
| 330 | return err |
| 331 | } |
| 332 | // remove write deadline |
| 333 | return rtm.connscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#conn..SetWriteDeadlinescip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/Conn#SetWriteDeadline().(timescip-go gomod github.com/golang/go/src go1.16 time/.Timescip-go gomod github.com/golang/go/src go1.16 time/Time#{}) |
| 334 | } |
| 335 | |
| 336 | // sendOutgoingMessage sends the given OutgoingMessage to the slack websocket. |
| 337 | // |
| 338 | // It does not currently detect if a outgoing message fails due to a disconnect |
| 339 | // and instead lets a future failed 'PING' detect the failed connection. |
| 340 | func (rtm *RTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#) sendOutgoingMessagescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#sendOutgoingMessage().(msg OutgoingMessagescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/OutgoingMessage#) { |
| 341 | rtm.Debuglnscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugln().("Sending message:", msg) |
| 342 | if len([]rune(msg.Textscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/OutgoingMessage#Text.)) > MaxMessageTextLengthscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/MaxMessageTextLength. { |
| 343 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"outgoing_error", &MessageTooLongEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/MessageTooLongEvent#{ |
| 344 | Messagescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/MessageTooLongEvent#Message.: msg, |
| 345 | MaxLengthscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/MessageTooLongEvent#MaxLength.: MaxMessageTextLengthscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/MaxMessageTextLength., |
| 346 | }} |
| 347 | return |
| 348 | } |
| 349 | |
| 350 | if err := rtm.sendWithDeadlinescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#sendWithDeadline().(msg); err != nil { |
| 351 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"outgoing_error", &OutgoingErrorEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/OutgoingErrorEvent#{ |
| 352 | Messagescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/OutgoingErrorEvent#Message.: msg, |
| 353 | ErrorObjscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/OutgoingErrorEvent#ErrorObj.: err, |
| 354 | }} |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | // ping sends a 'PING' message to the RTM's websocket. If the 'PING' message |
| 359 | // fails to send then this returns an error signifying that the connection |
| 360 | // should be considered disconnected. |
| 361 | // |
| 362 | // This does not handle incoming 'PONG' responses but does store the time of |
| 363 | // each successful 'PING' send so latency can be detected upon a 'PONG' |
| 364 | // response. |
| 365 | func (rtm *RTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#) pingscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#ping().() error { |
| 366 | id := rtm.idGenscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#idGen..Nextscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/IDGenerator#Next.() |
| 367 | rtm.Debuglnscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugln().("Sending PING ", id) |
| 368 | msg := &Pingscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Ping#{IDscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Ping#ID.: id, Typescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Ping#Type.: "ping", Timestampscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Ping#Timestamp.: timescip-go gomod github.com/golang/go/src go1.16 time/.Nowscip-go gomod github.com/golang/go/src go1.16 time/Now().().Unixscip-go gomod github.com/golang/go/src go1.16 time/Time#Unix().()} |
| 369 | |
| 370 | if err := rtm.sendWithDeadlinescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#sendWithDeadline().(msg); err != nil { |
| 371 | rtm.Debugfscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugf().("RTM Error sending 'PING %d': %s", id, err.Error()) |
| 372 | return err |
| 373 | } |
| 374 | return nil |
| 375 | } |
| 376 | |
| 377 | // receiveIncomingEvent attempts to receive an event from the RTM's websocket. |
| 378 | // This will block until a frame is available from the websocket. |
| 379 | // If the read from the websocket results in a fatal error, this function will return non-nil. |
| 380 | func (rtm *RTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#) receiveIncomingEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#receiveIncomingEvent().(events chan jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage#) error { |
| 381 | event := jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage#{} |
| 382 | err := rtm.connscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#conn..ReadJSONscip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/Conn#ReadJSON().(&event) |
| 383 | |
| 384 | // check if the connection was closed. |
| 385 | if websocketscip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/.IsUnexpectedCloseErrorscip-go gomod github.com/gorilla/websocket v1.4.2 `github.com/gorilla/websocket`/IsUnexpectedCloseError().(err) { |
| 386 | return err |
| 387 | } |
| 388 | |
| 389 | switch { |
| 390 | case err == ioscip-go gomod github.com/golang/go/src go1.16 io/.ErrUnexpectedEOFscip-go gomod github.com/golang/go/src go1.16 io/ErrUnexpectedEOF.: |
| 391 | // EOF's don't seem to signify a failed connection so instead we ignore |
| 392 | // them here and detect a failed connection upon attempting to send a |
| 393 | // 'PING' message |
| 394 | |
| 395 | // trigger a 'PING' to detect potential websocket disconnect |
| 396 | select { |
| 397 | case rtm.forcePingscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#forcePing. <- true: |
| 398 | case <-rtm.disconnectedscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#disconnected.: |
| 399 | } |
| 400 | case err != nil: |
| 401 | // All other errors from ReadJSON come from NextReader, and should |
| 402 | // kill the read loop and force a reconnect. |
| 403 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"incoming_error", &IncomingEventErrorscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/IncomingEventError#{ |
| 404 | ErrorObjscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/IncomingEventError#ErrorObj.: err, |
| 405 | }} |
| 406 | |
| 407 | return err |
| 408 | case len(event) == 0: |
| 409 | rtm.Debuglnscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugln().("Received empty event") |
| 410 | default: |
| 411 | rtm.Debuglnscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugln().("Incoming Event:", string(event)) |
| 412 | select { |
| 413 | case events <- event: |
| 414 | case <-rtm.disconnectedscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#disconnected.: |
| 415 | rtm.Debuglnscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugln().("disonnected while attempting to send raw event") |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | return nil |
| 420 | } |
| 421 | |
| 422 | // handleRawEvent takes a raw JSON message received from the slack websocket |
| 423 | // and handles the encoded event. |
| 424 | // returns the event type of the message. |
| 425 | func (rtm *RTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#) handleRawEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#handleRawEvent().(rawEvent jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage#) string { |
| 426 | event := &Eventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Event#{} |
| 427 | err := jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/Unmarshal().(rawEvent, event) |
| 428 | if err != nil { |
| 429 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"unmarshalling_error", &UnmarshallingErrorEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmarshallingErrorEvent#{err}} |
| 430 | return "" |
| 431 | } |
| 432 | |
| 433 | switch event.Typescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Event#Type. { |
| 434 | case rtmEventTypeAckscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/rtmEventTypeAck.: |
| 435 | rtm.handleAckscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#handleAck().(rawEvent) |
| 436 | case rtmEventTypeHelloscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/rtmEventTypeHello.: |
| 437 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"hello", &HelloEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/HelloEvent#{}} |
| 438 | case rtmEventTypePongscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/rtmEventTypePong.: |
| 439 | rtm.handlePongscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#handlePong().(rawEvent) |
| 440 | case rtmEventTypeGoodbyescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/rtmEventTypeGoodbye.: |
| 441 | // just return the event type up for goodbye, will be handled by caller. |
| 442 | default: |
| 443 | rtm.handleEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#handleEvent().(event.Typescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Event#Type., rawEvent) |
| 444 | } |
| 445 | |
| 446 | return event.Typescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Event#Type. |
| 447 | } |
| 448 | |
| 449 | // handleAck handles an incoming 'ACK' message. |
| 450 | func (rtm *RTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#) handleAckscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#handleAck().(event jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage#) { |
| 451 | ack := &AckMessagescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/AckMessage#{} |
| 452 | if err := jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/Unmarshal().(event, ack); err != nil { |
| 453 | rtm.Debuglnscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugln().("RTM Error unmarshalling 'ack' event:", err) |
| 454 | rtm.Debuglnscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugln().(" -> Erroneous 'ack' event:", string(event)) |
| 455 | return |
| 456 | } |
| 457 | |
| 458 | if ack.Okscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMResponse#Ok. { |
| 459 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"ack", ack} |
| 460 | } else if ack.RTMResponsescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/AckMessage#RTMResponse..Errorscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMResponse#Error. != nil { |
| 461 | // As there is no documentation for RTM error-codes, this |
| 462 | // identification of a rate-limit warning is very brittle. |
| 463 | if ack.RTMResponsescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/AckMessage#RTMResponse..Errorscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMResponse#Error..Codescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMError#Code. == -1 && ack.RTMResponsescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/AckMessage#RTMResponse..Errorscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMResponse#Error..Msgscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMError#Msg. == "slow down, too many messages..." { |
| 464 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"ack_error", &RateLimitEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RateLimitEvent#{}} |
| 465 | } else { |
| 466 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"ack_error", &AckErrorEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/AckErrorEvent#{ack.Errorscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMResponse#Error., ack.ReplyToscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/AckMessage#ReplyTo.}} |
| 467 | } |
| 468 | } else { |
| 469 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"ack_error", &AckErrorEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/AckErrorEvent#{ErrorObjscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/AckErrorEvent#ErrorObj.: fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("ack decode failure")}} |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | // handlePong handles an incoming 'PONG' message which should be in response to |
| 474 | // a previously sent 'PING' message. This is then used to compute the |
| 475 | // connection's latency. |
| 476 | func (rtm *RTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#) handlePongscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#handlePong().(event jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage#) { |
| 477 | var ( |
| 478 | p Pongscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Pong# |
| 479 | ) |
| 480 | |
| 481 | rtm.resetDeadmanscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#resetDeadman().() |
| 482 | |
| 483 | if err := jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/Unmarshal().(event, &p); err != nil { |
| 484 | rtm.Clientscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#Client..logscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#log..Printlnscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ilogger#Println.("RTM Error unmarshalling 'pong' event:", err) |
| 485 | return |
| 486 | } |
| 487 | |
| 488 | latency := timescip-go gomod github.com/golang/go/src go1.16 time/.Sincescip-go gomod github.com/golang/go/src go1.16 time/Since().(timescip-go gomod github.com/golang/go/src go1.16 time/.Unixscip-go gomod github.com/golang/go/src go1.16 time/Unix().(p.Timestampscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Pong#Timestamp., 0)) |
| 489 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"latency_report", &LatencyReportscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/LatencyReport#{Valuescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/LatencyReport#Value.: latency}} |
| 490 | } |
| 491 | |
| 492 | // handleEvent is the "default" response to an event that does not have a |
| 493 | // special case. It matches the command's name to a mapping of defined events |
| 494 | // and then sends the corresponding event struct to the IncomingEvents channel. |
| 495 | // If the event type is not found or the event cannot be unmarshalled into the |
| 496 | // correct struct then this sends an UnmarshallingErrorEvent to the |
| 497 | // IncomingEvents channel. |
| 498 | func (rtm *RTMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#) handleEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#handleEvent().(typeStr string, event jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage#) { |
| 499 | v, exists := EventMappingscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/EventMapping.[typeStr] |
| 500 | if !exists { |
| 501 | rtm.Debugfscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugf().("RTM Error - received unmapped event %q: %s\n", typeStr, string(event)) |
| 502 | err := NewUnmappedErrorscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/NewUnmappedError().("RTM Error", typeStr, event) |
| 503 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"unmarshalling_error", &UnmarshallingErrorEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmarshallingErrorEvent#{err}} |
| 504 | return |
| 505 | } |
| 506 | t := reflectscip-go gomod github.com/golang/go/src go1.16 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.16 reflect/TypeOf().(v) |
| 507 | recvEvent := reflectscip-go gomod github.com/golang/go/src go1.16 reflect/.Newscip-go gomod github.com/golang/go/src go1.16 reflect/New().(t).Interfacescip-go gomod github.com/golang/go/src go1.16 reflect/Value#Interface().() |
| 508 | err := jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/Unmarshal().(event, recvEvent) |
| 509 | if err != nil { |
| 510 | rtm.Debugfscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/Client#Debugf().("RTM Error, could not unmarshall event %q: %s\n", typeStr, string(event)) |
| 511 | err := fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("RTM Error: Could not unmarshall event %q", typeStr) |
| 512 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{"unmarshalling_error", &UnmarshallingErrorEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UnmarshallingErrorEvent#{err}} |
| 513 | return |
| 514 | } |
| 515 | rtm.IncomingEventsscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTM#IncomingEvents. <- RTMEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/RTMEvent#{typeStr, recvEvent} |
| 516 | } |
| 517 | |
| 518 | // EventMapping holds a mapping of event names to their corresponding struct |
| 519 | // implementations. The structs should be instances of the unmarshalling |
| 520 | // target for the matching event type. |
| 521 | var EventMappingscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/EventMapping. = map[string]interface{}{ |
| 522 | "message": MessageEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/MessageEvent#{}, |
| 523 | "presence_change": PresenceChangeEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/PresenceChangeEvent#{}, |
| 524 | "user_typing": UserTypingEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UserTypingEvent#{}, |
| 525 | |
| 526 | "channel_marked": ChannelMarkedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ChannelMarkedEvent#{}, |
| 527 | "channel_created": ChannelCreatedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ChannelCreatedEvent#{}, |
| 528 | "channel_joined": ChannelJoinedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ChannelJoinedEvent#{}, |
| 529 | "channel_left": ChannelLeftEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ChannelLeftEvent#{}, |
| 530 | "channel_deleted": ChannelDeletedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ChannelDeletedEvent#{}, |
| 531 | "channel_rename": ChannelRenameEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ChannelRenameEvent#{}, |
| 532 | "channel_archive": ChannelArchiveEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ChannelArchiveEvent#{}, |
| 533 | "channel_unarchive": ChannelUnarchiveEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ChannelUnarchiveEvent#{}, |
| 534 | "channel_history_changed": ChannelHistoryChangedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ChannelHistoryChangedEvent#{}, |
| 535 | |
| 536 | "dnd_updated": DNDUpdatedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/DNDUpdatedEvent#{}, |
| 537 | "dnd_updated_user": DNDUpdatedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/DNDUpdatedEvent#{}, |
| 538 | |
| 539 | "im_created": IMCreatedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/IMCreatedEvent#{}, |
| 540 | "im_open": IMOpenEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/IMOpenEvent#{}, |
| 541 | "im_close": IMCloseEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/IMCloseEvent#{}, |
| 542 | "im_marked": IMMarkedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/IMMarkedEvent#{}, |
| 543 | "im_history_changed": IMHistoryChangedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/IMHistoryChangedEvent#{}, |
| 544 | |
| 545 | "group_marked": GroupMarkedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/GroupMarkedEvent#{}, |
| 546 | "group_open": GroupOpenEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/GroupOpenEvent#{}, |
| 547 | "group_joined": GroupJoinedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/GroupJoinedEvent#{}, |
| 548 | "group_left": GroupLeftEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/GroupLeftEvent#{}, |
| 549 | "group_close": GroupCloseEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/GroupCloseEvent#{}, |
| 550 | "group_rename": GroupRenameEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/GroupRenameEvent#{}, |
| 551 | "group_archive": GroupArchiveEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/GroupArchiveEvent#{}, |
| 552 | "group_unarchive": GroupUnarchiveEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/GroupUnarchiveEvent#{}, |
| 553 | "group_history_changed": GroupHistoryChangedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/GroupHistoryChangedEvent#{}, |
| 554 | |
| 555 | "file_created": FileCreatedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/FileCreatedEvent#{}, |
| 556 | "file_shared": FileSharedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/FileSharedEvent#{}, |
| 557 | "file_unshared": FileUnsharedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/FileUnsharedEvent#{}, |
| 558 | "file_public": FilePublicEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/FilePublicEvent#{}, |
| 559 | "file_private": FilePrivateEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/FilePrivateEvent#{}, |
| 560 | "file_change": FileChangeEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/FileChangeEvent#{}, |
| 561 | "file_deleted": FileDeletedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/FileDeletedEvent#{}, |
| 562 | "file_comment_added": FileCommentAddedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/FileCommentAddedEvent#{}, |
| 563 | "file_comment_edited": FileCommentEditedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/FileCommentEditedEvent#{}, |
| 564 | "file_comment_deleted": FileCommentDeletedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/FileCommentDeletedEvent#{}, |
| 565 | |
| 566 | "pin_added": PinAddedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/PinAddedEvent#{}, |
| 567 | "pin_removed": PinRemovedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/PinRemovedEvent#{}, |
| 568 | |
| 569 | "star_added": StarAddedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/StarAddedEvent#{}, |
| 570 | "star_removed": StarRemovedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/StarRemovedEvent#{}, |
| 571 | |
| 572 | "reaction_added": ReactionAddedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ReactionAddedEvent#{}, |
| 573 | "reaction_removed": ReactionRemovedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ReactionRemovedEvent#{}, |
| 574 | |
| 575 | "pref_change": PrefChangeEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/PrefChangeEvent#{}, |
| 576 | |
| 577 | "team_join": TeamJoinEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/TeamJoinEvent#{}, |
| 578 | "team_rename": TeamRenameEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/TeamRenameEvent#{}, |
| 579 | "team_pref_change": TeamPrefChangeEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/TeamPrefChangeEvent#{}, |
| 580 | "team_domain_change": TeamDomainChangeEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/TeamDomainChangeEvent#{}, |
| 581 | "team_migration_started": TeamMigrationStartedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/TeamMigrationStartedEvent#{}, |
| 582 | |
| 583 | "manual_presence_change": ManualPresenceChangeEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ManualPresenceChangeEvent#{}, |
| 584 | |
| 585 | "user_change": UserChangeEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/UserChangeEvent#{}, |
| 586 | |
| 587 | "emoji_changed": EmojiChangedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/EmojiChangedEvent#{}, |
| 588 | |
| 589 | "commands_changed": CommandsChangedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/CommandsChangedEvent#{}, |
| 590 | |
| 591 | "email_domain_changed": EmailDomainChangedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/EmailDomainChangedEvent#{}, |
| 592 | |
| 593 | "bot_added": BotAddedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/BotAddedEvent#{}, |
| 594 | "bot_changed": BotChangedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/BotChangedEvent#{}, |
| 595 | |
| 596 | "accounts_changed": AccountsChangedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/AccountsChangedEvent#{}, |
| 597 | |
| 598 | "reconnect_url": ReconnectUrlEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/ReconnectUrlEvent#{}, |
| 599 | |
| 600 | "member_joined_channel": MemberJoinedChannelEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/MemberJoinedChannelEvent#{}, |
| 601 | "member_left_channel": MemberLeftChannelEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/MemberLeftChannelEvent#{}, |
| 602 | |
| 603 | "subteam_created": SubteamCreatedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/SubteamCreatedEvent#{}, |
| 604 | "subteam_members_changed": SubteamMembersChangedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/SubteamMembersChangedEvent#{}, |
| 605 | "subteam_self_added": SubteamSelfAddedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/SubteamSelfAddedEvent#{}, |
| 606 | "subteam_self_removed": SubteamSelfRemovedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/SubteamSelfRemovedEvent#{}, |
| 607 | "subteam_updated": SubteamUpdatedEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/SubteamUpdatedEvent#{}, |
| 608 | |
| 609 | "desktop_notification": DesktopNotificationEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/DesktopNotificationEvent#{}, |
| 610 | "mobile_in_app_notification": MobileInAppNotificationEventscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack`/MobileInAppNotificationEvent#{}, |
| 611 | } |