slack-webhook

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Usage

使用方法

Simple Message

简单消息

Write to
/tmp/slack_request.json
:
json
{
  "text": "Hello, world."
}
Then run:
bash
curl -X POST $SLACK_WEBHOOK_URL -H "Content-type: application/json" -d @/tmp/slack_request.json
写入
/tmp/slack_request.json
json
{
  "text": "Hello, world."
}
然后运行:
bash
curl -X POST $SLACK_WEBHOOK_URL -H "Content-type: application/json" -d @/tmp/slack_request.json

With Formatting

带格式的消息

Write to
/tmp/slack_request.json
:
json
{
  "text": "*Bold* and _italic_ text"
}
Then run:
bash
curl -X POST $SLACK_WEBHOOK_URL -H "Content-type: application/json" -d @/tmp/slack_request.json
写入
/tmp/slack_request.json
json
{
  "text": "*Bold* and _italic_ text"
}
然后运行:
bash
curl -X POST $SLACK_WEBHOOK_URL -H "Content-type: application/json" -d @/tmp/slack_request.json

With Link

带链接的消息

Write to
/tmp/slack_request.json
:
json
{
  "text": "Check <https://example.com|this link>"
}
Then run:
bash
curl -X POST $SLACK_WEBHOOK_URL -H "Content-type: application/json" -d @/tmp/slack_request.json
写入
/tmp/slack_request.json
json
{
  "text": "Check <https://example.com|this link>"
}
然后运行:
bash
curl -X POST $SLACK_WEBHOOK_URL -H "Content-type: application/json" -d @/tmp/slack_request.json

With Blocks (Rich Layout)

带Blocks(富文本布局)的消息

Write to
/tmp/slack_request.json
:
json
{
  "text": "New review submitted",
  "blocks": [
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "Danny left the following review:"
      }
    },
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "<https://example.com|Overlook Hotel>\n:star:\nDoors had too many axe holes."
      }
    }
  ]
}
Then run:
bash
curl -X POST $SLACK_WEBHOOK_URL -H "Content-type: application/json" -d @/tmp/slack_request.json
写入
/tmp/slack_request.json
json
{
  "text": "New review submitted",
  "blocks": [
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "Danny left the following review:"
      }
    },
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "<https://example.com|Overlook Hotel>\n:star:\nDoors had too many axe holes."
      }
    }
  ]
}
然后运行:
bash
curl -X POST $SLACK_WEBHOOK_URL -H "Content-type: application/json" -d @/tmp/slack_request.json

With Fields

带字段的消息

Write to
/tmp/slack_request.json
:
json
{
  "text": "Deployment status",
  "blocks": [
    {
      "type": "section",
      "fields": [
        {
          "type": "mrkdwn",
          "text": "*Environment:*\nProduction"
        },
        {
          "type": "mrkdwn",
          "text": "*Status:*\nSuccess"
        }
      ]
    }
  ]
}
Then run:
bash
curl -X POST $SLACK_WEBHOOK_URL -H "Content-type: application/json" -d @/tmp/slack_request.json
写入
/tmp/slack_request.json
json
{
  "text": "Deployment status",
  "blocks": [
    {
      "type": "section",
      "fields": [
        {
          "type": "mrkdwn",
          "text": "*Environment:*\nProduction"
        },
        {
          "type": "mrkdwn",
          "text": "*Status:*\nSuccess"
        }
      ]
    }
  ]
}
然后运行:
bash
curl -X POST $SLACK_WEBHOOK_URL -H "Content-type: application/json" -d @/tmp/slack_request.json

Message Formatting

消息格式

SyntaxResult
*bold*
bold
_italic_
italic
~strike~
strike
`code`
code
\n
newline
<URL|text>
hyperlink
:emoji:
emoji
语法效果
*bold*
bold
_italic_
italic
~strike~
strike
`code`
code
\n
换行
<URL|text>
超链接
:emoji:
表情符号

Shell Escaping

Shell转义

Messages with
!
may fail due to shell history expansion. Use heredoc:
bash
curl -s -X POST $SLACK_WEBHOOK_URL -H "Content-type: application/json" -d @- << 'EOF'
{"text":"Deploy completed! :rocket:"}
EOF
包含
!
的消息可能会因Shell历史扩展而发送失败,请使用here文档:
bash
curl -s -X POST $SLACK_WEBHOOK_URL -H "Content-type: application/json" -d @- << 'EOF'
{"text":"Deploy completed! :rocket:"}
EOF

Response

响应

Success:
ok
(HTTP 200)
Errors:
  • invalid_payload
    - Malformed JSON
  • no_text
    - Missing
    text
    field
  • no_service
    - Webhook disabled or invalid
  • channel_not_found
    - Channel deleted
  • channel_is_archived
    - Channel archived
  • action_prohibited
    - Admin restriction
成功:返回
ok
(HTTP 200)
错误情况:
  • invalid_payload
    - JSON格式错误
  • no_text
    - 缺少
    text
    字段
  • no_service
    - Webhook已禁用或无效
  • channel_not_found
    - 频道已删除
  • channel_is_archived
    - 频道已归档
  • action_prohibited
    - 管理员限制

Limitations

限制

  • One webhook = one channel only
  • Cannot override username or icon (set in app config)
  • Send only (no reading messages)
  • Cannot delete messages after posting
  • Rate limit: 1 message/second
For full API access, use the
slack
skill with Bot Token.
  • 一个Webhook仅对应一个频道
  • 无法覆盖用户名或图标(需在应用配置中设置)
  • 仅支持发送消息(无法读取消息)
  • 发布后无法删除消息
  • 速率限制:每秒1条消息
如需完整API访问权限,请使用带有Bot Token的
slack
技能。

API Reference

API参考