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

Can this bot be used as part of an existing web app with its own routing? #5

Open tonyalaribe opened 7 years ago

tonyalaribe commented 7 years ago

I have an eccomerce platform, and would like to build a facebook bot to interact with the platform. I;m currently using julienschmidt/httprouter for routing. How can i attach the webhook to the router?

ghost commented 7 years ago

I had to copy over SetWebhook implementation since I had only 1 http port available.

ghost commented 7 years ago

@tonyalaribe Success in the challenge ... 😄

tonyalaribe commented 7 years ago

Lmao... @kelonye seems i'm not the only one in the challenge. Thanks for the headsup.

alsuren commented 7 years ago

Most http frameworks seem to have a way to use a http.Handler to handle specific paths. If you pass the mux of callbacks, mux := bot.SetWebhook("/webhook") into it, it should just work.

For my app (using gin) I had to do:

    router.GET("/webhook", gin.WrapH(mux))
    router.POST("/webhook", gin.WrapH(mux))

For julienschmidt/httprouter it looks like this method will do what you want, but I've not tried it: https://godoc.org/github.com/julienschmidt/httprouter#Router.Handler