1
0
mirror of synced 2024-11-25 22:36:03 +03:00

Add auto-verify

This commit is contained in:
Harrison 2016-04-18 20:03:57 +10:00
parent f8da84d8c9
commit 494b974cb2

View File

@ -40,6 +40,7 @@ type Messenger struct {
messageHandlers []MessageHandler messageHandlers []MessageHandler
deliveryHandlers []DeliveryHandler deliveryHandlers []DeliveryHandler
token string token string
verifyHandler func(http.ResponseWriter, *http.Request)
} }
// New creates a new Messenger. You pass in Options in order to affect settings. // New creates a new Messenger. You pass in Options in order to affect settings.
@ -49,11 +50,8 @@ func New(mo Options) *Messenger {
token: mo.Token, token: mo.Token,
} }
if mo.Verify { m.verifyHandler = newVerifyHandler(mo.VerifyToken)
m.mux.HandleFunc(WebhookURL, newVerifyHandler(mo.VerifyToken)) m.mux.HandleFunc(WebhookURL, m.handle)
} else {
m.mux.HandleFunc(WebhookURL, m.handle)
}
return m return m
} }
@ -98,6 +96,11 @@ func (m *Messenger) ProfileByID(id int64) (Profile, error) {
// handle is the internal HTTP handler for the webhooks. // handle is the internal HTTP handler for the webhooks.
func (m *Messenger) handle(w http.ResponseWriter, r *http.Request) { func (m *Messenger) handle(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
m.verifyHandler(w, r)
return
}
var rec Receive var rec Receive
err := json.NewDecoder(r.Body).Decode(&rec) err := json.NewDecoder(r.Body).Decode(&rec)