main.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package main
  2. import (
  3. "surdeus.su/core/amo"
  4. "surdeus.su/core/amo/api"
  5. //"surdeus.su/core/amo/webhooks"
  6. "surdeus.su/core/amo/events"
  7. //"surdeus.su/core/ss"
  8. //"surdeus.su/core/ss/statuses"
  9. //"os"
  10. "fmt"
  11. //"io"
  12. //"encoding/json"
  13. "time"
  14. )
  15. func main() {
  16. //fmt.Println(opts)
  17. client, err := amo.NewAmoClient("secret.json")
  18. if err != nil {
  19. panic(err)
  20. }
  21. client.Api.Debug = true
  22. company, err := client.GetCompany(80828925, "")
  23. if err != nil && err != api.NoContentErr {
  24. panic(err)
  25. }
  26. fmt.Printf("company: %+v\n", company)
  27. interval := time.Second * 10
  28. now := time.Now()
  29. lastChanged := now
  30. for {
  31. time.Sleep(interval)
  32. req := events.EventsRequest{}
  33. req.Limit = 10
  34. req.Filter.Entity = []string{"company", "contact"}
  35. req.Filter.Type = events.CustomFieldValueChanged(
  36. 2192301,
  37. 2678095,
  38. )
  39. req.With = []string{"company_name"}
  40. req.Filter.CreatedAt.From = lastChanged
  41. events, err := client.GetEvents(req)
  42. if err != nil {
  43. fmt.Printf("Error: %s", err)
  44. continue
  45. }
  46. if len(events) == 0 {
  47. fmt.Printf("nothing changed")
  48. continue
  49. }
  50. lastChanged = time.Now()
  51. for i, event := range events {
  52. fmt.Printf("event %d: %v\n", i, event)
  53. }
  54. }
  55. }