关于 node.js:Slack 斜杠命令 – 显示用户输入的文本?

Slack slash commands - show user-entered text?

我正在使用 slack slash commands API,到目前为止,它可以与我的机器人 (https://github.com/jesseditson/slashbot) 完美配合,除了一件事:

在其他斜线集成中(例如 giphy),当用户键入斜线命令时,该命令将输出到公共聊天,然后发布响应:

giphy

这似乎可以通过任何 giphy 用于集成的方式来实现,这给我留下了一些问题:

  • giphy 是使用私有 API,还是我错过了模拟这种行为的正确 API?

  • 是否有我错过的设置允许这样做?

我正在使用 node.js,但我更感兴趣的是这是否可能,语言除外。

作为旁注,我意识到我可以使用 Bot API 或实时消息传递 API 来实现类似的功能,但没有斜线 - 但是,我真的很喜欢斜线命令附带的文档选项和自动完成功能,所以这就是我对这个问题的追求是什么。


我最近遇到了这个问题,甚至遇到了这个问题。答案分布在斜杠命令文档中的两个地方。在 \\'"In Channel" 与 "Ephemeral" 响应\\' 标题下:

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.

然后,当谈到延迟响应(来自节点服务器的请求)时:

The only user-facing difference between immediate responses and delayed responses is that"in channel" delayed responses will not include the initial command sent by the user. To echo the command back to the channel, you'll still need to provide a response to Slack's original visit to your invocation URL.

因此,在您对机器人所在服务器的初始请求结束时,您会希望发送一个类似于

的响应

response.send({"response_type":"in_channel"});

将回显 /command。不久之后,当图像获取请求的响应返回时,发布到 response_url 会将有效负载发送回 slack,并将在回显的 /command 下打印。


来自 Slack 的 /Command API 文档:

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"
}
]
}

我认为您需要将 response_type 设置为 "in_channel" 以允许其他用户看到响应。


我认为这与"立即响应"和"延迟响应"的区别有关。

当我通过 cURL 发送消息时,它不显示斜杠命令 \\'in channel\\'。我发现,如果我只包含 header(\\'content-type header: application/json\\'),并使用包含 \\'in_channel\\' 的 json 有效负载回显我的响应,斜杠命令就会出现。无需 API!

示例:

1
2
3
4
5
6
7
$reply ="Whatever you want";
    $data = array(
       "response_type"=>"in_channel",
       "text"=>$repy,
        );
    header('Content-Type: application/json');
    echo json_encode($data);

希望对您有所帮助,这是我的第一篇文章,如果我违反了 stackoverflow 的任何潜规则,请保持温和。


不幸的是,Slack 目前不提供将 /command 回显到频道的选项,/giphy 是一个独特的内部集成。

目前唯一的选择是创建一个 Slack API 应用程序并让您的用户单独进行身份验证。在使用 /command 后,使用 chat.postMessage 将原始 /command message 发布回频道,然后发布您的 Incoming webhook 消息。