| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A WeCom (WeChat Work) bot client library for Go, using go-http-client for HTTP operations.
go get github.com/futuretea/go-wecom-botpackage main
import (
"log"
"github.com/futuretea/go-wecom-bot"
"github.com/futuretea/go-wecom-bot/text"
)
func main() {
// Create bot instance
bot := wecombot.New("your-bot-key")
// Send text message
msg := text.New("Hello, WeCom Bot!")
if err := bot.Send(msg); err != nil {
log.Fatal(err)
}
}import "github.com/futuretea/go-wecom-bot/text"
// Simple text
msg := text.New("Hello, World!")
// Mention users
msg.WithMention("userid1", "userid2", "all")
// Mention by mobile
msg.WithMentionMobile("13800138000")
// Chaining
msg := text.New("Hello @all").
WithMention("all").
WithMentionMobile("13800138000")import "github.com/futuretea/go-wecom-bot/markdown"
content := `## System Notification
**Time**: 2024-01-15 10:30:00
**Level**: Warning
[View Details](https://example.com)`
msg := markdown.New(content)import "github.com/futuretea/go-wecom-bot/image"
// base64: base64 encoded image content
// md5: md5 hash of the original image content
msg := image.New(base64EncodedString, md5Hash)import "github.com/futuretea/go-wecom-bot/news"
msg := news.New().
AddArticle("Title 1", "Description 1", "https://example.com/1", "https://example.com/pic1.jpg").
AddArticle("Title 2", "Description 2", "https://example.com/2", "https://example.com/pic2.jpg")import "github.com/futuretea/go-wecom-bot/templatecard"
card := templatecard.NewTextNotice().
WithSource("https://example.com/icon.png", "WeCom", templatecard.SourceDescColorBlue).
WithMainTitle("Onboarding Approval", "You have a pending approval").
WithEmphasisContent("100", "Pending Count").
WithSubTitle("Please process in time").
WithCardAction(templatecard.ActionTypeURL, "https://work.weixin.qq.com").
AddHorizontalContent("Applicant", "John Doe", templatecard.HorizontalContentTypeText).
AddJump(templatecard.JumpTypeURL, "View Details", "https://work.weixin.qq.com")import "github.com/futuretea/go-wecom-bot/templatecard"
card := templatecard.NewNewsNotice().
WithSource("https://example.com/icon.png", "WeCom", templatecard.SourceDescColorGreen).
WithMainTitle("WeCom Update", "New template card feature").
WithCardImage("https://example.com/news.jpg", 1.3).
WithCardAction(templatecard.ActionTypeURL, "https://work.weixin.qq.com")// Quick text
bot.SendText("Hello!")
// Quick markdown
bot.SendMarkdown("## Title\nContent")
// Quick image
bot.SendImage(base64, md5)
// Quick news
bot.SendNews(news.Article{Title: "...", Description: "...", URL: "...", PicURL: "..."})
// Quick template card
bot.SendTemplateCard(card)media, err := bot.UploadMedia("filename.pdf", fileBytes)
if err != nil {
log.Fatal(err)
}
// Use media.MediaID to reference the file in template cardsimport (
httpclient "github.com/futuretea/go-http-client"
)
config := &httpclient.Config{
BaseURL: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send",
Timeout: 10 * time.Second,
}
client := httpclient.NewClient(config,
httpclient.WithRetry(3, 200*time.Millisecond, 10*time.Second),
)
bot := wecombot.New("your-key", wecombot.WithHTTPClient(client))Enable HTTP request/response logging for troubleshooting:
bot := wecombot.New("your-key", wecombot.WithDebug())Output example:
> POST /cgi-bin/webhook/send?key=xxx HTTP/1.1
> Content-Type: application/json
>
{"msgtype":"text","text":{"content":"Hello"}}
< HTTP/1.1 200 OK
< Content-Type: application/json
<
{"errcode":0,"errmsg":"ok"}
WithBaseURL keeps the existing behavior: it sets the complete send webhook endpoint only.
bot := wecombot.New("your-key",
wecombot.WithBaseURL("https://custom-proxy.example.com/webhook"),
)Use WithAPIBaseURL when an internal proxy exposes both WeCom webhook APIs under one root. The library appends the send and upload paths, preserving any path prefix in the root.
bot := wecombot.New("your-key",
wecombot.WithAPIBaseURL("https://custom-proxy.example.com/wecom"),
)WithAPIBaseURL controls both message sends and file uploads. Existing WithHTTPClient behavior remains unchanged: it applies to message sends only.
go-wecom-bot/ ├── bot.go # Main Bot client ├── types/ # Common types ├── text/ # Text message ├── markdown/ # Markdown message ├── image/ # Image message ├── news/ # News message └── templatecard/ # Template card message
MIT License
| Back | FazBrowse Home | New Git URL |