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

Allow a custom SocketModeReceiver to be used with Socket Mode #1972

Merged
merged 1 commit into from
Oct 18, 2023

Conversation

zimeg
Copy link
Member

@zimeg zimeg commented Oct 16, 2023

Summary

This PR allows a custom SocketModeReceiver to be used with Socket Mode when initializing an app.

Reviewers

These changes can be verified with the following snippets:

Socket Mode receiver

This should now work fine! The custom route at http://localhost:3000/health and the message response should both respond with something expected.

/** Socket Mode receiver */
const receiver = new SocketModeReceiver({
    appToken: process.env.SLACK_APP_TOKEN,
    customRoutes: [
    {
      path: '/health',
      method: ['GET'],
      handler: (req, res) => {
        res.writeHead(200);
        res.end(`Things are going just fine at ${req.headers.host}!`);
      },
    },
  ]
});

/** App initialization */
const app = new App({
    token: process.env.SLACK_BOT_TOKEN,
    socketMode: true,
    appToken: process.env.SLACK_APP_TOKEN,
    logLevel: LogLevel.DEBUG,
    receiver
});

app.message('hello', async ({ say }) => {
  await say('hi!');
});

(async () => {
    await app.start(process.env.PORT || 3000);
    console.log("⚡️ Bolt app is running!");
})();

Express receiver

This will still error with an AppInitializationError trying to run the app.

/** Express receiver */
const receiver = new ExpressReceiver({
    signingSecret: process.env.SLACK_SIGNING_SECRET,
});

receiver.router.use((req, res, next) => {
    console.log(`Request time: ${Date.now()}`);
    next();
})

receiver.router.get("/health", (req, res) => {
    res.writeHead(200);
    res.end(`Things are going just fine at ${req.headers.host}!`);
});

/** App initialization */
const app = new App({
    token: process.env.SLACK_BOT_TOKEN,
    socketMode: true,
    appToken: process.env.SLACK_APP_TOKEN,
    logLevel: LogLevel.DEBUG,
    receiver
});

app.message('hello', async ({ say }) => {
  await say('hi!');
});

(async () => {
    await app.start(process.env.PORT || 3000);
    console.log("⚡️ Bolt app is running!");
})();

Requirements

@zimeg zimeg added enhancement M-T: A feature request for new functionality semver:patch labels Oct 16, 2023
@zimeg zimeg added this to the 3.14.1 milestone Oct 16, 2023
@zimeg zimeg self-assigned this Oct 16, 2023
@codecov
Copy link

codecov bot commented Oct 16, 2023

Codecov Report

Merging #1972 (1b59b70) into main (2b259a9) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1972   +/-   ##
=======================================
  Coverage   82.21%   82.21%           
=======================================
  Files          18       18           
  Lines        1524     1524           
  Branches      438      438           
=======================================
  Hits         1253     1253           
  Misses        175      175           
  Partials       96       96           
Files Coverage Δ
src/App.ts 83.41% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

LGTM 👍

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.

LGTM! Was this in response to a particular issue?

@zimeg
Copy link
Member Author

zimeg commented Oct 18, 2023

@seratch @filmaj Thank y'all for the reviews! This was found while exploring for #1971 though doesn't directly address the issue.

@zimeg zimeg merged commit f104c0b into slackapi:main Oct 18, 2023
8 checks passed
@zimeg zimeg deleted the socket-mode-receiver-init branch October 18, 2023 16:40
@filmaj filmaj modified the milestones: 3.14.1, 3.15.0 Nov 14, 2023
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 semver:patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants