diff --git a/v1/client.go b/v1/client.go index ddd0c95..d809396 100644 --- a/v1/client.go +++ b/v1/client.go @@ -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{} diff --git a/v1/types.go b/v1/types.go index 10edb29..b6b6657 100644 --- a/v1/types.go +++ b/v1/types.go @@ -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 {