Skip to content
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

Introduce a @slack/cli-hooks package that implements Slack CLI hooks #1714

Merged
merged 48 commits into from Jan 26, 2024

Conversation

zimeg
Copy link
Member

@zimeg zimeg commented Jan 8, 2024

Summary

This PR introduces a standalone package that implements hooks for the Slack CLI, meant for use in Bolt for JavaScript apps.

Early versions of this package are published to NPM here: https://www.npmjs.com/package/@slack/cli-hooks

Reviewers

Update a new Bolt app with the latest version of the CLI and the following commands:

$ slack create hooks --template slack-samples/bolt-js-custom-function-template

# Confirm a manifest.json file is found
$ slack manifest

# Check that the app starts without problems
$ slack run

# Verify dependencies with updates are shown
# Note: Installing updates is not yet supported
$ slack update

Notes

A few quick questions rose during development:

  • Should the start hook default file be app.js or index.js? 👍
  • Is the install-update hook alright to implement as a follow up? 👍

Some tasks remain as TODOs as well: #1714 (comment) 👍

Requirements

@zimeg zimeg added semver:minor enhancement M-T: A feature request for new functionality pkg:cli-hooks applies to `@slack/cli-hooks` labels Jan 8, 2024
@zimeg zimeg self-assigned this Jan 8, 2024
packages/hooks/README.md Outdated Show resolved Hide resolved
packages/hooks/README.md Outdated Show resolved Hide resolved
packages/hooks/package.json Outdated Show resolved Hide resolved
packages/hooks/src/check-update.js Outdated Show resolved Hide resolved
return version;
});
return {
name: 'the Slack SDK',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how correct it is, but it matches the Deno hooks implementation and makes some sense to me. This field "corresponds to the overall package/library, in which individual component releases are bundled" and I'm not sure of better naming for it since both @slack/bolt and @slack/hooks might be included. Open to any suggestions though!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've always disliked what we chose for the Deno one since it feels so general. No harm though in staying the course: let's keep it for now!

name: 'the Slack SDK',
message: '',
releases,
url: 'https://api.slack.com/automation/changelog',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, is this what we would want to point them to?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Not sure of a better place at the moment... It does seem strange since CLI release notes are displayed separately from this and the automation changelog is mostly CLI and Deno. I'm open to changing this whenever!

For reference here are example update logs
$ slack update

🌱 A new version of the Slack CLI is available:
   v1.0.0 → 2.15.0

   You can read the release notes at:
   https://api.slack.com/automation/changelog

   To manually update, visit the download page:
   https://api.slack.com/automation/cli/install

? 🚀 Do you want to auto-update to the latest version now? No

🛠️  An update from the Slack SDK is available:

    › @slack/hooks
      0.0.5 → 0.0.6

      Learn more at:
      https://github.com/slackapi/node-slack-sdk/releases/tag/@slack/hooks@0.0.6

   For more information about this update, visit:
   https://api.slack.com/automation/changelog

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for the visual! That's helpful. I guess my question is will the hooks package update be present in the Changelog with everything else? If so, it makes sense. If not, we probably need to tweak the CLI logic at some point.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to future changes in the CLI since I don't think these hooks will be included in the changelog / follow the same release cycle. Maybe we do align these releases though?

For now I think this is alright to leave but will add it to the backlog!

packages/hooks/src/get-hooks.js Outdated Show resolved Hide resolved
packages/hooks/src/start.js Outdated Show resolved Hide resolved
packages/hooks/src/start.js Outdated Show resolved Hide resolved
Co-authored-by: Alissa Renz <alissa.renz@gmail.com>
Copy link
Member Author

@zimeg zimeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@misscoded Really appreciate the review! Going to follow up with a few updates to the README and an update to get-manifest but will hold off on changes to naming and removal of Deno for right now. Definitely open to making these changes soon though!

packages/hooks/README.md Outdated Show resolved Hide resolved
packages/hooks/README.md Outdated Show resolved Hide resolved
packages/hooks/src/check-update.js Outdated Show resolved Hide resolved
return version;
});
return {
name: 'the Slack SDK',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how correct it is, but it matches the Deno hooks implementation and makes some sense to me. This field "corresponds to the overall package/library, in which individual component releases are bundled" and I'm not sure of better naming for it since both @slack/bolt and @slack/hooks might be included. Open to any suggestions though!

name: 'the Slack SDK',
message: '',
releases,
url: 'https://api.slack.com/automation/changelog',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Not sure of a better place at the moment... It does seem strange since CLI release notes are displayed separately from this and the automation changelog is mostly CLI and Deno. I'm open to changing this whenever!

For reference here are example update logs
$ slack update

🌱 A new version of the Slack CLI is available:
   v1.0.0 → 2.15.0

   You can read the release notes at:
   https://api.slack.com/automation/changelog

   To manually update, visit the download page:
   https://api.slack.com/automation/cli/install

? 🚀 Do you want to auto-update to the latest version now? No

🛠️  An update from the Slack SDK is available:

    › @slack/hooks
      0.0.5 → 0.0.6

      Learn more at:
      https://github.com/slackapi/node-slack-sdk/releases/tag/@slack/hooks@0.0.6

   For more information about this update, visit:
   https://api.slack.com/automation/changelog

packages/hooks/src/start.js Outdated Show resolved Hide resolved
packages/hooks/src/start.js Outdated Show resolved Hide resolved
packages/hooks/src/get-hooks.js Outdated Show resolved Hide resolved
packages/hooks/README.md Outdated Show resolved Hide resolved
@zimeg zimeg marked this pull request as ready for review January 11, 2024 07:49
Copy link
Contributor

@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great 💯 I left a few suggestions and NITs

Should the start hook default file be app.js or index.js?

Our templates and samples use app.js defaulting to it makes sense

Is the install-update hook alright to implement as a follow up?

I say go for it but I think there is also value in implementing the message boundary protocol

packages/hooks/src/check-update.js Outdated Show resolved Hide resolved
packages/hooks/src/check-update.js Outdated Show resolved Hide resolved
packages/hooks/src/get-hooks.js Outdated Show resolved Hide resolved
@filmaj
Copy link
Contributor

filmaj commented Jan 11, 2024

Gonna start my review now, but re: your questions in your original comment:

Should the start hook default file be app.js or index.js?

slack.dev getting started instructions use app.js, so that has my vote.

Is the install-update hook alright to implement as a follow up?

100%

@filmaj
Copy link
Contributor

filmaj commented Jan 11, 2024

@zimeg one thing I noticed: I have the sample up and running, but I can't add the function bundled in the app to WFB when I deploy it to my test workspace. I think because the output of slack manifest doesn't include any functions, so there's no 'custom step' in WFB to add.

@zimeg
Copy link
Member Author

zimeg commented Jan 26, 2024

@misscoded @WilliamBergamin @filmaj A few patches later and I believe this is ready for re-review! I've updated the steps to review to hopefully be easier (everything should be working right away) but you will need a dev build of the CLI to handle automagic tokens.

Please let me know if there's anything more that needs updating! Or just changing! 🙏

@filmaj
Copy link
Contributor

filmaj commented Jan 26, 2024

Two paper-cut style issues I just encountered (feel free to file somewhere and move on if you think this is something worth addressing at some point):

create --template clones using https://

I had some issues testing this out from scratch, I think because the template repo you linked to is internal:

10:40:14 in ~/src
➜ slak create remote-func-js --template slack-samples/bolt-js-custom-function-template
⚙️  Creating a new Slack app in ~/src/remote-func-js

Username for 'https://github.com': filmaj
Password for 'https://filmaj@github.com':
Check /Users/fmaj/.slack/logs/slack-debug-20240126.log for full error logs

🚫 Error: While cloning repository, the following error occurred:

git clone --depth=1 https://github.com/slack-samples/bolt-js-custom-function-template.git /Users/fmaj/src/remote-func-js

Cloning into '/Users/fmaj/src/remote-func-js'...
remote: Support for password authentication was removed on August 13, 2021.

Even entering my username and password doesn't work as GitHub seems to block those attempts.

Idea: can the CLI fallback to trying to clone using SSH if cloning using HTTPS fails?

Error returned if bolt-js dependencies not installed is unclear

Another sharp edge: I then tried just manually cloning the repo and running slack manifest within - but forgetting to run npm i within. The error I get is:

➜ slak manifest
Check /Users/fmaj/.slack/logs/slack-debug-20240126.log for full error logs

🚫 There was an error while reading the Slack Configuration file (`slack.json`) or running the `get-hooks` hook (sdk_config_load_error)

Error Details:

1: Command for '' returned an error: exit status 1
npm ERR! canceled

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/fmaj/.npm/_logs/2024-01-26T15_44_44_782Z-debug-0.log (sdk_hook_invocation_failed)
Suggestion: Run `slack doctor` to check that your system dependencies are up-to-date.


Suggestion:

Run `slack doctor` to check that your system dependencies are up-to-date.

Is there any way to return a nicer / clearer error in this case?

@filmaj
Copy link
Contributor

filmaj commented Jan 26, 2024

But - in general works GREAT! AWESOME!

Screenshot 2024-01-26 at 10 55 33 AM Screenshot 2024-01-26 at 10 55 15 AM

Copy link
Contributor

@filmaj filmaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work, very close to being ready I think!

packages/cli-hooks/src/check-update.js Show resolved Hide resolved

/**
* Standardized communication format between the SDK and CLI regarding hooks.
* @typedef SDKInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job documenting these

'sdk-managed-connection-enabled': true,
},
runtime: 'node',
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanliness of this implementation gives me the warm n fuzzies

packages/cli-hooks/src/get-manifest.js Show resolved Hide resolved
packages/cli-hooks/package.json Show resolved Hide resolved
packages/cli-hooks/src/protocols.js Show resolved Hide resolved
'.',
],
},
'protocol-version': ['message-boundaries', 'default'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we pull these protocol names from the protocol source file in this package? The reason I bring this up is that protocol.js defines a SUPPORTED_NAMED_PROTOCOLS array that only includes the message boundary protocol, but by returning this line in get-hooks, we're telling the CLI that either of the two named protocols is fine to use (with a preference for message-boundaries). We should decide on one approach.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally in favor of using SUPPORTED_NAMED_PROTOCOLS - good call. Making the update now to use that exported array with only message-boundaries for now. Open to also including default in the export, but I lean towards including just the message-boundaries in this hook.

packages/cli-hooks/src/protocols.spec.js Outdated Show resolved Hide resolved
});
});

describe('message boundary protocol', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work!

packages/cli-hooks/src/start.js Outdated Show resolved Hide resolved
Copy link
Contributor

@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome 💯 just left some nits take them or leave them

packages/cli-hooks/src/protocols.js Outdated Show resolved Hide resolved
packages/cli-hooks/src/check-update.js Show resolved Hide resolved
packages/cli-hooks/src/protocols.js Outdated Show resolved Hide resolved
@zimeg
Copy link
Member Author

zimeg commented Jan 26, 2024

@filmaj @WilliamBergamin appreciate another round of reviews and pointers on polish! I think I've addressed all of the comments and suggestions (or added more polish-related CLI-things to our backlog) so I think this is ready for another round of review.

I've tested this on Node v18.19.0 and v20.8.0 for macOS and Node v18.19.0 and v20.11.0 for Windows. Everything is working as hoped! There is a problem forming the actual web socket connection on Windows, but I think this is a problem with the virtual environment I'm using and not the hooks (the app is stuck trying to authenticate the Socket Mode request) 😬

Copy link
Contributor

@filmaj filmaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@zimeg
Copy link
Member Author

zimeg commented Jan 26, 2024

@filmaj :excited: 🚀 let's goooooo!! Do we want to start this at v1.0.0 or stay in the patch range for now? Or maybe that's extreme and we want something more minor?

@filmaj
Copy link
Contributor

filmaj commented Jan 26, 2024

Your call big guy!

@zimeg
Copy link
Member Author

zimeg commented Jan 26, 2024

@filmaj The time feels right for a 1.0.0 😎

@zimeg
Copy link
Member Author

zimeg commented Jan 26, 2024

@filmaj @WilliamBergamin @misscoded Really appreciate all of the reviews on this! Thanks a ton! 🚢 💨

@zimeg zimeg merged commit f3dff4d into main Jan 26, 2024
17 checks passed
@zimeg zimeg deleted the cli-hooks branch January 26, 2024 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement M-T: A feature request for new functionality pkg:cli-hooks applies to `@slack/cli-hooks` release semver:major
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants