abhinavdahiya / go-messenger-bot

Golang bindings for the Messenger Bot API
https://godoc.org/github.com/abhinavdahiya/go-messenger-bot
MIT License
52 stars 10 forks source link

setup on Appengine Standard Environment #14

Open matjazonline opened 6 years ago

matjazonline commented 6 years ago

On GAE Standard Environment I encountered this error:

fatal error: all goroutines are asleep - deadlock!

Setup in init function:

`func init() { bot := mbotapi.NewBotAPI(PAGE_ACCESS_TKN, "whk", "sekret")

callbacks, mux := bot.SetWebhook("/webhook")

var gaeCtx context.Context

var handlerFunc http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
    r = r.WithContext(appengine.NewContext(r))
    gaeCtx = r.Context()
    mux.ServeHTTP(w, r)
}

http.Handle("/webhook", handlerFunc)

for callback := range callbacks {
    log.Debugf(gaeCtx, "[%#v] %s", callback.Sender, callback.Message.Text)
    msg := mbotapi.NewMessage(callback.Message.Text)
    bot.Send(callback.Sender, msg, mbotapi.RegularNotif)
}

}`

I see that otherwise mbotapi would work by setting GAE's urlfetch.Client pointer.