Search code examples
herokuslack

Slack Slash Commands trigger GET request with no query parms


I am trying to extend Slack by creating a Slack App that installs Slash Commands when the Slack App is installed by the user. The Slash Commands when triggered by a Slack chat user, will interact with an external web service that I am trying to develop.

According to the Slack documents for Slash Commands (https://api.slack.com/slash-commands), any Slash command will trigger a POST to the external service with a set of parameters in the POST body to indicate among other things, the user, the Slack channel, etc., that triggered the request.

When I made the web service I am developing on localhost available to the Internet using localtunnel (https://www.npmjs.com/package/localtunnel), localtunnel actually creates a virtual server with some random hostname on localtunnel.me, e.g., https://wkbtfodclm.localtunnel.me, which connects to my localhost.

If I key in the Slash Command on my Slack chat, Slack successfully sends a POST request to the localtunnel.me server, which gets piped to my localhost.

However, after I deploy to Heroku, which has a domain, e.g., https://example.com, I notice that the Slash Command sends a GET request with no parameters to the server on Heroku. Has anybody experience this before?


Solution

  • Everything on the Slack side was working as expected. When I use the Slash command, Slack contacts its server, which then does a POST to the external web service https://example.com (as I configured) with all the parameters. However, the web service (due to DNS settings) will redirect https://example.com requests to https://www.example.com (NOTE the www). This resulted in the POST by Slack to be redirected as a GET with no URL queries. Configuring the Slash command to use https://www.example.com fixed this.