mirror of
https://github.com/retailcrm/mg-bot-api-client-go.git
synced 2024-11-24 13:56:03 +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
|
// WsMeta let you receive url & headers to open web socket connection
|
||||||
func (c *MgClient) WsMeta(events []string) (string, http.Header, error) {
|
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[:], ","))
|
var url string
|
||||||
headers := http.Header{}
|
|
||||||
headers.Add("x-bot-token", c.Token)
|
|
||||||
|
|
||||||
if url == "" {
|
|
||||||
err := errors.New("empty WS URL")
|
|
||||||
return url, headers, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(events) < 1 {
|
if len(events) < 1 {
|
||||||
err := errors.New("events list must not be empty")
|
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
|
return url, headers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package v1
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
@ -314,3 +316,19 @@ func TestMgClient_CommandEditDelete(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
t.Logf("%v", d)
|
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