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

custom routes not working #2084

Closed
yashgandhi-32 opened this issue Apr 2, 2024 · 7 comments
Closed

custom routes not working #2084

yashgandhi-32 opened this issue Apr 2, 2024 · 7 comments
Labels
auto-triage-stale question M-T: User needs support to use the project

Comments

@yashgandhi-32
Copy link

yashgandhi-32 commented Apr 2, 2024

I have @slack/bolt version v3.7.0 and using a custom route but it's not working for express receiver in some cases. Could you pls share what is the behaviour here?

return new App({
      receiver: this.receiver,
      customRoutes: [
        {
          path: '/health-check',
          method: ['GET'],
          handler: (req, res) => {
            res.writeHead(200);
            res.end(`Things are going just fine at ${req.headers.host}!`);
          },
        },
      ],
    });

when I am trying below endpoint /health-check

I get

{
  "statusCode": 404,
  "message": "Cannot GET /health-check",
  "error": "Not Found"
}

When I add using express it works

this.receiver.router.get('/health-check', (req, res) => {
      // You're working with an express req and res now.
      res.send('yay!');
    });

but for /slack/install it still fails

this.receiver.router.get('/slack/install', (req, res) => {
      // You're working with an express req and res now.
      res.send('yay!');
    });
@filmaj
Copy link
Contributor

filmaj commented Apr 2, 2024

What is this.receiver? Please post the code definition for this, otherwise it is difficult for us to help you.

customRoutes only has an effect if you don't customize the receiver (as the receiver is responsible itself for setting up any routes). I believe the confusion is you are a) using a custom, express-based receiver, but b) you are giving Bolt a list of custom routes, but it doesn't know how to set up the custom receiver with these custom routes.

You can check the code for how Bolt initializes receivers and handles the customRoutes parameter. Specifically, if the receiver is defined, it simply returns it. Only in the case that no receiver is provided does customRoutes get used to customize one of the default SocketModeReceiver or the HTTPReceiver.

If you are instantiating your own receiver, then please look at our Receiver Reference documentation, and specifically the endpoints field, which sounds like what you need (a way to tell a receiver what endpoints to listen on).

@filmaj filmaj added question M-T: User needs support to use the project and removed untriaged labels Apr 2, 2024
@seratch
Copy link
Member

seratch commented Apr 3, 2024

You don't need to define /slack/install and /slack/oauth_redirect URLs as they are already enabled by the Express receiver. If you desire to customize the behavior, please pass installerOptions with callbackOptions: https://slack.dev/node-slack-sdk/reference/oauth#callbackoptions

@yashgandhi-32
Copy link
Author

I tried this below code with version of boltjs ^3.13.0 it works but with v3.7.0 I get the error slack_oauth_invalid_state

new App({
receiver: new ExpressReceiver({
      signingSecret: this.configService.get('src.slackSigninSecret'),
      stateSecret: this.configService.get('src.stateSecret'),
      clientId: this.configService.get('src.clientId'),
      clientSecret: this.configService.get('src.clientSecret'),
      scopes: ['commands', 'chat:write', 'users:read', 'users:read.email', 'mpim:write'],

      installationStore: {
        storeInstallation: async installation => {
         
        },

        fetchInstallation: async installQuery => {
          
        },
        deleteInstallation: async installQuery => {
          
        },
      },
      installerOptions: {
        directInstall: true,
        callbackOptions: {
          successAsync: async (installation, _options, _req, res) => {
           
            res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });
            res.write('data');
            res.end();

        
          },
        },
      },
    });
})
    ```

@seratch
Copy link
Member

seratch commented Apr 3, 2024

Since v3.11, we've improved the security about the OAuth flow. Refer to the release notes for more details: https://github.com/slackapi/bolt-js/releases/tag/%40slack%2Fbolt%403.11.0

If you encounter behavior changes described at #1412, consider either changing your app code or setting installerOptions.legacyStateVerification: true for now.

We really don't recommend legacyStateVerification: true but if there is a certain use case to bypass the OAuth state parameter (e.g., installing from Slack admin pages for orgs/workspaces), you can add the option to make your app to function as with older versions.

@yashgandhi-32
Copy link
Author

Now I used this

beforeInstallation: async (opts, req, res) => {
            res.writeHead(301,
              {Location: 'http://app.example.io'}
            );
            res.end();
            return false;
          },

It still taking user to the page to select the workspace once user select and click install it then redirect to other website , I am using directInstall: true is there any way to customize so user get directly to some other page on my website when they click app on slack app directory

Copy link

github-actions bot commented May 6, 2024

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

Copy link

As this issue has been inactive for more than one month, we will be closing it. Thank you to all the participants! If you would like to raise a related issue, please create a new issue which includes your specific details and references this issue number.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-triage-stale question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

3 participants