webhook

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WEBHOOK_TYPE_WEIXIN_WORK string = "企微机器人"
	WEBHOOK_TYPE_DINGDING    string = "钉钉机器人"
	WEBHOOK_TYPE_FEISHU      string = "飞书机器人"
	MESSAGE_TYPE_TEXT        string = "text"
	MESSAGE_TYPE_MARKDOWN    string = "markdown"
	MESSAGE_TYPE_IMAGE       string = "image"
)

Variables

View Source
var DICT_WEBHOOK_TYPE_TO_MESSAGE_TEMPLATE = map[string]map[string]map[string]any{
	WEBHOOK_TYPE_WEIXIN_WORK: {
		MESSAGE_TYPE_TEXT:     {"msgtype": "text", "text": map[string]string{"content": ""}},
		MESSAGE_TYPE_MARKDOWN: {"msgtype": "markdown", "markdown": map[string]string{"content": ""}},
		MESSAGE_TYPE_IMAGE:    {"msgtype": "image", "image": map[string]string{"base64": "", "md5": ""}},
	},
	WEBHOOK_TYPE_DINGDING: {
		MESSAGE_TYPE_TEXT:     {"msgtype": "text", "text": map[string]string{"content": ""}},
		MESSAGE_TYPE_MARKDOWN: {"msgtype": "markdown", "markdown": map[string]string{"title": "新消息", "text": ""}},
	},
	WEBHOOK_TYPE_FEISHU: {
		MESSAGE_TYPE_TEXT:     {"msg_type": "text", "content": map[string]string{"text": ""}},
		MESSAGE_TYPE_MARKDOWN: {"msg_type": "text", "content": map[string]string{"text": ""}},
	},
}
View Source
var DICT_WEBHOOK_TYPE_TO_SERVER_ADDRESS = map[string]string{
	WEBHOOK_TYPE_WEIXIN_WORK: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=",
	WEBHOOK_TYPE_DINGDING:    "https://oapi.dingtalk.com/robot/send?access_token=",
	WEBHOOK_TYPE_FEISHU:      "https://open.feishu.cn/open-apis/bot/v2/hook/",
}

Functions

func SendToDingDing

func SendToDingDing(api_key string, content map[string]any, proxy_address string) (err error)

func SendToFeiShu

func SendToFeiShu(api_key string, content map[string]any, proxy_address string) (err error)

func SendToWeiXinWork

func SendToWeiXinWork(api_key string, content map[string]any, proxy_address string) (err error)

Types

type OptionFunc

type OptionFunc func(*WebhookSender)

func WithMessageTitle

func WithMessageTitle(s string) OptionFunc

钉钉机器人的 Markdown 类型支持指定消息标题,不指定时默认使用“新消息”作为标题

func WithOptions

func WithOptions(options WebhookSender) OptionFunc

func WithProxyAddress

func WithProxyAddress(s string) OptionFunc

可指定代理地址,为空时不使用代理

func WithRequestHeaders

func WithRequestHeaders(m map[string]string) OptionFunc

可指定请求头,为空时使用默认请求头

func WithServerAddress

func WithServerAddress(s string) OptionFunc

可指定服务端地址,为空时使用 webhook 类型的默认地址

func WithWebhookType

func WithWebhookType(s string) OptionFunc

可指定 webhook 类型,为空时默认使用 企微机器人

type WebhookSender

type WebhookSender struct {
	// contains filtered or unexported fields
}

func New

func New(api_key string, options ...OptionFunc) *WebhookSender

func (*WebhookSender) SendMessage

func (webhook_sender *WebhookSender) SendMessage(content map[string]any) (err error)

func (*WebhookSender) SendMessageMarkdown

func (webhook_sender *WebhookSender) SendMessageMarkdown(content string) (err error)

推送Markdown类型消息

飞书机器人不支持Markdown格式降级为text类型
钉钉机器人的 Markdown 类型支持指定消息标题,不指定时默认使用“新消息”作为标题

func (*WebhookSender) SendMessageText

func (webhook_sender *WebhookSender) SendMessageText(content string) (err error)

推送Text类型消息

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL