add mgTransport callbacks

This commit is contained in:
Pavel 2024-09-04 13:34:37 +03:00 committed by GitHub
commit c9e5b1f79d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 77 additions and 2 deletions

30
system_time.go Normal file
View File

@ -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))
}

View File

@ -1254,8 +1254,14 @@ type Action struct {
// MgTransport type. // MgTransport type.
type MgTransport struct { type MgTransport struct {
WebhookURL string `json:"webhookUrl,omitempty"` WebhookURL string `json:"webhookUrl,omitempty"`
RefreshToken bool `json:"refreshToken,omitempty"` RefreshToken bool `json:"refreshToken,omitempty"`
Actions *MgTransportActions `json:"actions,omitempty"`
}
type MgTransportActions struct {
Visits string `json:"visits,omitempty"`
Online string `json:"online,omitempty"`
} }
// MgBot type. // MgBot type.
@ -1355,6 +1361,45 @@ type Activity struct {
Freeze bool `json:"freeze"` Freeze bool `json:"freeze"`
} }
type ChatCustomerOnline struct {
LastOnline SystemTime `json:"lastOnline"`
}
type ChatVisitsResponse struct {
UTM *ChatUTM `json:"utm,omitempty"`
Device ChatDevice `json:"device"`
Country string `json:"country"`
City string `json:"city"`
LastVisit ChatLastVisit `json:"lastVisit"`
CountVisits uint `json:"countVisits"`
}
type ChatLastVisit struct {
CreatedAt SystemTime `json:"createdAt"`
EndedAt *SystemTime `json:"endedAt,omitempty"`
Source string `json:"source"`
Pages []ChatVisitedPage `json:"pages"`
Duration uint `json:"duration"`
}
type ChatVisitedPage struct {
DateTime SystemTime `json:"dateTime"`
Title string `json:"title,omitempty"`
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. // Tag struct.
type Tag struct { type Tag struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`