slack-webhook
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUsage
使用方法
Simple Message
简单消息
Write to :
/tmp/slack_request.jsonjson
{
"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.jsonjson
{
"text": "Hello, world."
}然后运行:
bash
curl -X POST $SLACK_WEBHOOK_URL -H "Content-type: application/json" -d @/tmp/slack_request.jsonWith Formatting
带格式的消息
Write to :
/tmp/slack_request.jsonjson
{
"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.jsonjson
{
"text": "*Bold* and _italic_ text"
}然后运行:
bash
curl -X POST $SLACK_WEBHOOK_URL -H "Content-type: application/json" -d @/tmp/slack_request.jsonWith Link
带链接的消息
Write to :
/tmp/slack_request.jsonjson
{
"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.jsonjson
{
"text": "Check <https://example.com|this link>"
}然后运行:
bash
curl -X POST $SLACK_WEBHOOK_URL -H "Content-type: application/json" -d @/tmp/slack_request.jsonWith Blocks (Rich Layout)
带Blocks(富文本布局)的消息
Write to :
/tmp/slack_request.jsonjson
{
"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.jsonjson
{
"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.jsonWith Fields
带字段的消息
Write to :
/tmp/slack_request.jsonjson
{
"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.jsonjson
{
"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.jsonMessage Formatting
消息格式
| Syntax | Result |
|---|---|
| bold |
| italic |
| |
| |
| newline |
| hyperlink |
| emoji |
| 语法 | 效果 |
|---|---|
| bold |
| italic |
| |
| |
| 换行 |
| 超链接 |
| 表情符号 |
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:"}
EOFResponse
响应
Success: (HTTP 200)
okErrors:
- - Malformed JSON
invalid_payload - - Missing
no_textfieldtext - - Webhook disabled or invalid
no_service - - Channel deleted
channel_not_found - - Channel archived
channel_is_archived - - Admin restriction
action_prohibited
成功:返回 (HTTP 200)
ok错误情况:
- - JSON格式错误
invalid_payload - - 缺少
no_text字段text - - Webhook已禁用或无效
no_service - - 频道已删除
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 skill with Bot Token.
slack- 一个Webhook仅对应一个频道
- 无法覆盖用户名或图标(需在应用配置中设置)
- 仅支持发送消息(无法读取消息)
- 发布后无法删除消息
- 速率限制:每秒1条消息
如需完整API访问权限,请使用带有Bot Token的 技能。
slackAPI Reference
API参考
- Webhooks Guide: https://docs.slack.dev/messaging/sending-messages-using-incoming-webhooks
- Block Kit Builder: https://app.slack.com/block-kit-builder
- Message Formatting: https://docs.slack.dev/messaging/formatting-message-text