5

我正在编写一个自定义的 slack 命令,该命令实现了一个类似界面的任务管理器(我知道......那里有很多:-),我使用 odesk/upwork 的界面来外包我的微任务 :-))。

无论如何,我非常喜欢 /remind 命令如何在其输出中包含 Complete Delete 等链接,以促进与输入命令的用户的后续交互,我正在尝试找出如何做同样的技巧。

到目前为止,我的想法是在我的输出中包含...的链接,GET /slack-link?method=POST&token=xxx&team_id=xx&command=.. 即在他们的查询字符串中携带 slack 从普通自定义命令产生的完整 json 有效负载。slack-link充当“代理”,其唯一作用是将 POST 提交回我的正常松弛端点。我什至可以为这些命令链接重用相同的 response_url。

我还没有尝试过,但我认为这些 URL 只会打开另一个窗口,这样路径就不会完全正常工作......

有没有人尝试过这样的事情?

4

2 回答 2

4

As you've learned, those are currently only available to built-in commands. However, as I was curious and wanted to know how those are done, I looked in the API and found out that the URLs are just formatted normally but have a special "protocol":

You asked me to remind you to “test”.
​_<slack-action://BSLACKBOT/reminders/complete/D01234567/1234//0/0/5678|Mark as complete>
or remind me later: <slack-action://BSLACKBOT/reminders/snooze/D01234567/1234//0/0/5678/15|15 mins> [...]

Clicking on such a link results in an API request to method chat.action, with the following parameters:

bot: BSLACKBOT
payload: reminders/complete/D01234567/1234//0/0/5678
token: xoxs-tokenhere-nowayiampostingithere

So it looks like those URLs have three parts:

<slack-action://BSLACKBOT/reminders/complete/[...]|Mark as complete>
  1. slack-action://: the "protocol" like prefix to let Slack know this is a chat action URL.
  2. BSLACKBOT: the bot which (who?) will receive the payload. Can only be a bot user and the ID must start with B, or the API request will fail with invalid_bot.
  3. the rest of the URL: the payload that gets passed to the bot. It doesn't look like this is parsed nor handled specially by Slack.

This is actually not a new feature, since they used to have API URLs back in late 2013 or early 2014 (I don't remember precisely) which they removed for "security reasons".

It could be interesting to see if we can use chat actions with custom bots, and if so, what we could do with it.

于 2015-12-23T22:47:38.490 回答
3

我从 Slack 支持人员那里得到了答案:

关于您最初的问题:目前 Slack 不提供在我们的自定义集成中嵌入“操作”链接的能力。目前只有像 /remind 这样的内置功能可以使用这些功能。对于外部服务,您需要链接到在外部 Web 浏览器中打开的 URL。

我们确实希望将来为自定义集成提供类似的功能,允许交互式消息。

谢谢,

于 2015-12-16T04:06:27.697 回答