improve ws url generation

This commit is contained in:
Alex Lushpai 2018-08-31 17:54:53 +03:00
parent 473f66c665
commit 5e81617876

View File

@ -5,6 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
"strings"
"time" "time"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
@ -659,9 +660,9 @@ func (c *MgClient) CommandDelete(request string) (map[string]interface{}, int, e
return resp, status, err return resp, status, err
} }
// Ws let you receive url & headers to open web socket connection // WsMeta let you receive url & headers to open web socket connection
func (c *MgClient) Ws() (string, http.Header, error) { func (c *MgClient) WsMeta(events []string) (string, http.Header, error) {
url := fmt.Sprintf("%s%s%s", c.URL, prefix, "/ws") url := fmt.Sprintf("%s%s%s%s", c.URL, prefix, "/ws?events=", strings.Join(events[:], ","))
headers := http.Header{} headers := http.Header{}
headers.Add("x-bot-token", c.Token) headers.Add("x-bot-token", c.Token)
@ -670,6 +671,11 @@ func (c *MgClient) Ws() (string, http.Header, error) {
return url, headers, err return url, headers, err
} }
if len(events) < 1 {
err := errors.New("events list must not be empty")
return url, headers, err
}
return url, headers, nil return url, headers, nil
} }