summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/Rhymen/go-whatsapp
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-11-22 15:55:57 +0100
committerGitHub <noreply@github.com>2020-11-22 15:55:57 +0100
commit4cc2c914e634eb8c79eb61aa1bc29faf6021ffcf (patch)
tree92d3b8d27cd35455eae7423e4d47aad67cc6a43b /vendor/github.com/Rhymen/go-whatsapp
parentcbb46293ab670c1989bfcd9aae5d853223074038 (diff)
downloadmatterbridge-msglm-4cc2c914e634eb8c79eb61aa1bc29faf6021ffcf.tar.gz
matterbridge-msglm-4cc2c914e634eb8c79eb61aa1bc29faf6021ffcf.tar.bz2
matterbridge-msglm-4cc2c914e634eb8c79eb61aa1bc29faf6021ffcf.zip
Update vendor (#1297)
Diffstat (limited to 'vendor/github.com/Rhymen/go-whatsapp')
-rw-r--r--vendor/github.com/Rhymen/go-whatsapp/conn.go78
-rw-r--r--vendor/github.com/Rhymen/go-whatsapp/errors.go2
-rw-r--r--vendor/github.com/Rhymen/go-whatsapp/go.sum1
-rw-r--r--vendor/github.com/Rhymen/go-whatsapp/media.go36
-rw-r--r--vendor/github.com/Rhymen/go-whatsapp/message.go17
-rw-r--r--vendor/github.com/Rhymen/go-whatsapp/read.go4
6 files changed, 93 insertions, 45 deletions
diff --git a/vendor/github.com/Rhymen/go-whatsapp/conn.go b/vendor/github.com/Rhymen/go-whatsapp/conn.go
index 59445591..4b28cbe1 100644
--- a/vendor/github.com/Rhymen/go-whatsapp/conn.go
+++ b/vendor/github.com/Rhymen/go-whatsapp/conn.go
@@ -116,31 +116,59 @@ Creates a new connection with a given timeout. The websocket connection to the W
The goroutine for handling incoming messages is started
*/
func NewConn(timeout time.Duration) (*Conn, error) {
- wac := &Conn{
- handler: make([]Handler, 0),
- msgCount: 0,
- msgTimeout: timeout,
- Store: newStore(),
-
- longClientName: "github.com/rhymen/go-whatsapp",
- shortClientName: "go-whatsapp",
- clientVersion: "0.1.0",
- }
- return wac, wac.connect()
+ return NewConnWithOptions(&Options{
+ Timeout: timeout,
+ })
}
// NewConnWithProxy Create a new connect with a given timeout and a http proxy.
func NewConnWithProxy(timeout time.Duration, proxy func(*http.Request) (*url.URL, error)) (*Conn, error) {
+ return NewConnWithOptions(&Options{
+ Timeout: timeout,
+ Proxy: proxy,
+ })
+}
+
+// NewConnWithOptions Create a new connect with a given options.
+type Options struct {
+ Proxy func(*http.Request) (*url.URL, error)
+ Timeout time.Duration
+ Handler []Handler
+ ShortClientName string
+ LongClientName string
+ ClientVersion string
+ Store *Store
+}
+func NewConnWithOptions(opt *Options) (*Conn, error) {
+ if opt == nil {
+ return nil, ErrOptionsNotProvided
+ }
wac := &Conn{
handler: make([]Handler, 0),
msgCount: 0,
- msgTimeout: timeout,
+ msgTimeout: opt.Timeout,
Store: newStore(),
-
- longClientName: "github.com/rhymen/go-whatsapp",
+ longClientName: "github.com/Rhymen/go-whatsapp",
shortClientName: "go-whatsapp",
clientVersion: "0.1.0",
- Proxy: proxy,
+ }
+ if opt.Handler != nil {
+ wac.handler = opt.Handler
+ }
+ if opt.Store != nil {
+ wac.Store = opt.Store
+ }
+ if opt.Proxy != nil {
+ wac.Proxy = opt.Proxy
+ }
+ if len(opt.ShortClientName) != 0 {
+ wac.shortClientName = opt.ShortClientName
+ }
+ if len(opt.LongClientName) != 0 {
+ wac.longClientName = opt.LongClientName
+ }
+ if len(opt.ClientVersion) != 0 {
+ wac.clientVersion = opt.ClientVersion
}
return wac, wac.connect()
}
@@ -249,10 +277,26 @@ func (wac *Conn) keepAlive(minIntervalMs int, maxIntervalMs int) {
}
}
+// IsConnected returns whether the server connection is established or not
+func (wac *Conn) IsConnected() bool {
+ return wac.connected
+}
+
+// GetConnected returns whether the server connection is established or not
+//
+// Deprecated: function name is not go idiomatic, use IsConnected instead
func (wac *Conn) GetConnected() bool {
- return wac.connected
+ return wac.connected
+}
+
+//IsLoggedIn returns whether the you are logged in or not
+func (wac *Conn) IsLoggedIn() bool {
+ return wac.loggedIn
}
+// GetLoggedIn returns whether the you are logged in or not
+//
+// Deprecated: function name is not go idiomatic, use IsLoggedIn instead.
func (wac *Conn) GetLoggedIn() bool {
- return wac.loggedIn
+ return wac.loggedIn
}
diff --git a/vendor/github.com/Rhymen/go-whatsapp/errors.go b/vendor/github.com/Rhymen/go-whatsapp/errors.go
index be78ea0f..022f977a 100644
--- a/vendor/github.com/Rhymen/go-whatsapp/errors.go
+++ b/vendor/github.com/Rhymen/go-whatsapp/errors.go
@@ -22,6 +22,8 @@ var (
ErrMediaDownloadFailedWith404 = errors.New("download failed with status code 404")
ErrMediaDownloadFailedWith410 = errors.New("download failed with status code 410")
ErrInvalidWebsocket = errors.New("invalid websocket")
+ ErrMessageTypeNotImplemented = errors.New("message type not implemented")
+ ErrOptionsNotProvided = errors.New("new conn options not provided")
)
type ErrConnectionFailed struct {
diff --git a/vendor/github.com/Rhymen/go-whatsapp/go.sum b/vendor/github.com/Rhymen/go-whatsapp/go.sum
index b724cb47..ee786406 100644
--- a/vendor/github.com/Rhymen/go-whatsapp/go.sum
+++ b/vendor/github.com/Rhymen/go-whatsapp/go.sum
@@ -32,5 +32,6 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6Zh
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
diff --git a/vendor/github.com/Rhymen/go-whatsapp/media.go b/vendor/github.com/Rhymen/go-whatsapp/media.go
index 225eac8e..0fcacd2e 100644
--- a/vendor/github.com/Rhymen/go-whatsapp/media.go
+++ b/vendor/github.com/Rhymen/go-whatsapp/media.go
@@ -38,7 +38,7 @@ func Download(url string, mediaKey []byte, appInfo MediaType, fileLength int) ([
return nil, err
}
if len(data) != fileLength {
- return nil, fmt.Errorf("file length does not match")
+ return nil, fmt.Errorf("file length does not match. Expected: %v, got: %v", fileLength, len(data))
}
return data, nil
}
@@ -93,21 +93,21 @@ func downloadMedia(url string) (file []byte, mac []byte, err error) {
return data[:n-10], data[n-10 : n], nil
}
-
-type MediaConn struct {
- Status int `json:"status"`
- MediaConn struct {
- Auth string `json:"auth"`
- TTL int `json:"ttl"`
- Hosts []struct {
- Hostname string `json:"hostname"`
- IPs []interface{} `json:"ips"`
- } `json:"hosts"`
- } `json:"media_conn"`
+type MediaConn struct {
+ Status int `json:"status"`
+ MediaConn struct {
+ Auth string `json:"auth"`
+ TTL int `json:"ttl"`
+ Hosts []struct {
+ Hostname string `json:"hostname"`
+ IPs []struct {
+ IP4 string `json:"ip4"`
+ IP6 string `json:"ip6"`
+ } `json:"ips"`
+ } `json:"hosts"`
+ } `json:"media_conn"`
}
-
-
func (wac *Conn) queryMediaConn() (hostname, auth string, ttl int, err error) {
queryReq := []interface{}{"query", "mediaConn"}
ch, err := wac.writeJson(queryReq)
@@ -131,7 +131,7 @@ func (wac *Conn) queryMediaConn() (hostname, auth string, ttl int, err error) {
var host string
for _, h := range resp.MediaConn.Hosts {
- if h.Hostname!="" {
+ if h.Hostname != "" {
host = h.Hostname
break
}
@@ -143,10 +143,10 @@ func (wac *Conn) queryMediaConn() (hostname, auth string, ttl int, err error) {
}
var mediaTypeMap = map[MediaType]string{
- MediaImage: "/mms/image",
- MediaVideo: "/mms/video",
+ MediaImage: "/mms/image",
+ MediaVideo: "/mms/video",
MediaDocument: "/mms/document",
- MediaAudio: "/mms/audio",
+ MediaAudio: "/mms/audio",
}
func (wac *Conn) Upload(reader io.Reader, appInfo MediaType) (downloadURL string, mediaKey []byte, fileEncSha256 []byte, fileSha256 []byte, fileLength uint64, err error) {
diff --git a/vendor/github.com/Rhymen/go-whatsapp/message.go b/vendor/github.com/Rhymen/go-whatsapp/message.go
index 15797cb4..34fc02af 100644
--- a/vendor/github.com/Rhymen/go-whatsapp/message.go
+++ b/vendor/github.com/Rhymen/go-whatsapp/message.go
@@ -238,7 +238,7 @@ func getMessageInfo(msg *proto.WebMessageInfo) MessageInfo {
return MessageInfo{
Id: msg.GetKey().GetId(),
RemoteJid: msg.GetKey().GetRemoteJid(),
- SenderJid: msg.GetKey().GetParticipant(),
+ SenderJid: msg.GetParticipant(),
FromMe: msg.GetKey().GetFromMe(),
Timestamp: msg.GetMessageTimestamp(),
Status: MessageStatus(msg.GetStatus()),
@@ -838,19 +838,16 @@ func ParseProtoMessage(msg *proto.WebMessageInfo) interface{} {
default:
//cannot match message
-
+ return ErrMessageTypeNotImplemented
}
-
- return nil
}
-
/*
BatteryMessage represents a battery level and charging state.
*/
type BatteryMessage struct {
- Plugged bool
- Powersave bool
+ Plugged bool
+ Powersave bool
Percentage int
}
@@ -859,8 +856,8 @@ func getBatteryMessage(msg map[string]string) BatteryMessage {
powersave, _ := strconv.ParseBool(msg["powersave"])
percentage, _ := strconv.Atoi(msg["value"])
batteryMessage := BatteryMessage{
- Plugged: plugged,
- Powersave: powersave,
+ Plugged: plugged,
+ Powersave: powersave,
Percentage: percentage,
}
@@ -869,7 +866,7 @@ func getBatteryMessage(msg map[string]string) BatteryMessage {
func getNewContact(msg map[string]string) Contact {
contact := Contact{
- Jid: msg["jid"],
+ Jid: msg["jid"],
Notify: msg["notify"],
}
diff --git a/vendor/github.com/Rhymen/go-whatsapp/read.go b/vendor/github.com/Rhymen/go-whatsapp/read.go
index c35f7f0e..81e16619 100644
--- a/vendor/github.com/Rhymen/go-whatsapp/read.go
+++ b/vendor/github.com/Rhymen/go-whatsapp/read.go
@@ -62,6 +62,10 @@ func (wac *Conn) processReadData(msgType int, msg []byte) error {
data[0] = "!"
}
+ if len(data) == 2 && len(data[1]) == 0 {
+ return nil
+ }
+
if len(data) != 2 || len(data[1]) == 0 {
return ErrInvalidWsData
}