Search code examples
slackslack-apislack-commands

Slash command response send two different responses, one to the user and another to channel


I have created a slack slash command "/myMeetings", this is actually been configured with a requestURL - https://slack.mycompany.com/slack

So now my use case is to send a response which is having two text messages, one of the type ephemeral and other message for in_channel

request_type - in_channel 
and
request_type - ephemeral

something like this

[
    {
      "response_type": "in_channel",
      "text": "This message will be shown to the entire channel"
    },
    {
      "response_type": "ephemeral",
      "text": "only shown to the user who initiates slash command"
    }
]

How can i achieve this behaviour?


Solution

  • You can only send one direct response to the Slash command request and it can only be either in_channel or ephemeral. So the suggested syntax will not work.

    However, to achieve your requirement you could simply post a message in addition to the response, with chat.postMessage for in_channel or chat.postEphermal for ephemeral. You will get the channel ID in the slask response request, so you know where to send the message to.

    Note that there are some special considerations with the approach:

    • Your app will need additional scopes for posting messages (e.g. chat.write.bot)
    • This approach will work fine in public channels, but not in any private or even direct message channel, since your app might not have access to that channel. To mitigate I can recommend forcing the user to invite your bot user to any private channel, thus giving your app access.