Bolt-js: Slash command endpoint

Created on 24 Jun 2019  路  7Comments  路  Source: slackapi/bolt-js

Description

Hi, i've been trying to setup slash commands for a bot but can't seem to find the endpoint that the slash command is listening at.

I've copied the below from the example given by the docs:

app.command('/echo', async ({ command, ack, say }) => {
  // Acknowledge command request
  ack();
  say(`${command.text}`);
});

In my slack app slash command config, I've created a new command at
https://localtunnel/echo
https://localtunnel/slack/command
https://localtunnel/slack/command/echo
https://localtunnel/slack/commands/echo

But I always get an error: Darn - that slash command didn't work (error message: '404_client_error'). Manage the command at Test App.

Am I pointing at the wrong endpoint or is there something else going wrong?

Thanks

What type of issue is this? (place an x in one of the [ ])

  • [ ] bug
  • [ ] enhancement (feature request)
  • [x] question
  • [ ] documentation related
  • [ ] testing related
  • [ ] discussion

Requirements (place an x in each of the [ ])

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Most helpful comment

@evanhli All of the endpoints are configured to be the same for simplicity: /slack/events (so in your case https://localtunnel/slack/events).

If you'd like, you can optionally pass in your own endpoint(s) to the constructor using the endpoints argument:

const app = new App({
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  token: process.env.SLACK_BOT_TOKEN,
  endpoints: {
     events: '/slack/events',
     commands: '/slack/commands' 
   }
});

This should be mentioned in the guide.

I've faced the same issue as well.

All 7 comments

@evanhli All of the endpoints are configured to be the same for simplicity: /slack/events (so in your case https://localtunnel/slack/events).

If you'd like, you can optionally pass in your own endpoint(s) to the constructor using the endpoints argument:

const app = new App({
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  token: process.env.SLACK_BOT_TOKEN,
  endpoints: {
     events: '/slack/events',
     commands: '/slack/commands' 
   }
});

Thanks!

@evanhli All of the endpoints are configured to be the same for simplicity: /slack/events (so in your case https://localtunnel/slack/events).

If you'd like, you can optionally pass in your own endpoint(s) to the constructor using the endpoints argument:

const app = new App({
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  token: process.env.SLACK_BOT_TOKEN,
  endpoints: {
     events: '/slack/events',
     commands: '/slack/commands' 
   }
});

This should be mentioned in the guide.

I've faced the same issue as well.

This is really should be mentioned in the guide. I met the same problem.

@evanhli All of the endpoints are configured to be the same for simplicity: /slack/events (so in your case https://localtunnel/slack/events).
If you'd like, you can optionally pass in your own endpoint(s) to the constructor using the endpoints argument:

const app = new App({
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  token: process.env.SLACK_BOT_TOKEN,
  endpoints: {
     events: '/slack/events',
     commands: '/slack/commands' 
   }
});

This should be mentioned in the guide.

I've faced the same issue as well.

@evanhli All of the endpoints are configured to be the same for simplicity: /slack/events (so in your case https://localtunnel/slack/events).

If you'd like, you can optionally pass in your own endpoint(s) to the constructor using the endpoints argument:

const app = new App({
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  token: process.env.SLACK_BOT_TOKEN,
  endpoints: {
     events: '/slack/events',
     commands: '/slack/commands' 
   }
});

This is really really should be mentioned in the guide.
I met the same problem.

+1 to others, please update the guide. For those encountering the same issue: Your code is likely correct - you need to update the Request URL of your slash command in app management to point to /slack/events

So..yes the docs now talk about this but it was extremely misleading still easy to gloss over, and confusing still coming from originally coding against the Slack API and not Bolt. I spent an hour trying to figure out and finally realizing this after coming across this issue which helped.

I was coding against /slack/actions and kept hitting my head against the wall as to why my app.action was not being hit. It was because Bolt was expecting /events which is just weird to me TBH. It's a convenience for you that makes it hella confusing for us Slack Team!

I suggest either:

1) Put an additional note to that effect in the beginning of the Actions section of the doc
2) better would probably be to just keep consistent with how the Slack API works for this and just tell people to use the endpoints prop in the app configuration to make it consistent with how the Real Slack API works. That way, there is no chance of people missing that part in your docs. I realize that for you it's "nice" but really it's not great for devs using Bolt because we're looking and using the Slack API configuration in the end

It's better to be explicit here. Stop the subtle difference between how Bolt treats the urls vs core Slack API patterns. There are some things you need to maintain consistency on and I think the core url pattern that you see most people setup in their API should be consistent with what we're putting in our incoming hooks value vs. events which are really two separate domain concepts.

_From the top_, here's what worked for me:

In the Slack Slash Commands page, set the request URL to ip:port/slack/events:

image

Initialize your Bolt app as you would normally:

export const app = new bolt.App({
  token: process.env.SLACK_BOT_TOKEN,
  signingSecret: process.env.SLACK_SIGNING_SECRET
});
app.command('/burn', async (everything: any) => {    //Ignore the :any if you're not using Typescript
  everything.ack();

  console.log(JSON.stringify(everything));    //A good way to see what variables you have to play with
});

And then for simplicity, I use the app.client.chat.postMessage to craft my response. You can get the channel and everything else within the _everything_ variable above.

Hopefully this helps someone 馃殌

Was this page helpful?
0 / 5 - 0 ratings

Related issues

johnsonyick picture johnsonyick  路  4Comments

seblaz picture seblaz  路  4Comments

erkand-imeri picture erkand-imeri  路  4Comments

i-break-codes picture i-break-codes  路  4Comments

jamesfmac picture jamesfmac  路  5Comments