Documentation ¶
Overview ¶
Package wechat provides sending message ability on WeChat.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MessageType ¶
MessageType sets MsgType, like: TextType, MarkdownType, ImageType, NewsType and FileType.
Types ¶
type Message ¶
type Message struct { MessageType string `json:"msgtype"` Text *textMessage `json:"text,omitempty"` Markdown *markdownMessage `json:"markdown,omitempty"` Image *imageMessage `json:"image,omitempty"` News *newsMessage `json:"news,omitempty"` File *fileMessage `json:"file,omitempty"` }
Message reflects the message body request WeChat api.
type MsgType ¶
type MsgType int
MsgType indicates message format.
const ( // TextType indicates text message you will send. TextType MsgType = iota + 1 // MarkdownType indicates markdown message you will send. MarkdownType // ImageType indicates Image message you will send. ImageType // NewsType indicates news message you will send. NewsType // FileType indicates file message you will send. FileType )
type WeChat ¶
type WeChat struct {
// contains filtered or unexported fields
}
WeChat implements Sender which sends message WeChat.
func (*WeChat) Send ¶
Send sends message to WeChat which you have to provides io.Reader include message body, and few options which implements Option.
Example (File) ¶
package main import ( "log" "os" fw "github.com/LiangXianSen/firewheel" "github.com/LiangXianSen/firewheel/sender/wechat" ) func main() { fd, err := os.Open("../../testdata/report.csv") if err != nil { log.Fatal(err) } var sender fw.Sender key := "" webhook := "https://qyapi.weixin.qq.com/cgi-bin/webhook/send" sender = wechat.NewSender(webhook, key) if err = sender.Send( fd, wechat.MessageType(wechat.FileType), wechat.Filename("report.csv"), ); err != nil { log.Fatal(err) } }
Output:
Example (Image) ¶
package main import ( "log" "os" fw "github.com/LiangXianSen/firewheel" "github.com/LiangXianSen/firewheel/sender/wechat" ) func main() { fd, err := os.Open("../../testdata/timg.jpeg") if err != nil { log.Fatal(err) } var sender fw.Sender key := "" webhook := "https://qyapi.weixin.qq.com/cgi-bin/webhook/send" sender = wechat.NewSender(webhook, key) if err = sender.Send( fd, wechat.MessageType(wechat.ImageType), ); err != nil { log.Fatal(err) } }
Output:
Example (Markdown) ¶
package main import ( "log" "strings" fw "github.com/LiangXianSen/firewheel" "github.com/LiangXianSen/firewheel/sender/wechat" ) func main() { var sender fw.Sender key := "" webhook := "https://qyapi.weixin.qq.com/cgi-bin/webhook/send" sender = wechat.NewSender(webhook, key) if err := sender.Send( strings.NewReader("# test message"), wechat.MessageType(wechat.MarkdownType), ); err != nil { log.Fatal(err) } }
Output:
Example (News) ¶
package main import ( "log" "strings" fw "github.com/LiangXianSen/firewheel" "github.com/LiangXianSen/firewheel/sender/wechat" ) func main() { var sender fw.Sender key := "" webhook := "https://qyapi.weixin.qq.com/cgi-bin/webhook/send" sender = wechat.NewSender(webhook, key) if err := sender.Send( strings.NewReader(""), wechat.MessageType(wechat.NewsType), wechat.Article("No.1", "Coding commnunity", "github.com", "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606718584317&di=2546710d44d6582d9fe58bf18d2711a7&imgtype=0&src=http%3A%2F%2Foss.cyzone.cn%2F2016%2F0304%2F20160304022832427.png"), wechat.Article("No.2", "something else", "github.com", ""), wechat.Article("No.3", "last one", "github.com", ""), ); err != nil { log.Fatal(err) } }
Output:
Example (Text) ¶
package main import ( "log" "strings" fw "github.com/LiangXianSen/firewheel" "github.com/LiangXianSen/firewheel/sender/wechat" ) func main() { var sender fw.Sender key := "" webhook := "https://qyapi.weixin.qq.com/cgi-bin/webhook/send" sender = wechat.NewSender(webhook, key) if err := sender.Send( strings.NewReader("test message"), wechat.MessageType(wechat.TextType), wechat.Cue("@all"), wechat.Cue("18512345678"), ); err != nil { log.Fatal(err) } }
Output:
Click to show internal directories.
Click to hide internal directories.