package lineobj import ( "encoding/json" "fmt" ) // SourceObject - type SourceObject struct { Type string `json:"type" cc:"type"` UserID string `json:"userId" cc:"userId"` GroupID string `json:"groupId" cc:"groupId"` } // EventObject - type EventObject struct { Source *SourceObject `json:"source" cc:"source"` Type string `json:"type" cc:"type"` Timestamp int64 `json:"timestamp" cc:"timestamp"` ReplyToken string `json:"replyToken" cc:"replyToken"` Message map[string]interface{} `json:"message" cc:"message"` } // HookEvent - type HookEvent struct { Events []*EventObject `json:"events"` } // ParseWebhookBody - func ParseWebhookBody(b []byte) *HookEvent { if len(b) == 0 { return nil } evt := &HookEvent{} err := json.Unmarshal(b, evt) if err != nil { return nil } return evt } // MessageEvent - func MessageEvent(e *EventObject) { switch e.Type { case "message": // TODO break default: fmt.Printf("line webhook type not match (%v)", e.Type) } } func messageType(e *EventObject) { msg := e.Message mtype, ok := msg["type"] if !ok { return } if t, ok := mtype.(string); ok { switch t { case "text": // TODO break case "iamge": // TODO break } } }