go-messenger-bot icon indicating copy to clipboard operation
go-messenger-bot copied to clipboard

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

Open tonyalaribe opened this issue 8 years ago • 4 comments

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?

tonyalaribe avatar Feb 16 '17 19:02 tonyalaribe

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

ghost avatar Feb 18 '17 16:02 ghost

@tonyalaribe Success in the challenge ... 😄

ghost avatar Feb 18 '17 16:02 ghost

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

tonyalaribe avatar Feb 18 '17 17:02 tonyalaribe

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

alsuren avatar May 06 '17 17:05 alsuren