1

I implemented a slash command in Slack that calls an AWS Lambda function and in return, the Lambda function needs to run some other Slash commands in Slack. What's the best way of doing this?

Is it possible to do it through the webhook of a channel? So that instead of just posting text, it runs the commands. This would be very convenient since it's so straightforward (the app is an internal app by the company, so hardcoding a webhook is entirely valid).

If not, what's the next possible solution?

I'm aware of these two questions:

but they are quite old and point to a Python package that has been abandoned.

Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622

2 Answers2

0

I think the command is hidden because of security concerns, because you can run other apps other than your own. You cant execute the command but your app could give the user the ability to excute it manually, by clicking a button for example.

I think you can do the following: Use Asynchronous responses and use response_url parameter in the payload. this will execute along process and wait for a response.

Also you could use modal response with 'trigger_id' and generate and use a webhook in 3 seconds or it will expire.

user16930239
  • 6,319
  • 2
  • 9
  • 33
0

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).

Alperen Tahta
  • 459
  • 2
  • 12