Slack slash commands cannot be executed programmatically via the API or any other method. This includes attempting to use them through a webhook. The main reason for this is a security measure by Slack to prevent unauthorized or malicious use of potentially powerful commands.
If you want to mimic the functionality of some slash commands, you will typically need to implement that functionality yourself using the Slack API, webhooks, or possibly app integrations depending on what you are trying to achieve.
Receiving a Slash Command in Slack: Create a Slash command in Slack and link it to your AWS Lambda function via API Gateway. Slack sends a POST request to your specified URL (API Gateway URL in this case) when a user types the command in the chat.
Running Functionality Equivalent to Slash Commands: Since you can't execute a Slash command directly from your AWS Lambda function, you need to simulate the command's functionality. For instance, if you want to simulate the /poll command
- Use the Slack API to send a message to a channel asking for a poll.
- Use AWS Lambda along with DynamoDB to store responses.
- Monitor the channel for responses (using Slack Events API) and update the poll results in DynamoDB.
- Post updated results to the channel.
This does require more setup and coding, but it will give you much more control over the functionality and interface.
You can use the slack_sdk package (formerly slackclient).