github.com/fumiama/NanoBot@v0.0.0-20231122134259-c22d8183efca/openapi_v2_message.go (about) 1 package nano 2 3 import ( 4 "strconv" 5 6 "github.com/sirupsen/logrus" 7 ) 8 9 type MessageType int 10 11 const ( 12 MessageTypeText MessageType = iota 13 MessageTypeTextImage 14 MessageTypeMarkdown 15 MessageTypeArk 16 MessageTypeEmbed 17 MessageTypeUnk1 18 MessageTypeUnk2 19 MessageTypeMedia 20 ) 21 22 func (mt2 MessageType) String() string { 23 switch mt2 { 24 case MessageTypeText: 25 return "文本" 26 case MessageTypeTextImage: 27 return "图文混排" 28 case MessageTypeMarkdown: 29 return "MD" 30 case MessageTypeArk: 31 return "模版" 32 case MessageTypeEmbed: 33 return "嵌入" 34 case MessageTypeMedia: 35 return "富媒体" 36 default: 37 return "未知类型" + strconv.Itoa(int(mt2)) 38 } 39 } 40 41 // PostMessageToQQUser 向 openid 指定的用户发送消息 42 // 43 // https://bot.q.qq.com/wiki/develop/api-231017/server-inter/message/send-receive/send.html#%E5%8D%95%E8%81%8A 44 func (bot *Bot) PostMessageToQQUser(id string, content *MessagePost) (*Message, error) { 45 logrus.Infoln(getLogHeader(), "<= [Q]单:", id+",", content) 46 return bot.postMessageTo("/v2/users/"+id+"/messages", content) 47 } 48 49 // PostMessageToQQGroup 向 openid 指定的群发送消息 50 // 51 // https://bot.q.qq.com/wiki/develop/api-231017/server-inter/message/send-receive/send.html#%E7%BE%A4%E8%81%8A 52 func (bot *Bot) PostMessageToQQGroup(id string, content *MessagePost) (*Message, error) { 53 logrus.Infoln(getLogHeader(), "<= [Q]群:", id+",", content) 54 return bot.postMessageTo("/v2/groups/"+id+"/messages", content) 55 }