Add auto-verify
This commit is contained in:
parent
f8da84d8c9
commit
494b974cb2
11
messenger.go
11
messenger.go
@ -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))
|
|
||||||
} else {
|
|
||||||
m.mux.HandleFunc(WebhookURL, m.handle)
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user