forked from jshiffer/matterbridge
Handle audio downloads (whatsapp)
This commit is contained in:
parent
5ad788e768
commit
2c20f72a9c
@ -266,6 +266,63 @@ func (b *Bwhatsapp) HandleVideoMessage(message whatsapp.VideoMessage) {
|
|||||||
b.Remote <- rmsg
|
b.Remote <- rmsg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HandleAudioMessage downloads audio messages
|
||||||
|
func (b *Bwhatsapp) HandleAudioMessage(message whatsapp.AudioMessage) {
|
||||||
|
if message.Info.FromMe || message.Info.Timestamp < b.startedAt {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
senderJID := message.Info.SenderJid
|
||||||
|
if len(message.Info.SenderJid) == 0 && message.Info.Source != nil && message.Info.Source.Participant != nil {
|
||||||
|
senderJID = *message.Info.Source.Participant
|
||||||
|
}
|
||||||
|
|
||||||
|
senderName := b.getSenderName(message.Info.SenderJid)
|
||||||
|
if senderName == "" {
|
||||||
|
senderName = "Someone" // don't expose telephone number
|
||||||
|
}
|
||||||
|
|
||||||
|
rmsg := config.Message{
|
||||||
|
UserID: senderJID,
|
||||||
|
Username: senderName,
|
||||||
|
Channel: message.Info.RemoteJid,
|
||||||
|
Account: b.Account,
|
||||||
|
Protocol: b.Protocol,
|
||||||
|
Extra: make(map[string][]interface{}),
|
||||||
|
ID: message.Info.Id,
|
||||||
|
}
|
||||||
|
|
||||||
|
if avatarURL, exists := b.userAvatars[senderJID]; exists {
|
||||||
|
rmsg.Avatar = avatarURL
|
||||||
|
}
|
||||||
|
|
||||||
|
fileExt, err := mime.ExtensionsByType(message.Type)
|
||||||
|
if err != nil {
|
||||||
|
b.Log.Errorf("Mimetype detection error: %s", err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
filename := fmt.Sprintf("%v%v", message.Info.Id, fileExt[0])
|
||||||
|
|
||||||
|
b.Log.Debugf("Trying to download %s with size %#v and type %s", filename, message.Length, message.Type)
|
||||||
|
|
||||||
|
data, err := message.Download()
|
||||||
|
if err != nil {
|
||||||
|
b.Log.Errorf("Download audio failed: %s", err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move file to bridge storage
|
||||||
|
helper.HandleDownloadData(b.Log, &rmsg, filename, "audio message", "", &data, b.General)
|
||||||
|
|
||||||
|
b.Log.Debugf("<= Sending message from %s on %s to gateway", senderJID, b.Account)
|
||||||
|
b.Log.Debugf("<= Message is %#v", rmsg)
|
||||||
|
|
||||||
|
b.Remote <- rmsg
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
//func (b *Bwhatsapp) HandleJsonMessage(message string) {
|
//func (b *Bwhatsapp) HandleJsonMessage(message string) {
|
||||||
// fmt.Println(message) // TODO implement
|
// fmt.Println(message) // TODO implement
|
||||||
|
Loading…
Reference in New Issue
Block a user