github.com/grokify/go-ringcentral-client@v0.3.31/office/v1/examples/event_parse/event_parse.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "io/ioutil" 7 "log" 8 "os" 9 "path/filepath" 10 11 "github.com/grokify/mogo/fmt/fmtutil" 12 13 rc "github.com/grokify/go-ringcentral-client/office/v1/client" 14 ru "github.com/grokify/go-ringcentral-client/office/v1/util" 15 ) 16 17 type Body struct { 18 ID string 19 Body interface{} 20 } 21 22 type BodyOne struct { 23 Foo string 24 } 25 26 type BodyTwo struct { 27 Bar string 28 } 29 30 func main() { 31 str1 := `{"ID":"MY_ID","Foo":"Here"}` 32 str2 := `{"ID":"MY_ID","Bar":"Here"}` 33 34 fmt.Println(str1) 35 fmt.Println(str2) 36 37 body := &Body{} 38 err := json.Unmarshal([]byte(str1), body) 39 if err != nil { 40 log.Fatal(err) 41 } 42 fmtutil.PrintJSON(body) 43 44 if 1 == 1 { 45 msg, err := ru.GetFileBytesForEventType("instant_message_sms") 46 if err != nil { 47 log.Fatal(err) 48 } 49 50 evt, err := ru.EventParseBytes(msg) 51 if err != nil { 52 log.Fatal(err) 53 } 54 55 if evt.IsEventType(ru.InstantMessageEvent) { 56 body, err := evt.GetInstantMessageBody() 57 if err != nil { 58 log.Fatal(err) 59 } 60 fmtutil.PrintJSON(body) 61 } else { 62 log.Fatal("is not InstantMessageEvent") 63 } 64 } 65 66 if 1 == 0 { 67 msg, err := ru.GetFileBytesForEventType("glip_post") 68 if err != nil { 69 log.Fatal(err) 70 } 71 //fmt.Println(string(msg)) 72 73 evt, err := ru.EventParseBytes(msg) 74 if err != nil { 75 log.Fatal(err) 76 } 77 //fmtutil.PrintJSON(evt) 78 if evt.IsEventType(ru.GlipPostEvent) { 79 body, err := evt.GetGlipPostEventBody() 80 if err != nil { 81 log.Fatal(err) 82 } 83 fmtutil.PrintJSON(body) 84 } 85 } 86 if 1 == 1 { 87 file := filepath.Join( 88 os.Getenv("GOPATH"), 89 "/src/github.com/grokify/go-ringcentral-client/office/v1/util/example_api-response_list-messages.json") 90 resp, err := ioutil.ReadFile(file) 91 if err != nil { 92 log.Fatal(err) 93 } 94 //fmt.Println(string(resp)) 95 info := &rc.GetMessageList{} 96 err = json.Unmarshal(resp, info) 97 if err != nil { 98 log.Fatal(err) 99 } 100 fmtutil.PrintJSON(info) 101 } 102 103 fmt.Println("DONE") 104 }