doudao9896 2017-07-06 19:56
浏览 41
已采纳

Slack Slash命令 - 不在私有通道或直接消息中工作

I have programmed several slash commands that show a response in public channels without any problems, but they don't show any response in private channels or direct messages.

As shown below, I am using the in_channel response type. Is there any other response type I can use or a workaround so that it works everywhere?

$data = array(
    "username" => "My_user",
    "channel" => $channel_id,
    "response_type" => "in_channel",
    "text" => $text,
    "mrkdwn" => true,
    "icon_url" => $icon_url

);

$json_string = json_encode($data);
$slack_call = curl_init($slack_webhook_url);
curl_setopt($slack_call, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($slack_call, CURLOPT_POSTFIELDS, $json_string);    
curl_setopt($slack_call, CURLOPT_CRLF, true);
curl_setopt($slack_call, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($slack_call, CURLOPT_HTTPHEADER, array(                                                                          
    "Content-Type: application/json",
    "Content-Length: " . strlen($json_string))
);                                                                                                                   
$result = curl_exec($slack_call);
curl_close($slack_call);

Thanks in advance!

  • 写回答

2条回答 默认 最新

  • duanji1482 2017-07-06 23:54
    关注

    That does not look like the right approach.

    Responding to slash commands

    For responding to a slash command you must not send a new message back (e.g. via webhook as in your code example). Instead just respond to the request from Slack with the content of your message.

    Example

    $message = array (
        'response_type' => 'in_channel',
        'text' => $text
        );
    
    header ('content-type: application/json');
    echo json_encode ($message);
    

    that is all you need.

    response_type defines if the response can be seen by all members of a channel "in_channel" or only by the issuer of the slash command "ephemeral"

    Please see the official documentation for more details and options.

    Sending additional messages

    You can of course also send a message from your script in response to the slash command. However, if you want to send a message to a private channel please note that the slash command request from Slack will not include the correct channel ID if it is used in a non-public channel. I don't think there is currently any solution or workaround for this.

    You can however always send a direct message to the user by using the ID of the user as channel ID.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问为什么我配置IPsec后PC1 ping不通 PC2,抓包出来数据包也并没有被加密
  • ¥200 求博主教我搞定neo4j简易问答系统,有偿
  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 数学建模数学建模需要