-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Socket Mode support #885
Socket Mode support #885
Conversation
This is a WIP implementation of Socket Mode support for this library based on the official documentation at https://api.slack.com/apis/connections/socket and some reverse engineering on https://github.com/slackapi/node-slack-sdk/blob/main/packages/socket-mode. Please read [the official annoucement](https://medium.com/slack-developer-blog/socket-to-me-3d122f96d955) for more information about Socket Mode. Resolves slack-go#883
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mumoshu You are so quick! I am happy to be of help. Please feel free to ask me or other folks in the github.com/SlackAPI team any questions 👋
socket_mode_client.go
Outdated
Type string `json:"type"` | ||
Reason string `json:"reason"` | ||
Payload SocketModeMessagePayload `json:"payload"` | ||
EnvelopeID string `json:"envelope_id"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A Socket Mode envelope can have the following attributes.
- AcceptsResponsePayload bool
- RetryAttempt *int // only for Events API
- RetryReason string // only for Events API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I've added a bunch of fields according to your info and my observation
…pkg and slacksocketmode pkg
smc.Debugln("Sending ACK ", envelopeID) | ||
|
||
// See https://github.com/slackapi/node-slack-sdk/blob/c3f4d7109062a0356fb765d53794b7b5f6b3b5ae/packages/socket-mode/src/SocketModeClient.ts#L417 | ||
msg := map[string]interface{}{"envelope_id": envelopeID} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response message can have "payload" in addition to "envelop_id" for interactive / slash_commands types, while events_api requires only "envelope_id".
- https://api.slack.com/apis/connections/socket-implement#acknowledge
- https://github.com/slackapi/java-slack-sdk/tree/v1.5.1/slack-api-client/src/main/java/com/slack/api/socket_mode/response
slack.OutgoingMessage
is not compatible with Socket Mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah thanks! First of all, I didn't realize till now that slash_commands
and interactive
are top-level types that are comparable to events_api
and hello
and so on.
And it's really good to know that the way we ack the socket mode "request" (or "event", which do you prefer btw? I thought you call it SocketModeRequest
in python-sdk and event
in node-sdk)
I will soon try modifying examples/socketmode
and the library and test it accordingly and circle back to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first changeset for this: 88722e9#diff-f5d9e76c79011a908909fa0f14332b25faba7ef70c64f12682937d35382f3f47R395-R425
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Thank you.
I've add a few comments, but I will do another detailed review when you finish implementing.
Added proper support (as I think) for Also note that the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just left a few more comments. This pull request looks almost done 👍
(Please feel free to mention me whenever you and the maintainers of this project need my help.)
// `events_api` type only | ||
EnvelopeID string `json:"envelope_id"` | ||
// TODO Can it really be a non-object type? | ||
// See https://github.com/slackapi/python-slack-sdk/blob/3f1c4c6e27bf7ee8af57699b2543e6eb7848bcf9/slack_sdk/socket_mode/request.py#L26-L31 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, never mind about L30-31 in the Python SDK (the code should be improved). You can safely assume the "payload" is an object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thanks for clarification 😃
// We treat the `disconnect` request from Slack as an error internally, | ||
// so that we can tell the consumer of this function to reopen the connection on it. | ||
return ErrorRequestedDisconnect{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the handling code look like? Do developers need to write a handler on their own? If so, having the code in the example should be helpful. The disconnect requests can be regularly sent to all Socket Mode apps. This is not a rare case.
If this library can have the reconnection logic (= acquiring a new WSS URL and establishing a new connection to the endpoint under the hood), that's amazing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this library can have the reconnection logic (= acquiring a new WSS URL and establishing a new connection to the endpoint under the hood), that's amazing!
Good question - Yes I've made the client to handle the reconnection on its own, following all the awesome Socket Mode clients you've written for other languages 😄
For your reference, the below is where we implement the infinite reconnection loop:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW In Go anything that is NOT under internal
package whose name starts with an uppercase letter is considered public - so ErrorRequestedDisconnect
is fairly confusing as it can give users misconception that one might want to use this outside of this package.
I'm going to make it private so that it is clear that the consumer of the client does not need to know about this internal error happens on disconnect request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so ErrorRequestedDisconnect is fairly confusing as it can give users misconception that one might want to use this outside of this package.
Yes, actually I was thinking so too. Making it private should be the right direction 👍
Also, I've verified the reconnecting logic works properly. Great work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added few comments, but looks good to me!
Thanks to everyone for reviewing! I believe I've addressed all the feedback we had so far. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!!
@seratch How do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I am not a maintainer of this project, please allow me to give an approval. I am pretty sure that this Socket Mode client implementation is production-ready 👍
Hey 👋 Did the slacktest package ever get updated at all? Doesn't look like it did by this PP, and that means using it to unit test your bot's business logic doesn't currently work :/ e.g:
|
This is a
WIPimplementation of Socket Mode support for this library based on the official documentation at https://api.slack.com/apis/connections/socket and some reverse engineering on https://github.com/slackapi/node-slack-sdk/blob/main/packages/socket-mode.Please read the official annoucement for more information about Socket Mode.
Resolves #883
Notes for reviewers:
socketmode.Client
is added, which is a bit similar to the existingslack.RTM
Pull Request Guidelines
These are recommendations for pull requests.
They are strictly guidelines to help manage expectations.
PR preparation
Run
make pr-prep
from the root of the repository to run formatting, linting and tests.Should this be an issue instead
API changes
Since API changes have to be maintained they undergo a more detailed review and are more likely to require changes.
Examples of API changes that do not meet guidelines: