diff --git a/websocket.go b/websocket.go index cdf3838..a39f405 100644 --- a/websocket.go +++ b/websocket.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "log" + "strings" "github.com/gorilla/websocket" v1 "github.com/retailcrm/mg-bot-api-client-go/v1" @@ -48,6 +49,15 @@ func (l *WebsocketListener) Listen() error { return fmt.Errorf("cannot get meta for connection: %w", err) } + if strings.HasPrefix(data, "http:") { + log.Println("warning: found http: in the URL - replacing with ws:") + data = "ws:" + data[5:] + } + if strings.HasPrefix(data, "https:") { + log.Println("warning: found https: in the URL - replacing with wss:") + data = "wss:" + data[6:] + } + ws, _, err := websocket.DefaultDialer.Dial(data, header) if err != nil { return fmt.Errorf("cannot estabilish WebSocket connection to %s: %w", data, err)