botclient

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: MIT Imports: 3 Imported by: 0

README

botclient

wx work bot client

func TestText(t *testing.T) {
	msg := &TextMessage{
		Content:       "hello",
		MentionedList: []string{All},
	}
	bot := New("98fcbeba-ce84-451b-8b6d-ae162d769fd6")
	if err := bot.Send(msg); err != nil {
		t.Error(err)
	}
}

func TestUploadMedia(t *testing.T) {
	bot := New("98fcbeba-ce84-451b-8b6d-ae162d769fd6")
	mid, err := bot.UploadMedia("go.mod")
	if err != nil {
		t.Error(err)
	}
	fmt.Println(mid)
}

func TestImage(t *testing.T) {
	body, err := os.ReadFile("1.png")
	if err != nil {
		panic(err)
	}

	hash := md5.New()
	hash.Write(body)
	md5Str := hex.EncodeToString(hash.Sum(nil))
	base64Str := base64.StdEncoding.EncodeToString(body)

	bot := New("98fcbeba-ce84-451b-8b6d-ae162d769fd6")
	msg := &ImageMessage{
		Base64: base64Str,
		Md5:    md5Str,
	}
	if err := bot.Send(msg); err != nil {
		t.Error(err)
	}
}

func TestNews(t *testing.T) {
	bot := New("98fcbeba-ce84-451b-8b6d-ae162d769fd6")
	msg := &NewsMessage{}
	msg.AddArticle(NewsMessageArticle{
		Title:  "test",
		URL:    "https://github.com/duke-git/lancet/blob/main/README_zh-CN.md",
		PicURL: "https://picb9.photophoto.cn/39/872/39872639_1.jpg",
	})
	if err := bot.Send(msg); err != nil {
		t.Error(err)
	}
}

func TestFile(t *testing.T) {
	bot := New("98fcbeba-ce84-451b-8b6d-ae162d769fd6")
	mid, err := bot.UploadMedia("go.mod")
	if err != nil {
		panic(err)
	}
	msg := &FileMessage{
		MediaId: mid,
	}
	if err := bot.Send(msg); err != nil {
		t.Error(err)
	}
}

Documentation

Index

Constants

View Source
const (
	Text     = "text"
	Markdown = "markdown"
	Image    = "image"
	News     = "news"
	File     = "file"
	All      = "@all"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FileMessage

type FileMessage struct {
	MediaId string `json:"media_id"`
}

func (*FileMessage) GetType

func (file *FileMessage) GetType() string

type ImageMessage

type ImageMessage struct {
	Base64 string `json:"base64"`
	Md5    string `json:"md5"`
}

func (*ImageMessage) GetType

func (image *ImageMessage) GetType() string

type MarkdownMessage

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

func (*MarkdownMessage) GetType

func (markdown *MarkdownMessage) GetType() string

type Message

type Message interface {
	GetType() string
}

type NewsMessage

type NewsMessage struct {
	Articles []NewsMessageArticle `json:"articles"`
}

func (*NewsMessage) AddArticle

func (news *NewsMessage) AddArticle(article ...NewsMessageArticle)

func (*NewsMessage) GetType

func (news *NewsMessage) GetType() string

type NewsMessageArticle

type NewsMessageArticle struct {
	Title       string `json:"title"`
	Description string `json:"description"`
	URL         string `json:"url"`
	PicURL      string `json:"picurl"`
}

type TextMessage

type TextMessage struct {
	Content             string   `json:"content"`
	MentionedList       []string `json:"mentioned_list,omitempty"`
	MentionedMobileList []string `json:"mentioned_mobile_list,omitempty"`
}

func (*TextMessage) GetType

func (text *TextMessage) GetType() string

type WxWorkBot

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

func New

func New(key string) *WxWorkBot

func (*WxWorkBot) Send

func (bot *WxWorkBot) Send(message Message) error

func (*WxWorkBot) UploadMedia

func (bot *WxWorkBot) UploadMedia(filepath string) (mediaId string, err error)

func (*WxWorkBot) UploadMediaReader added in v0.0.3

func (bot *WxWorkBot) UploadMediaReader(fileName string, read io.Reader) (mediaId string, err error)

Jump to

Keyboard shortcuts

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