-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Webhook health check endpoint #272
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually love this PR! Please fix the little details, we merge this in!
@@ -133,8 +133,13 @@ class TelegramBotWebHook { | |||
debug('WebHook request URL: %s', req.url); | |||
debug('WebHook request headers: %j', req.headers); | |||
|
|||
// If there isn't token on URL | |||
if (!this._regex.test(req.url)) { | |||
if (/\/healthz/.test(req.url)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make this configurable, like with this._regexp
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Done.
// If there isn't token on URL | ||
if (!this._regex.test(req.url)) { | ||
if (/\/healthz/.test(req.url)) { | ||
// If this is a helth check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uuuuuh! Typo! 😸
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops, thanks! 🙈
* @param {Boolean} [options.https=false] Use https | ||
* @return {Promise} | ||
*/ | ||
sendWebHook, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we named it sendWebHookRequest
, so it makes more sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, fixed!
cdd0e6c
to
998c652
Compare
debug('WebHook health check passed'); | ||
res.statusCode = 200; | ||
res.end('OK'); | ||
} else if (!this._regex.test(req.url)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should test for the token first, then the health endpoint, considering that we do not want to waste too much CPU with each and every update we receive on the webhook! What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, changed the order.
Codecov Report
Continue to review full report at Codecov.
|
998c652
to
3263c6c
Compare
References: * Author: @mironov (https://github.com/mironov) * PR: #272
Thanks @mironov for your time and effort in this PR! Awesome! 🎉 |
Added: 1. Add constructor options: * (#243) `options.polling.params` (by @GochoMugo, requested-by @sidelux) 1. Add methods: * (#74) *TelegramBot#removeReplyListener()* (by @githugger) 1. (#283) Add proper error handling (by @GochoMugo) 1. (#272) Add health-check endpoint (by @mironov) * `options.webHook.healthEndpoint` 1. (#152) Add test for TelegramBot#sendDocument() using 'fileOpts' param (by @evolun) 1. Document `options.webHook.host` (by @GochoMugo) 1. (#264) Add Bot API version to README (by @kamikazechaser) 1. Add examples: - (#271) WebHook on Heroku (by @TheBeastOfCaerbannog) - (#274) WebHook on Zeit Now (by @ferrari) Changed: 1. (#147) Use *String#indexOf()*, instead of *RegExp#test()*, to find token in webhook request (by @AVVS) Fixed: * Fix bug: - (#275, #280) fix es6 syntax error on Node.js v4.x (by @CrazyAbdul) - (#276) promise.warning from `request-promise` (by @GochoMugo, reported-by @preco21) - (#281) fix handling error during polling (by @GochoMugo, reported-by @dimawebmaker) - (#284) fix error during deletion of already-set webhook, during polling (by @GochoMugo, reported-by @dcparga) 1. Fix links in documentation (by @Ni2c2k)
Shipped in v0.27.0. |
References: * Author: @mironov (https://github.com/mironov) * PR: yagop/node-telegram-bot-api#272
References: * Author: @mironov (https://github.com/mironov) * PR: yagop/node-telegram-bot-api#272
Docker-ized environments usually expose an HTTP endpoint for health checks.
For example, in order to use a bot built with this lib in a kubernetes cluster, we have to give it an HTTP endpoint that responds 200 OK.
Refs:
https://github.com/kubernetes/contrib/tree/master/ingress/controllers/gce#health-checks
https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#defining-a-liveness-http-request