1
0
mirror of synced 2025-02-18 06:13:13 +03:00

Add "/" as default WebhookURL

This is because an empty string is *invalid* in net/http and will yield
a panic.
This commit is contained in:
Harrison 2016-05-20 09:18:01 +10:00
parent 036b286d6b
commit 1dc4bcc67d

View File

@ -23,7 +23,7 @@ type Options struct {
VerifyToken string VerifyToken string
// Token is the access token of the Facebook page to send messages from. // Token is the access token of the Facebook page to send messages from.
Token string Token string
// WebhookURL is where the Messenger client should listen for webhook events. // WebhookURL is where the Messenger client should listen for webhook events. Leaving the string blank implies a path of "/".
WebhookURL string WebhookURL string
} }
@ -53,6 +53,10 @@ func New(mo Options) *Messenger {
token: mo.Token, token: mo.Token,
} }
if mo.WebhookURL == "" {
mo.WebhookURL = "/"
}
m.verifyHandler = newVerifyHandler(mo.VerifyToken) m.verifyHandler = newVerifyHandler(mo.VerifyToken)
m.mux.HandleFunc(mo.WebhookURL, m.handle) m.mux.HandleFunc(mo.WebhookURL, m.handle)
@ -113,7 +117,7 @@ func (m *Messenger) handle(w http.ResponseWriter, r *http.Request) {
err := json.NewDecoder(r.Body).Decode(&rec) err := json.NewDecoder(r.Body).Decode(&rec)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println("could not decode response:", err)
fmt.Fprintln(w, `{status: 'not ok'}`) fmt.Fprintln(w, `{status: 'not ok'}`)
return return
} }