Closed sknr closed 2 years ago
Hi @sknr,
What's not clear to me is how the custom HTTP server is going to pass to the dispatcher the incoming updates. Does the user have to pass to the custom HTTP server the HandleWebhook
dispatcher method for doing so?
You're absolutely right @NicoNex, the user has to pass the HandleWebhook to the server he will set on the dispatcher. I can write an example within the read.me file if you like, so it will be clear how to use it. But it doesn't change too much IMO, because right now, the user has handle the Webhook by himself, too.
Yes please, if it's not too much of a hassle for you a little example in the readme would be very nice and useful for the users.
@NicoNex please have a look at my last commit (c0a1158). I added the HandleWebhook automatically now so that the user does not have to care about registering the webhook himself.
@NicoNex I added an example. Feel free to adjust as needed ;)
@sknr from the example in the readme I see that you instantiate a new *http.ServeMux
, wouldn't it get overridden once you call dsp.ListenWebhook(...)
by the code in your commit c0a1158f5f7ba2e3296fc94c6ab61a6b7b5e95fa?
@NicoNex if you like the first approach better, let's revert the commit c0a1158 and I'll adjust the example within the README.md file.
@NicoNex Depending on the path defined in u.EscapedPath(), the currently registered path of the custom Handler might be overridden by the HandleWebhook method. This is on purpose so that the registered webhookUR, which was registered on the telegram servers, will be correctly processed by the HandleWebhook method. All other routes should stay intact. But maybe I overlooked something.
My bad you're absolutely right, I overlooked that in the commit c0a1158f5f7ba2e3296fc94c6ab61a6b7b5e95fa you save the user-defined multiplexer with mux.Handle("/", d.httpServer.Handler)
before reassigning it with d.httpServer.Handler = mux
, so your pr is totally ok for me and so is the example in the readme. I'll just slightly modify the example adding a good practice and then the pr will be merged.
Thanks again for the contribution and keep up with your awesome work.
Hi @NicoNex,
I was wondering if it will be better to pass a pointer to an http.Server instead of the http.Handler because then, the user of the your library has more control and can for example, initiate a gracefully server shutdown by himself. I know that this will bring braking changes, and I'm sad that I don't came up earlier with this idea, but maybe you can consider the change for the next major version. Thanks in advance.