Documentation ¶
Index ¶
- Constants
- func IsBotBeenAt(msg *UserMessage) bool
- func IsGroupMessage(userName string) bool
- func SplitAtContent(msgContent string) string
- type BotServer
- type ChatBot
- func (bot *ChatBot) Close()
- func (bot *ChatBot) DelGroupMembers(group string, members []string) ([]string, error)
- func (bot *ChatBot) DownloadEmoji(xml string) (string, error)
- func (bot *ChatBot) DownloadPic(xml string) (*DownloadImageResponse, error)
- func (bot *ChatBot) DownloadVideo(xml string) (*DownloadVideoResponse, error)
- func (bot *ChatBot) DownloadVoice(msgID int64, xml string) (*DownloadVoiceResponse, error)
- func (bot *ChatBot) ParseEmojiXML(xml string) (md5, length string, err error)
- func (bot *ChatBot) Run()
- func (bot *ChatBot) SendEmoji(toUser, emojiMd5, emojiLen string) error
- func (bot *ChatBot) SendMiniProgram(req *SendMiniProgramRequest) error
- func (bot *ChatBot) SendPic(toUser, imgUrl string) error
- func (bot *ChatBot) SendText(toUser, content string, atList []string) error
- func (bot *ChatBot) SendVideo(toUser, videoUrl, thumbUrl string) error
- func (bot *ChatBot) SendVoice(toUser, url string) error
- func (bot *ChatBot) Use(plugin ...Plugin)
- type DelGroupRequest
- type DelGroupResponse
- type DownloadImageRequest
- type DownloadImageResponse
- type DownloadVideoRequest
- type DownloadVideoResponse
- type DownloadVoiceRequest
- type DownloadVoiceResponse
- type GroupBase
- type GroupBotEvent
- type GroupEvent
- type MemberBase
- type Plugin
- type PushMessage
- type PushMsgType
- type SendEmojiRequest
- type SendEmojiResponse
- type SendMiniProgramRequest
- type SendMiniProgramResponse
- type SendPicRequest
- type SendPicResponse
- type SendTextRequest
- type SendTextResponse
- type SendVideoRequest
- type SendVideoResponse
- type SendVoiceRequest
- type SendVoiceResponse
- type UserMessage
- type WsServer
Constants ¶
const ( MsgTypeText = 1 // 文本消息 MsgTypeImg = 3 // 图片消息 MsgTypeVoice = 34 // 语音消息 MsgTypeVideo = 43 // 视频消息 MsgTypeEmoji = 47 // 表情动图消息 MsgTypeApplet = 49 // 小程序 )
收到的转发消息具体分类
const ( RoleMember = 1 + iota RoleAdmin RoleOwner )
Variables ¶
This section is empty.
Functions ¶
func SplitAtContent ¶
SplitAtContent 分割包含@的消息内容 例如 @小明 你吃饭了么 其中消息体中间会有个"空格",这个可能是个特殊字符,也可能是个真的空格
Types ¶
type BotServer ¶
type BotServer struct {
// contains filtered or unexported fields
}
BotServer 调用机器人http接口的服务 主要用于基本的消息发送
type ChatBot ¶
type ChatBot struct {
// contains filtered or unexported fields
}
机器人实例
func (*ChatBot) DelGroupMembers ¶
DelGroupMembers 删除群成员
func (*ChatBot) DownloadEmoji ¶
DownloadEmoji 下载表情或者动态图片 注意这个方法只能提取表情的下载地址不能用于直接发送 发送(转发)表情需要用拿到的xml中的md5和len字段发送,可以使用ParseEmojiXML方法来获取
func (*ChatBot) DownloadPic ¶
func (bot *ChatBot) DownloadPic(xml string) (*DownloadImageResponse, error)
DownloadPic 下载图片
func (*ChatBot) DownloadVideo ¶
func (bot *ChatBot) DownloadVideo(xml string) (*DownloadVideoResponse, error)
DownloadVideo 下载视频
func (*ChatBot) DownloadVoice ¶
func (bot *ChatBot) DownloadVoice(msgID int64, xml string) (*DownloadVoiceResponse, error)
DownloadVoice 下载音频
func (*ChatBot) ParseEmojiXML ¶
ParseEmojiXML 解析emoji表情中的md5和len字段
func (*ChatBot) SendEmoji ¶
SendEmoji 发送表情动图 toUser 接收人微信号 emojiMd5 从收到的xml中可以解析md5字段 emojiLen 从收到的xml可以解析len字段
func (*ChatBot) SendMiniProgram ¶
func (bot *ChatBot) SendMiniProgram(req *SendMiniProgramRequest) error
SendMiniProgram 发送小程序 toUser 接收人微信号/ID thumbUrl 缩略图地址 title 标题 des 描述 url 地址 sourceUserName 来源用户名 sourceDisplayName 来源显示名 username 用户名 appId 小程序AppId type 类型 version 版本 iconUrl 图标地址 pagePath 启动页
func (*ChatBot) SendText ¶
SendText 发送文本形式的消息 @toUser 接收人微信号,一般为机器人推送过来的消息发送人,即你自己 @content 文本内容,如果有人被@需要填写对方昵称 @atList 被@人列表,这里填写的是对方微信号
func (*ChatBot) SendVideo ¶
SendVideo 发送视频 @toUser 接收人微信号 @videoUrl 视频网络地址 @thumbUrl 封面缩略图地址 视频发送必须有封面图,如果需要根据视频内容截取封面 可以自行搜索ffmpeg相关的资料
type DelGroupRequest ¶
type DelGroupRequest struct { Group string `json:"chatroom"` // 群号 MemberList []string `json:"memberList"` // 删除人员 }
删除群成员
type DelGroupResponse ¶
type DelGroupResponse struct {
DelMemberList []string `json:"delMemberList"`
}
type DownloadImageResponse ¶
type DownloadVideoResponse ¶
type DownloadVoiceRequest ¶
type DownloadVoiceRequest struct { NewMsgId int64 `json:"newMsgId"` // 服务端ID XML string `json:"xml"` // 内容xml }
下载语音
type DownloadVoiceResponse ¶
type GroupBase ¶
type GroupBase struct { GroupUserName string `json:"groupUserName"` GroupNickName string `json:"groupNickName"` GroupHeadImg string `json:"groupHeadImg"` }
群基本信息
type GroupBotEvent ¶
type GroupBotEvent struct { // 事件id Event GroupEvent `json:"event"` // 事件中文提示 EventText string `form:"eventText"` // 群信息 Group GroupBase `json:"group"` // 变动的群成员 Members []MemberBase `json:"members"` }
接收到的群内事件
type GroupEvent ¶
type GroupEvent int
const ( // 机器人被邀请进群 GroupEventInvited GroupEvent = 100000 + iota // 机器人被踢出群 GroupEventKicked // 群内有新用户加群 GroupEventNewMember // 群内有用户离开 GroupEventMemberQuit )
type MemberBase ¶
type MemberBase struct { UserName string `json:"userName"` NickName string `json:"nickName"` HeadImg string `json:"headImg"` }
成员基本信息
type PushMessage ¶
type PushMessage struct { MsgType PushMsgType `json:"msgType"` Data json.RawMessage `json:"data"` }
收到的推送消息统一格式 根据msgType字段来区别消息类型 data为具体的消息内容
type PushMsgType ¶
type PushMsgType int
const ( // 机器人收到的用户信息、群信息 // 包括文本、图片、音频等多种类型 CusMsgTypeUser PushMsgType = 10000 + iota // 群事件消息 // 包括群内成员变动、机器人加入和退出群 CusMsgTypeGroupEvent )
自定义的消息类型,在整个消息体的最外围,即外层的msgType字段 用于区分是普通的聊天消息还是群内事件等
type SendEmojiRequest ¶
type SendEmojiRequest struct { ToUser string `json:"toUser"` // 发送对象 EmojiMd5 string `json:"emojiMd5"` // 表情md5值 GifUrl string `json:"gifUrl"` // 动图地址,和md5和len互斥,不为空时候上传动图 EmojiTotalLen int64 `json:"emojiTotalLen"` // 表情长度 }
发送表情
type SendEmojiResponse ¶
type SendMiniProgramRequest ¶
type SendMiniProgramRequest struct { ToUser string `json:"toUser"` // 接收人微信号/ID ThumbUrl string `json:"thumbUrl"` // 缩略图地址 Title string `json:"title"` // 标题 Des string `json:"des"` // 描述 Url string `json:"url"` // 地址 SourceUserName string `json:"sourceUserName"` // 来源用户名 SourceDisplayName string `json:"sourceDisplayName"` // 来源显示名 Username string `json:"username"` // 用户名 AppId string `json:"appid"` // 小程序 APPID Type int `json:"type"` // 类型 Version int `json:"version"` // 版本 IconUrl string `json:"iconUrl"` // 图标地址 PagePath string `json:"pagePath"` // 启动页 }
发送小程序
type SendMiniProgramResponse ¶
type SendPicRequest ¶
type SendPicRequest struct { ToUser string `json:"toUser"` // 发送对象 ImgUrl string `json:"imgUrl"` // 图片地址 }
发送图片
type SendPicResponse ¶
type SendTextRequest ¶
type SendTextRequest struct { ToUser string `json:"toUser"` // 发送对象 AtList []string `json:"atList"` // 群内at的人微信号 Content string `json:"content"` // 发送内容 存在at时候必须有@xxx标识,xxx为对方昵称 }
发送文本
type SendTextResponse ¶
type SendVideoRequest ¶
type SendVideoRequest struct { ToUser string `json:"toUser"` // 发送对象 VideoUrl string `json:"videoUrl"` // 视频地址 VideoThumbUrl string `json:"videoThumbUrl"` // 视频缩略图地址 }
发送视频
type SendVideoResponse ¶
type SendVoiceRequest ¶
type SendVoiceRequest struct { ToUser string `json:"toUser"` // 发送对象 SilkUrl string `json:"silkUrl"` // 语音链接 }
发送语音
type SendVoiceResponse ¶
type UserMessage ¶
type UserMessage struct { NewMsgID int64 `json:"newMsgId"` // 消息id,在下载语音时候会用到 FromUser string `json:"fromUser"` AtList []string `json:"atList"` CreateTime int `json:"createTime"` PushContent string `json:"pushContent"` ClientUserName string `json:"clientUserName"` ToUser string `json:"toUser"` ImgBuf string `json:"imgBuf"` MsgType int `json:"msgType"` Content string `json:"content"` MsgSource string `json:"msgSource"` // 群内消息才会用到的字段 WhoAtBot string `json:"whoAtBot"` // 谁@的机器人,微信昵称,方便客户端机器人反向@ GroupMember string `json:"groupMember"` // 如果是群聊消息,则为分离content后的发言人微信号 GroupMemberNickname string `json:"groupMemberNickname"` // 群内说话人的微信昵称 GroupMemberRole int8 `json:"groupMemberRole"` // 用户在群内身份,1成员,2管理员,3群主 GroupContent string `json:"groupContent"` // 如果是群消息,则为分离content后的群消息内容 }
接收到的转发消息
func (*UserMessage) IsAdmin ¶
func (m *UserMessage) IsAdmin() bool
func (*UserMessage) IsGroupOwner ¶
func (m *UserMessage) IsGroupOwner() bool