mirror of
https://github.com/retailcrm/mg-bot-api-client-go.git
synced 2024-11-24 05:46:04 +03:00
Merge pull request #4 from gwinn/master
Add web socket related structs & methods
This commit is contained in:
commit
473f66c665
14
v1/client.go
14
v1/client.go
@ -659,6 +659,20 @@ func (c *MgClient) CommandDelete(request string) (map[string]interface{}, int, e
|
|||||||
return resp, status, err
|
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 {
|
func (c *MgClient) Error(info []byte) error {
|
||||||
var data map[string]interface{}
|
var data map[string]interface{}
|
||||||
|
|
||||||
|
26
v1/types.go
26
v1/types.go
@ -22,6 +22,18 @@ const (
|
|||||||
MessageScopePublic string = "public"
|
MessageScopePublic string = "public"
|
||||||
MessageScopePrivate string = "private"
|
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"
|
ChannelFeatureNone string = "none"
|
||||||
ChannelFeatureReceive string = "receive"
|
ChannelFeatureReceive string = "receive"
|
||||||
ChannelFeatureSend string = "send"
|
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
|
// Single entity types
|
||||||
type (
|
type (
|
||||||
Message struct {
|
Message struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user