dingtalkrobot

package
v0.0.0-...-4c3f971 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

README

钉钉自定义机器人

钉钉文档

使用

参考


rob := NewCustomRobot(
    WithSecureType(dingtalkrobot.KeyWord),
    WithAccessToken("xxxxx"))

rsp, err := rob.Send(NewTextMessage("【GM】hahaha"))
if err != nil {
    t.Fatal(err)
}
fmt.Printf("%#v", rsp)

Documentation

Index

Constants

View Source
const (
	KeyWord SecureType = iota
	Sign

	Custom RobotType = iota

	DingDingRobotAddr = `https://oapi.dingtalk.com/robot/send`
	ContentType       = `application/json; charset=utf-8`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

func NewConfig

func NewConfig(opts ...Option) *Config

func (Config) AccessToken

func (c Config) AccessToken() string

func (Config) Addr

func (c Config) Addr() string

func (Config) Secret

func (c Config) Secret() string

func (Config) SecureType

func (c Config) SecureType() SecureType

type LinkContent

type LinkContent struct {
	Text       string `json:"text,omitempty"`
	Title      string `json:"title,omitempty"`
	PicUrl     string `json:"picUrl,omitempty"`
	MessageUrl string `json:"messageUrl,omitempty"`
}

func (LinkContent) Apply

func (l LinkContent) Apply(msg *Message)

func (LinkContent) Type

func (l LinkContent) Type() string

type MarkdownContent

type MarkdownContent struct {
	Title string `json:"title,omitempty"`
	Text  string `json:"text,omitempty"`
}

Markdown 消息

func (MarkdownContent) Apply

func (m MarkdownContent) Apply(msg *Message)

func (MarkdownContent) Type

func (m MarkdownContent) Type() string

type Message

type Message struct {
	Typ string `json:"msgtype"`

	AT       *at             `json:"at,omitempty"`
	Text     TextContent     `json:"text,omitempty"`
	Link     LinkContent     `json:"link,omitempty"`
	Markdown MarkdownContent `json:"markdown,omitempty"`
	// contains filtered or unexported fields
}

基础消息体

func NewLinkMessage

func NewLinkMessage(text, title, picUrl, messageUrl string) *Message

func NewMarkdownMessage

func NewMarkdownMessage(text, title string) *Message

func NewMessage

func NewMessage() *Message

func NewTextMessage

func NewTextMessage(content string) *Message

func (*Message) AddAtMobiles

func (m *Message) AddAtMobiles(mobiles ...string)

func (*Message) Bytes

func (m *Message) Bytes() []byte

func (*Message) SetContent

func (m *Message) SetContent(content MessageContent)

func (*Message) SetIsAtAll

func (m *Message) SetIsAtAll(isAtAll bool)

func (*Message) String

func (m *Message) String() string

type MessageContent

type MessageContent interface {
	Type() string
	Apply(*Message)
}

消息类型接口

func NewLinkContent

func NewLinkContent(text, title, picUrl, messageUrl string) MessageContent

func NewMarkdownContent

func NewMarkdownContent(text, title string) MessageContent

func NewTextContent

func NewTextContent(content string) MessageContent

type Option

type Option interface {
	Apply(*Config)
}

type Response

type Response struct {
	Code    int    `json:"errcode"`
	Message string `json:"errmsg"`
}

响应

func DecodeResponse

func DecodeResponse(code io.ReadCloser) (*Response, error)

type Robot

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

func NewCustomRobot

func NewCustomRobot(opts ...Option) *Robot

func (*Robot) Send

func (rob *Robot) Send(msg *Message) (*Response, error)

type RobotType

type RobotType int

func (RobotType) Apply

func (s RobotType) Apply(config *Config)

type SecureType

type SecureType int

type TextContent

type TextContent struct {
	Content string `json:"content"`
}

纯文本消息

func (TextContent) Apply

func (t TextContent) Apply(m *Message)

func (TextContent) Type

func (t TextContent) Type() string

type WithAccessToken

type WithAccessToken string

func (WithAccessToken) Apply

func (at WithAccessToken) Apply(config *Config)

type WithAddr

type WithAddr string

func (WithAddr) Apply

func (addr WithAddr) Apply(config *Config)

type WithSecret

type WithSecret string

func (WithSecret) Apply

func (s WithSecret) Apply(config *Config)

type WithSecureType

type WithSecureType SecureType

func (WithSecureType) Apply

func (st WithSecureType) Apply(config *Config)

Jump to

Keyboard shortcuts

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