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

Commit

Permalink
Add "/" as default WebhookURL
Browse files Browse the repository at this point in the history
This is because an empty string is *invalid* in net/http and will yield
a panic.
  • Loading branch information
paked committed May 19, 2016
1 parent 036b286 commit 1dc4bcc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions messenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Options struct {
VerifyToken string
// Token is the access token of the Facebook page to send messages from.
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
}

Expand Down Expand Up @@ -53,6 +53,10 @@ func New(mo Options) *Messenger {
token: mo.Token,
}

if mo.WebhookURL == "" {
mo.WebhookURL = "/"
}

m.verifyHandler = newVerifyHandler(mo.VerifyToken)
m.mux.HandleFunc(mo.WebhookURL, m.handle)

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

err := json.NewDecoder(r.Body).Decode(&rec)
if err != nil {
fmt.Println(err)
fmt.Println("could not decode response:", err)
fmt.Fprintln(w, `{status: 'not ok'}`)
return
}
Expand Down

0 comments on commit 1dc4bcc

Please sign in to comment.