Clean&combed code
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
package bwhatsapp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mime"
|
||||
"strings"
|
||||
"time"
|
||||
"mime"
|
||||
"fmt"
|
||||
|
||||
"github.com/42wim/matterbridge/bridge/config"
|
||||
"github.com/42wim/matterbridge/bridge/helper"
|
||||
"github.com/42wim/matterbridge/bridge/helper"
|
||||
|
||||
"github.com/matterbridge/go-whatsapp"
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package bwhatsapp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"mime"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
"bytes"
|
||||
"mime"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/42wim/matterbridge/bridge"
|
||||
"github.com/42wim/matterbridge/bridge/config"
|
||||
@@ -277,8 +277,8 @@ func (b *Bwhatsapp) Send(msg config.Message) (string, error) {
|
||||
|
||||
b.Log.Debugf("Extra file is %#v", filetype)
|
||||
|
||||
// TODO: add different types
|
||||
// TODO: add webp conversion
|
||||
// TODO: add different types
|
||||
// TODO: add webp conversion
|
||||
if filetype == "image/jpeg" || filetype == "image/png" || filetype == "image/gif" {
|
||||
// Post image message
|
||||
message := whatsapp.ImageMessage{
|
||||
@@ -302,40 +302,18 @@ func (b *Bwhatsapp) Send(msg config.Message) (string, error) {
|
||||
message.Info.Id = strings.ToUpper(hex.EncodeToString(idbytes))
|
||||
err := b.conn.Send(message)
|
||||
|
||||
return message.Info.Id, err
|
||||
} else {
|
||||
// Post document message
|
||||
message := whatsapp.DocumentMessage{
|
||||
Info: whatsapp.MessageInfo{
|
||||
RemoteJid: msg.Channel,
|
||||
},
|
||||
Title: fi.Name,
|
||||
FileName: fi.Name,
|
||||
Type: filetype,
|
||||
Content: bytes.NewReader(*fi.Data),
|
||||
}
|
||||
|
||||
b.Log.Debugf("=> Sending %#v", msg)
|
||||
|
||||
// create message ID
|
||||
// TODO follow and act if https://github.com/Rhymen/go-whatsapp/issues/101 implemented
|
||||
idbytes := make([]byte, 10)
|
||||
if _, err := rand.Read(idbytes); err != nil {
|
||||
b.Log.Warn(err.Error())
|
||||
}
|
||||
|
||||
message.Info.Id = strings.ToUpper(hex.EncodeToString(idbytes))
|
||||
err := b.conn.Send(message)
|
||||
|
||||
return message.Info.Id, err
|
||||
}
|
||||
} else {
|
||||
// Post text message
|
||||
message := whatsapp.TextMessage{
|
||||
|
||||
// Post document message
|
||||
message := whatsapp.DocumentMessage{
|
||||
Info: whatsapp.MessageInfo{
|
||||
RemoteJid: msg.Channel, // which equals to group id
|
||||
RemoteJid: msg.Channel,
|
||||
},
|
||||
Text: msg.Username + msg.Text,
|
||||
Title: fi.Name,
|
||||
FileName: fi.Name,
|
||||
Type: filetype,
|
||||
Content: bytes.NewReader(*fi.Data),
|
||||
}
|
||||
|
||||
b.Log.Debugf("=> Sending %#v", msg)
|
||||
@@ -352,6 +330,28 @@ func (b *Bwhatsapp) Send(msg config.Message) (string, error) {
|
||||
|
||||
return message.Info.Id, err
|
||||
}
|
||||
|
||||
// Post text message
|
||||
message := whatsapp.TextMessage{
|
||||
Info: whatsapp.MessageInfo{
|
||||
RemoteJid: msg.Channel, // which equals to group id
|
||||
},
|
||||
Text: msg.Username + msg.Text,
|
||||
}
|
||||
|
||||
b.Log.Debugf("=> Sending %#v", msg)
|
||||
|
||||
// create message ID
|
||||
// TODO follow and act if https://github.com/Rhymen/go-whatsapp/issues/101 implemented
|
||||
idbytes := make([]byte, 10)
|
||||
if _, err := rand.Read(idbytes); err != nil {
|
||||
b.Log.Warn(err.Error())
|
||||
}
|
||||
|
||||
message.Info.Id = strings.ToUpper(hex.EncodeToString(idbytes))
|
||||
err := b.conn.Send(message)
|
||||
|
||||
return message.Info.Id, err
|
||||
}
|
||||
|
||||
// TODO do we want that? to allow login with QR code from a bridged channel? https://github.com/tulir/mautrix-whatsapp/blob/513eb18e2d59bada0dd515ee1abaaf38a3bfe3d5/commands.go#L76
|
||||
|
||||
Reference in New Issue
Block a user