slack.message() 函数
slack.message()
向 Slack 频道发送一条消息,并返回请求的 HTTP 响应代码。
该函数可以使用 chat.postMessage
API 或 Slack webhook。
函数类型签名
(
channel: A,
color: string,
text: B,
?token: string,
?url: string,
) => int
有关更多信息,请参阅 函数类型签名。
参数
url
Slack API URL。默认为 https://slack.com/api/chat.postMessage
。
如果使用 Slack webhook API,则此 URL 在 Slack webhook 设置过程中提供。
token
Slack API 令牌。默认为 ""
。
如果使用 Slack Webhook API,则不需要令牌。
channel
(必需) 要向其发送消息的 Slack 频道或用户。
text
(必需) 消息文本。
color
(必需) Slack 消息颜色。
有效值
- good
- warning
- danger
- 任何十六进制 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",
)
此页是否对您有帮助?
感谢您的反馈!