From 5e816178765a4b22865eafef44676c360e414c23 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Fri, 31 Aug 2018 17:54:53 +0300 Subject: [PATCH] improve ws url generation --- v1/client.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/v1/client.go b/v1/client.go index d809396..d3da606 100644 --- a/v1/client.go +++ b/v1/client.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net/http" + "strings" "time" "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 } -// Ws let you receive url & headers to open web socket connection -func (c *MgClient) Ws() (string, http.Header, error) { - url := fmt.Sprintf("%s%s%s", c.URL, prefix, "/ws") +// WsMeta let you receive url & headers to open web socket connection +func (c *MgClient) WsMeta(events []string) (string, http.Header, error) { + url := fmt.Sprintf("%s%s%s%s", c.URL, prefix, "/ws?events=", strings.Join(events[:], ",")) headers := http.Header{} headers.Add("x-bot-token", c.Token) @@ -670,6 +671,11 @@ func (c *MgClient) Ws() (string, http.Header, error) { 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 }