MCPcopy Create free account
hub / github.com/aurora-develop/aurora / DialChatWebsocketWithStateAndProxy

Function DialChatWebsocketWithStateAndProxy

internal/chatgpt/request.go:890–929  ·  view source on GitHub ↗
(client httpclient.AuroraHttpClient, secret *tokens.Secret, state *ChatClientState, proxy string)

Source from the content-addressed store, hash-verified

888}
889
890func DialChatWebsocketWithStateAndProxy(client httpclient.AuroraHttpClient, secret *tokens.Secret, state *ChatClientState, proxy string) (*websocket.Conn, error) {
891 wsURL, err := getChatWebsocketURLWithState(client, secret, state)
892 if err != nil {
893 return nil, err
894 }
895 dialer := websocket.Dialer{
896 HandshakeTimeout: 15 * time.Second,
897 Proxy: fhttp.ProxyFromEnvironment,
898 }
899 if proxyFunc, err := websocketProxyFunc(proxy); err != nil {
900 return nil, err
901 } else if proxyFunc != nil {
902 dialer.Proxy = proxyFunc
903 }
904 header := fhttp.Header{}
905 ua := defaultUserAgent()
906 if state != nil && state.UserAgent != "" {
907 ua = state.UserAgent
908 }
909 header.Set("User-Agent", ua)
910 header.Set("Origin", "https://chatgpt.com")
911 conn, _, err := dialer.Dial(wsURL, header)
912 if err != nil {
913 return nil, err
914 }
915 initMsg := []map[string]interface{}{
916 {"id": 1, "command": map[string]interface{}{
917 "type": "connect",
918 "presence": map[string]string{"type": "presence", "state": "background"},
919 }},
920 {"id": 2, "command": map[string]interface{}{"type": "subscribe", "topic_id": "calpico-chatgpt"}},
921 {"id": 3, "command": map[string]interface{}{"type": "subscribe", "topic_id": "conversations"}},
922 {"id": 4, "command": map[string]interface{}{"type": "subscribe", "topic_id": "app_notifications"}},
923 }
924 if err := conn.WriteJSON(initMsg); err != nil {
925 conn.Close()
926 return nil, err
927 }
928 return conn, nil
929}
930
931func websocketProxyFunc(proxy string) (func(*fhttp.Request) (*url.URL, error), error) {
932 if proxy == "" {

Callers 2

Calls 4

websocketProxyFuncFunction · 0.85
defaultUserAgentFunction · 0.85
SetMethod · 0.80

Tested by

no test coverage detected