Jan
Jan

Reputation: 2168

Slack slash command: Respond as user, not app

When sending the response to a Slack slash command, I would like to send it under the user that has launched the slach command.

I have created a Slack app with a slash command. It calls my Flask webservice and I use the "response_url" webhook to write something back to the channel. The response in the channel is given by my app. This works as expected. But I would like for the response to be displayed as if a user has given it.

An example would be the Slack plugin from giphy. If I call it, I get an ephemeral message to choose the gif I would like. But then it is posted in the channel under my name.

So I have 2 questions:

  1. How does the API call look like to respond to the slash command as a specific user?
  2. What permissions for my app are required to allow for such behaviour of the app?

The Slack API documentation is comprehensive, but much research didn't yield the result I wanted.

Thanks!

Upvotes: 1

Views: 655

Answers (1)

Jai Pandya
Jai Pandya

Reputation: 2329

When you are using response_url, you can't customize your username or icon. For this, you'll need to use chat.postMessage API method. There are now two ways to achieve what you need here:

  1. Use user token: This gives you access to take actions on the behalf of the user. Although, you'll need to take authorization from every user you want post the message as.

  2. Request chat:write.customize scope with your bot token: You can post a message with icon_url and username parameters where you can provide the user's icon and name respectively for both the parameters. This is much easier, as this only requires one-time authorization.

More information in the official documentation.

Upvotes: 2

Related Questions