要实现功能:
- 企微机器人提醒
- 机器人数量不一定
- 机器人提醒企微有限制 一分钟不能超过20条
准备好发送markdown消息的方法
type RobotRsp struct {
ErrCode int `json:"errcode"`
ErrMsg string `json:"errmsg"`
}
type RobotMsg struct {
Msgtype string `json:"msgtype"`
Text RobotContent `json:"text"`
Markdown RobotContent `json:"markdown"`
}
type RobotContent struct {
Content string `json:"content"`
}
func RobotMarkdownMsg(content string, url string) {
var rspInfo = rsp.RobotRsp{}
var robotMsg = req.RobotMsg{
Msgtype: "markdown",
Markdown: req.RobotContent{
Content:content,
},
}
_ = ApiPost(url, &rspInfo, robotMsg, time.Second * 3)
if rspInfo.ErrCode != 0 {
fmt.Printf("RobotMsg markdown信息发送失败:%#v \n", rspInfo)
}
}
将发送消息的Service加好
type RobotMsgService struct {
ImpService
UrlsMap map[string]*RobotTimer
mtx sync.Mutex
MaxContentLen int
}
type RobotTimer st

本文介绍如何构建一个可扩展的企微机器人,支持批量提醒功能,同时遵循每分钟不超过20条的限制。通过Markdown消息格式和定时任务管理发送,确保高效并发且遵守平台规则。
最低0.47元/天 解锁文章
712

被折叠的 条评论
为什么被折叠?



