-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvoice.go
More file actions
30 lines (26 loc) · 871 Bytes
/
Copy pathvoice.go
File metadata and controls
30 lines (26 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package wecombot
// VoiceMessage 语音类型消息。详见 https://developer.work.weixin.qq.com/document/path/91770#%E8%AF%AD%E9%9F%B3%E7%B1%BB%E5%9E%8B
type VoiceMessage struct {
// MsgType 必填。语音类型,此时固定为 voice 。
MsgType MsgType `json:"msgtype"`
// 消息内容
Voice struct {
// MediaID 必填。语音文件id,通过文件上传接口获取。
MediaID string `json:"media_id"`
} `json:"voice"`
}
// SendVoiceMessage 发送语音消息
func (bot *Bot) SendVoiceMessage(msg *VoiceMessage) (err error) {
msg.MsgType = VoiceMsgType
return bot.send(msg)
}
// SendVoice 发送语音
func (bot *Bot) SendVoice(f []byte, filename string) (err error) {
ret, err := bot.UploadMedia(VoiceFile, f, filename)
if err != nil {
return err
}
var msg VoiceMessage
msg.Voice.MediaID = ret.MediaID
return bot.SendVoiceMessage(&msg)
}