From b5e7c3ff339c6263af82261d37a402fdd04f0a4b Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Wed, 20 Dec 2023 11:41:14 +0300 Subject: [PATCH 1/6] add `mgTransport` callbacks --- types.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/types.go b/types.go index bb51ef2..7640199 100644 --- a/types.go +++ b/types.go @@ -1254,7 +1254,13 @@ type Action struct { // MgTransport type. type MgTransport struct { - WebhookURL string `json:"webhookUrl,omitempty"` + WebhookURL string `json:"webhookUrl,omitempty"` + Actions *MgTransportActions `json:"actions,omitempty"` +} + +type MgTransportActions struct { + Visits string `json:"visits,omitempty"` + Online string `json:"online,omitempty"` } // MgBot type. From 81a09e24d43f7bd57b40dbbac877cfd975832560 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Thu, 21 Dec 2023 10:53:18 +0300 Subject: [PATCH 2/6] callbacks structs --- system_time.go | 30 ++++++++++++++++++++++++++++++ types.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 system_time.go 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"` From a4de6df1469ba2785e41f95d6f06b5f951fdcb99 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Thu, 21 Dec 2023 17:18:40 +0300 Subject: [PATCH 3/6] fix field names --- types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types.go b/types.go index af215cb..b502766 100644 --- a/types.go +++ b/types.go @@ -1366,8 +1366,8 @@ type ChatVisitsResponse struct { LastVisit ChatLastVisit `json:"lastVisit"` IP string `json:"ip"` CountVisits uint `json:"countVisits"` - ChatDevice ChatDevice `json:"chatDevice"` - ChatUTM *ChatUTM `json:"chatUtm,omitempty"` + Device ChatDevice `json:"device"` + UTM *ChatUTM `json:"utm,omitempty"` } type ChatLastVisit struct { From e28631dcb2cba0c180caeb33c3b77491872bd126 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Tue, 6 Feb 2024 14:59:39 +0300 Subject: [PATCH 4/6] fieldalignment fix --- types.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/types.go b/types.go index b502766..d344d8f 100644 --- a/types.go +++ b/types.go @@ -1363,19 +1363,19 @@ type ChatCustomerOnline struct { } type ChatVisitsResponse struct { - LastVisit ChatLastVisit `json:"lastVisit"` - IP string `json:"ip"` - CountVisits uint `json:"countVisits"` - Device ChatDevice `json:"device"` UTM *ChatUTM `json:"utm,omitempty"` + Device ChatDevice `json:"device"` + IP string `json:"ip"` + LastVisit ChatLastVisit `json:"lastVisit"` + CountVisits uint `json:"countVisits"` } type ChatLastVisit struct { - Source string `json:"source"` - Duration uint `json:"duration"` CreatedAt SystemTime `json:"createdAt"` EndedAt *SystemTime `json:"endedAt,omitempty"` + Source string `json:"source"` Pages []ChatVisitedPage `json:"pages"` + Duration uint `json:"duration"` } type ChatVisitedPage struct { From 7c8e142cabcdfc2c0e48e25c792addfd0dfa659a Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Tue, 13 Feb 2024 13:49:13 +0300 Subject: [PATCH 5/6] country & city fields instead of ip field --- types.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types.go b/types.go index d344d8f..c6d7440 100644 --- a/types.go +++ b/types.go @@ -1365,7 +1365,8 @@ type ChatCustomerOnline struct { type ChatVisitsResponse struct { UTM *ChatUTM `json:"utm,omitempty"` Device ChatDevice `json:"device"` - IP string `json:"ip"` + Country string `json:"country"` + City string `json:"city"` LastVisit ChatLastVisit `json:"lastVisit"` CountVisits uint `json:"countVisits"` } From 29062b8bf0a5ad1f9e077a01afc19c6d0cd6fae2 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Wed, 20 Mar 2024 15:01:10 +0300 Subject: [PATCH 6/6] add title field to ChatVisitedPage --- types.go | 1 + 1 file changed, 1 insertion(+) diff --git a/types.go b/types.go index c6d7440..72f179e 100644 --- a/types.go +++ b/types.go @@ -1381,6 +1381,7 @@ type ChatLastVisit struct { type ChatVisitedPage struct { DateTime SystemTime `json:"dateTime"` + Title string `json:"title,omitempty"` URL string `json:"url"` }