Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slack slash commands - show user-entered text?

I'm working with the slack slash commands API, and it works swimmingly with my bot (https://github.com/jesseditson/slashbot) so far, except for one thing:

In other slash integrations (for instance giphy), when a user types a slash command, the command is output to the public chat, then the response is posted:

giphy integration
(source: pxfx.io)

However when I use a custom slash command, the original command is not output at all:

no message
(source: pxfx.io)

I'm currently using the Incoming Webhooks API to post messages back to the channel, which works OK, but the responses are disembodied and lacking context without the original request.

What I'd like it to do:

  1. A user types /command
  2. That command is echoed out to the chat room as a message that everyone can see (preferably if I return 2XX from the URL the slash command hits)
  3. The response is posted either inline, or via an incoming webhook (either works for me, having both as an option would be preferable)

This appears to be possible via whatever giphy uses to integrate, which leaves me with some questions:

  • Is giphy using a private API, or have I missed the correct API to emulate this behavior?

  • Is there a setting I missed to allow this?

I'm using node.js, but I'm more interested in if this is possible at all, language aside.


As a side note, I realize I could use the Bot API or Real Time Messaging API to achieve something similar, but without the slash - however, I really like the documentation options and autocomplete that comes with the slash commands, so that's what I'm after with this question.

like image 569
Jesse Avatar asked Jul 23 '15 21:07

Jesse


1 Answers

From Slack's /Command API Docs:

In Channel" vs "Ephemeral" responses

By default, the response messages sent to commands will only be visible to the user that issued the command (we call these "ephemeral" messages). However, if you would like the response to be visible to all members of the channel in which the user typed the command, you can add a response_type of in_channel to the JSON response, like this:

{ "response_type": "in_channel", "text": "It's 80 degrees right now.", "attachments": [ { "text":"Partly cloudy today and tomorrow" } ] }

I think you need to set response_type to "in_channel" to allow other users to see the response.

like image 114
esamek Avatar answered Nov 04 '22 05:11

esamek