diff --git a/system_time.go b/system_time.go new file mode 100644 index 0000000..dde62ec --- /dev/null +++ b/system_time.go @@ -0,0 +1,30 @@ +package retailcrm + +import ( + "fmt" + "strings" + "time" +) + +type SystemTime time.Time + +const systemTimeLayout = "2006-01-02 15:04:05" + +// UnmarshalJSON parses time.Time from system format. +func (st *SystemTime) UnmarshalJSON(b []byte) (err error) { + s := strings.Trim(string(b), `"`) + nt, err := time.Parse(systemTimeLayout, s) + *st = SystemTime(nt) + return +} + +// MarshalJSON will marshal time.Time to system format. +func (st SystemTime) MarshalJSON() ([]byte, error) { + return []byte(st.String()), nil +} + +// String returns the time in the custom format +func (st *SystemTime) String() string { + t := time.Time(*st) + return fmt.Sprintf("%q", t.Format(systemTimeLayout)) +} diff --git a/types.go b/types.go index 7640199..af215cb 100644 --- a/types.go +++ b/types.go @@ -1358,6 +1358,43 @@ type Activity struct { Freeze bool `json:"freeze"` } +type ChatCustomerOnline struct { + LastOnline SystemTime `json:"lastOnline"` +} + +type ChatVisitsResponse struct { + LastVisit ChatLastVisit `json:"lastVisit"` + IP string `json:"ip"` + CountVisits uint `json:"countVisits"` + ChatDevice ChatDevice `json:"chatDevice"` + ChatUTM *ChatUTM `json:"chatUtm,omitempty"` +} + +type ChatLastVisit struct { + Source string `json:"source"` + Duration uint `json:"duration"` + CreatedAt SystemTime `json:"createdAt"` + EndedAt *SystemTime `json:"endedAt,omitempty"` + Pages []ChatVisitedPage `json:"pages"` +} + +type ChatVisitedPage struct { + DateTime SystemTime `json:"dateTime"` + URL string `json:"url"` +} + +type ChatDevice struct { + Lang string `json:"lang"` + Browser string `json:"browser"` + OS string `json:"os"` +} + +type ChatUTM struct { + Source string `json:"source"` + Medium string `json:"medium"` + Campaign string `json:"campaign"` +} + // Tag struct. type Tag struct { Name string `json:"name,omitempty"`