Метод dialogs/history

This commit is contained in:
Roman Shakhov 2020-05-04 18:11:38 +03:00
parent 2b05530ce7
commit 4c79fef443
2 changed files with 57 additions and 0 deletions

View file

@ -785,6 +785,46 @@ func (c *MgClient) UploadFileByURL(request UploadFileByUrlRequest) (UploadFileRe
return resp, status, err
}
// ResponsibleHistory get history of responsibles
//
// Example:
//
// var client = v1.New("https://demo.url", "09jIJ")
//
// data, status, err := client.ResponsibleHistory(ResponsibleHistoryRequest{DialogID:1})
//
// if err != nil {
// fmt.Printf("%v", err)
// }
//
// if status >= http.StatusBadRequest {
// fmt.Printf("%v", err)
// }
//
// for _, historyItem := range data {
// fmt.Printf("%v %v\n", historyItem.AssignedAt)
// }
func (c *MgClient) ResponsibleHistory(request ResponsibleHistoryRequest) ([]ResponsibleHistoryResponseItem, int, error) {
var resp []ResponsibleHistoryResponseItem
var b []byte
outgoing, _ := query.Values(request)
data, status, err := c.GetRequest(fmt.Sprintf("/dialogs/history?%s", outgoing.Encode()), b)
if err != nil {
return resp, status, err
}
if status > http.StatusCreated || status < http.StatusOK {
return resp, status, c.Error(data)
}
if err := json.Unmarshal(data, &resp); err != nil {
return resp, status, err
}
return resp, status, err
}
// WsMeta let you receive url & headers to open web socket connection
func (c *MgClient) WsMeta(events []string) (string, http.Header, error) {
var url string

View file

@ -210,6 +210,12 @@ type (
UploadFileByUrlRequest struct {
Url string `json:"url"`
}
ResponsibleHistoryRequest struct {
ChatID uint64 `url:"chat_id,omitempty" json:"chat_id"`
DialogID uint64 `url:"dialog_id,omitempty" json:"dialog_id"`
Limit int `url:"int,omitempty"`
}
)
// Response types
@ -353,6 +359,17 @@ type (
Url *string `json:"source_url"`
CreatedAt time.Time `json:"created_at"`
}
ResponsibleHistoryResponseItem struct {
ID uint64 `json:"id"`
DialogID uint64 `json:"dialog_id"`
Responsible UserRef `json:"responsible"`
AssignedBy *UserRef `json:"assigned_by"`
UnassignedBy *UserRef `json:"unassigned_by"`
UnassignReason string `json:"unassign_reason"`
UnassignedAt *string `json:"unassigned_at"`
AssignedAt string `json:"assigned_at"`
}
)
// WS event types