Skip to content
This repository was archived by the owner on Jan 1, 2023. It is now read-only.

Commit 1dc4bcc

Browse files
committed
Add "/" as default WebhookURL
This is because an empty string is *invalid* in net/http and will yield a panic.
1 parent 036b286 commit 1dc4bcc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

messenger.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Options struct {
2323
VerifyToken string
2424
// Token is the access token of the Facebook page to send messages from.
2525
Token string
26-
// WebhookURL is where the Messenger client should listen for webhook events.
26+
// WebhookURL is where the Messenger client should listen for webhook events. Leaving the string blank implies a path of "/".
2727
WebhookURL string
2828
}
2929

@@ -53,6 +53,10 @@ func New(mo Options) *Messenger {
5353
token: mo.Token,
5454
}
5555

56+
if mo.WebhookURL == "" {
57+
mo.WebhookURL = "/"
58+
}
59+
5660
m.verifyHandler = newVerifyHandler(mo.VerifyToken)
5761
m.mux.HandleFunc(mo.WebhookURL, m.handle)
5862

@@ -113,7 +117,7 @@ func (m *Messenger) handle(w http.ResponseWriter, r *http.Request) {
113117

114118
err := json.NewDecoder(r.Body).Decode(&rec)
115119
if err != nil {
116-
fmt.Println(err)
120+
fmt.Println("could not decode response:", err)
117121
fmt.Fprintln(w, `{status: 'not ok'}`)
118122
return
119123
}

0 commit comments

Comments
 (0)