slack.message() 函数
slack.message() 向 Slack 频道发送一条消息并返回请求的 HTTP 响应代码。
该函数可以使用 chat.postMessage API 或 Slack webhook。
函数类型签名
(
channel: A,
color: string,
text: B,
?token: string,
?url: string,
) => int
有关更多信息,请参见 Function type signatures。
参数
网址
Slack API URL.
默认值是 https://slack.com/api/chat.postMessage。
如果使用Slack webhook API,该URL会在Slack webhook设置过程中提供。
令牌
Slack API 令牌。默认值是 ""。
如果使用Slack Webhook API,则不需要令牌。
频道
(必填) 要发送消息的Slack频道或用户。
文本
(必填) 消息文本。
颜色
(必填) Slack 消息颜色。
有效值:
- 好
- 警告
- 危险
- 任何十六进制 RGB 颜色代码
示例
使用 Slack webhook 发送消息到 Slack
import "slack"
slack.message(
url: "https://hooks.slack.com/services/EXAMPLE-WEBHOOK-URL",
channel: "#example-channel",
text: "Example slack message",
color: "warning",
)
使用 chat.postMessage API 向 Slack 发送消息
import "slack"
slack.message(
url: "https://slack.com/api/chat.postMessage",
token: "mySuPerSecRetTokEn",
channel: "#example-channel",
text: "Example slack message",
color: "warning",
)