mirror of
https://github.com/retailcrm/mg-bot-api-client-go.git
synced 2024-11-24 05:46:04 +03:00
improve ws url generation
This commit is contained in:
parent
473f66c665
commit
5e81617876
12
v1/client.go
12
v1/client.go
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user