はじめに
- Slackのslash commandのリクエストに対して、普通にレスポンスを返すと「あなただけに表示されています」という状態で投稿されます
- 他の人に投稿した内容が見えるようにする方法を簡単にまとめます。
「あなただけに表示されています」を解消する方法
- レスポンス内で
response_type: 'in_channel'
を指定します。 - ちなみに、Slackの公式サイトにも以下のように記載されています。
The response_type parameter in the JSON payload controls this visibility, by default it is set to ephemeral, but you can specify a value of in_channel to post the response into the channel, like this:
{
"response_type": "in_channel",
"text": "It's 80 degrees right now."
}
参考URL : https://api.slack.com/interactivity/slash-commands
デフォルトでは、"response_type": "ephemeral"
が設定されていると書いてありますね。
サンプルコード
body
内で、response_type: 'in_channel'
を指定すればOKです。
Node.js
constrequestPromise=require('request-promise');constoptions={url:responseURL,// SlackへのレスポンスURLheaders:{'Content-type':'application/json'},body:{response_type:'in_channel',// ★ ここで in_channelを指定text:response// Slackへのレスポンス内容},json:true};res=requestPromise.post(options);