59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"surdeus.su/core/amo"
|
|
"surdeus.su/core/amo/api"
|
|
//"surdeus.su/core/amo/webhooks"
|
|
"surdeus.su/core/amo/events"
|
|
//"surdeus.su/core/ss"
|
|
//"surdeus.su/core/ss/statuses"
|
|
//"os"
|
|
"fmt"
|
|
//"io"
|
|
//"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
//fmt.Println(opts)
|
|
client, err := amo.NewAmoClient("secret.json")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
client.Api.Debug = true
|
|
|
|
company, err := client.GetCompany(80828925, "")
|
|
if err != nil && err != api.NoContentErr {
|
|
panic(err)
|
|
}
|
|
fmt.Printf("company: %+v\n", company)
|
|
interval := time.Second * 10
|
|
|
|
now := time.Now()
|
|
lastChanged := now
|
|
for {
|
|
time.Sleep(interval)
|
|
req := events.EventsRequest{}
|
|
req.Limit = 10
|
|
req.Filter.Entity = []string{"company", "contact"}
|
|
req.Filter.Type = events.CustomFieldValueChanged(
|
|
2192301,
|
|
2678095,
|
|
)
|
|
req.With = []string{"company_name"}
|
|
req.Filter.CreatedAt.From = lastChanged
|
|
events, err := client.GetEvents(req)
|
|
if err != nil {
|
|
fmt.Printf("Error: %s", err)
|
|
continue
|
|
}
|
|
if len(events) == 0 {
|
|
fmt.Printf("nothing changed")
|
|
continue
|
|
}
|
|
lastChanged = time.Now()
|
|
for i, event := range events {
|
|
fmt.Printf("event %d: %v\n", i, event)
|
|
}
|
|
}
|
|
}
|