102 lines
2 KiB
Go
102 lines
2 KiB
Go
package main
|
|
|
|
import (
|
|
"vultras.su/core/amo"
|
|
"vultras.su/core/amo/api"
|
|
"vultras.su/core/amo/webhooks"
|
|
"vultras.su/core/amo/events"
|
|
"vultras.su/core/bond"
|
|
"vultras.su/core/bond/statuses"
|
|
//"os"
|
|
"fmt"
|
|
"io"
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
type Context = bond.Context
|
|
var (
|
|
gclient *amo.Client
|
|
)
|
|
|
|
var root = bond.Root(bond.Path().
|
|
Def(
|
|
"hook",
|
|
bond.Func(func(c *Context){
|
|
v := webhooks.Request{}
|
|
c.Scan(&v)
|
|
if c.ScanErr() != nil {
|
|
fmt.Println("scan-err:", c.ScanErr())
|
|
}
|
|
bts, err := json.MarshalIndent(v, "", "\t")
|
|
if err != nil {
|
|
fmt.Println("marsh-error:", err)
|
|
}
|
|
fmt.Println("request:", string(bts))
|
|
|
|
c.SetStatus(statuses.OK)
|
|
}),
|
|
).Def(
|
|
"auth",
|
|
bond.Func(func(c *Context){
|
|
fmt.Println("header:", c.R.Header)
|
|
fmt.Println("content-type:", c.ContentType())
|
|
bts, _ := io.ReadAll(c.R.Body)
|
|
fmt.Println("request:", string(bts))
|
|
c.SetStatus(statuses.OK)
|
|
return
|
|
v := map[string]any{}
|
|
c.Scan(&v)
|
|
if c.ScanErr() != nil {
|
|
fmt.Println("scan-err:", c.ScanErr())
|
|
}
|
|
fmt.Println("request:", v)
|
|
|
|
c.SetStatus(statuses.OK)
|
|
}),
|
|
))
|
|
|
|
func main() {
|
|
//fmt.Println(opts)
|
|
client, err := amo.NewAmoClient("secret.json")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
client.Api.Debug = true
|
|
gclient = client
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|