From 4c79fef443c51629e014b8ac0866613b682b09a1 Mon Sep 17 00:00:00 2001 From: Roman Shakhov Date: Mon, 4 May 2020 18:11:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D1=82=D0=BE=D0=B4=20dialogs/histor?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- v1/client.go | 40 ++++++++++++++++++++++++++++++++++++++++ v1/types.go | 17 +++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/v1/client.go b/v1/client.go index da677e0..6f02c99 100644 --- a/v1/client.go +++ b/v1/client.go @@ -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 diff --git a/v1/types.go b/v1/types.go index c7f8947..0cfe2fc 100644 --- a/v1/types.go +++ b/v1/types.go @@ -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