mirror of
https://github.com/Neur0toxine/simla-bot-quickreplies-test.git
synced 2024-11-27 07:16:02 +03:00
fallback in case http or https was returned from API
This commit is contained in:
parent
646caf2cab
commit
c62788dcc0
10
websocket.go
10
websocket.go
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
v1 "github.com/retailcrm/mg-bot-api-client-go/v1"
|
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)
|
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)
|
ws, _, err := websocket.DefaultDialer.Dial(data, header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot estabilish WebSocket connection to %s: %w", data, err)
|
return fmt.Errorf("cannot estabilish WebSocket connection to %s: %w", data, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user