add web socket related structs & methods

This commit is contained in:
Alex Lushpai 2018-08-31 17:39:27 +03:00
parent c8fbd8cd7a
commit 5533b72f96
2 changed files with 40 additions and 0 deletions

View File

@ -659,6 +659,20 @@ func (c *MgClient) CommandDelete(request string) (map[string]interface{}, int, e
return resp, status, err
}
// Ws let you receive url & headers to open web socket connection
func (c *MgClient) Ws() (string, http.Header, error) {
url := fmt.Sprintf("%s%s%s", c.URL, prefix, "/ws")
headers := http.Header{}
headers.Add("x-bot-token", c.Token)
if url == "" {
err := errors.New("empty WS URL")
return url, headers, err
}
return url, headers, nil
}
func (c *MgClient) Error(info []byte) error {
var data map[string]interface{}

View File

@ -22,6 +22,18 @@ const (
MessageScopePublic string = "public"
MessageScopePrivate string = "private"
WsEventMessageNew string = "message_new"
WsEventMessageUpdated string = "message_updated"
WsEventMessageDeleted string = "message_deleted"
WsEventDialogOpened string = "dialog_opened"
WsEventDialogClosed string = "dialog_closed"
WsEventDialogAssing string = "dialog_assign"
WsEventChatCreated string = "chat_created"
WsEventChatUpdated string = "chat_updated"
WsEventUserJoined string = "user_joined_chat"
WsEventUserLeave string = "user_left_chat"
WsEventUserUpdated string = "user_updated"
ChannelFeatureNone string = "none"
ChannelFeatureReceive string = "receive"
ChannelFeatureSend string = "send"
@ -270,6 +282,20 @@ type (
}
)
// WS event types
type (
WsEvent struct {
Type string `json:"type"`
Meta EventMeta `json:"meta"`
AppID uint `json:"app_id"`
Data interface{} `json:"data"`
}
EventMeta struct {
Timestamp int64 `json:"timestamp"`
}
)
// Single entity types
type (
Message struct {