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
|
||||
}
|
||||
|
||||
// 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{}
|
||||
|
||||
|
26
v1/types.go
26
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user