通过 Slack Outgoing Webhooks 发送的消息中的 URI 用角括号括起来

URIs in messages sent via Slack Outgoing Webhooks are wrapped with corner brackets

我通过 Slack Outgoing Webhook 在 Slack 和我的自定义应用程序之间进行了集成。最近,我发现如果 Slack 消息包含一个 URI(并且这个 URI 在 Slack 中被识别为 URI)发送到我的 webhook 的 JSON 有这个 link 被角括号包围('<' 和 ' >').

那么,现在我有两个问题:

  1. 这是预期行为还是错误?
  2. 有什么方法可以禁用它吗?

遗憾的是,官方 Slack 文档不是很有帮助。

这是预期的行为。我认为没有办法禁用它。

您在上面提到的行为发生在 Slack 消息中包含一些格式化文本时。不仅对于 URI,对于频道、用户名、组等其他字符串,您也会遇到这些括号。您需要编写代码才能解析这些字符串。

好消息是这些是 well-defined 个字符串,它们总是遵循特殊的结构。您可以查阅 Slack 文档 here,了解更多信息。

  1. Detect all sub-strings matching <(.*?)>
  2. Within those sub-strings, format content starting with #C as a channel link
  3. Format content starting with @U or @W as a user mention
  4. Format content starting with !subteam as a user group mention
  5. Format content starting with ! according to the rules for special mentions
  6. For any other content within those sub-strings, format as a URL link
  7. Once the format has been determined, check for a pipe (|) - if present, use the text following the pipe as the label for the link or mention.