mirror of
https://github.com/retailcrm/mg-bot-api-client-go.git
synced 2024-11-21 20:36:05 +03:00
minor improvements
This commit is contained in:
parent
109ad20fc0
commit
8ccda2e970
21
v1/client.go
21
v1/client.go
@ -662,20 +662,23 @@ func (c *MgClient) CommandDelete(request string) (map[string]interface{}, int, e
|
||||
|
||||
// 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)
|
||||
|
||||
if url == "" {
|
||||
err := errors.New("empty WS URL")
|
||||
return url, headers, err
|
||||
}
|
||||
var url string
|
||||
|
||||
if len(events) < 1 {
|
||||
err := errors.New("events list must not be empty")
|
||||
return url, headers, err
|
||||
return url, nil, err
|
||||
}
|
||||
|
||||
url = fmt.Sprintf("%s%s%s%s", c.URL, prefix, "/ws?events=", strings.Join(events[:], ","))
|
||||
|
||||
if url == "" {
|
||||
err := errors.New("empty WS URL")
|
||||
return url, nil, err
|
||||
}
|
||||
|
||||
headers := http.Header{}
|
||||
headers.Add("x-bot-token", c.Token)
|
||||
|
||||
return url, headers, nil
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,12 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
@ -314,3 +316,19 @@ func TestMgClient_CommandEditDelete(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
t.Logf("%v", d)
|
||||
}
|
||||
|
||||
func TestMgClient_WsMeta(t *testing.T) {
|
||||
c := client()
|
||||
events := []string{"user_updated", "user_join_chat"}
|
||||
url, headers, err := c.WsMeta(events)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
resUrl := fmt.Sprintf("%s%s%s%s", c.URL, prefix, "/ws?events=", strings.Join(events[:], ","))
|
||||
resToken := c.Token
|
||||
|
||||
assert.Equal(t, resUrl, url)
|
||||
assert.Equal(t, resToken, headers["X-Bot-Token"][0])
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user