-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for removing bots from the webhook server #118
Conversation
It looks good and it worked on my project. I have only found an issue, and it's when is used a custom URL. Right now, if we add a custom URL in the webhook, it doesn't work because it uses explicitly the token from the root URL. // This code didn't receive updates after the webhook was set.
if err := manager.updater.AddWebhook(bot, "/custom-url/"+token, ext.WebhookOpts{
SecretToken: manager.webhookSecret,
}); err != nil {
return nil, err
}
bot.SetWebhook(manager.webhookUrl+"/custom-url/"+token, &gotgbot.SetWebhookOpts{
MaxConnections: 100,
AllowedUpdates: nil,
DropPendingUpdates: true,
SecretToken: manager.webhookSecret,
}) I think the issue comes from here. The Close to this issue, I wonder if we could customize the identifier for the webhook of a bot. With this in mind, we can have a base URL for all webhooks and a custom identifier for each bot, mapping from the URL: What I want to achieve with this is not to be forced to set the full bot token as identifier in the webhook for a bot. Right now is mandatory, since the bot mapping is |
@svex99 You are entirely correct, thats my oversight entirely. Very good catch, thank you for that. I guess thats what I deserve for trying to do quick fixes. Let me take another proper look at the issue, shouldn't be too difficult to prepare! |
…onsist of the bot token
Have added an additional mapping of urlPath -> botToken so we can handle incoming URLs better. Let me know if that causes any other issues! |
@PaulSonOfLars, thank you for your hard work! Now we have an issue because the I was thinking about using a single map In the case of the webhooks, when calling Also, for bot removal, we just need the ID of the bot in both cases. I don't expect you to implement this solution, it may introduce some side effects I don't see right now. Thank you! |
Hey @svex99 - thanks again for the hard work in testing my tired and shoddy code. Excellent work 😆. I've gone ahead and patched the things you mentioned, as well as written a lot of new tests to cover those cases, and I hope I've now covered everything. At the very least, test coverage is higher than it was :p Ended up going with a second map of Anyway, third time the charm! |
Great @PaulSonOfLars! I'll be given a try to this soon. Thank you for your hard work! |
@svex99 Did you have the time to test that the above worked for you? |
@PaulSonOfLars everything looks good right now! |
What
This PR fixes an issue where adding a bot twice with the same token would cause a panic at the HTTP Handler level. This was caused by the fact that we never remove routes for bots that get removed, because the http router only supports adding routes, not removing them.
So, rather than continuously increase the number of bots (some of them dead) on the mux, it would be helpful to remove them completely. Luckily, this can easily be achieved by simply reusing the existing botMapping functionality, which actually handles exactly that usecase. Voila.
Impact