feat: add /status command to verify Better Stack connectivity - #15
Conversation
Makes a live GET request to the Better Stack incidents API to confirm the bot token is valid and the API is reachable. Returns HTTP status, policy ID (restricted for unauthorized users), and allowlist state. Also adds /status to /help command list. Closes #12
jangid
left a comment
There was a problem hiding this comment.
Review
Clean, well-structured PR. Follows existing patterns (edit-in-place UX, same error handling style). A few issues worth flagging:
Issues
-
/statusleaks connectivity info to unauthorized users —/alertblocks unauthorized users, but/statuslets anyone check if the API is connected, see the allowlist size, and probe error details. Consider gating it behind the sameALLOWED_USERScheck, or at least returning a minimal response for unauthorized users. -
PR body says "Closes #12" — Issue #12 was about
/helpand/start, which are already implemented and closed. This should reference a new issue or drop theClosesline. -
No rate limiting on
/status—/alerthas a 2-minute cooldown but/statusmakes an authenticated API call to Better Stack on every invocation with no throttle. A user (or bot spam) could hammer it. Consider reusing the cooldown map or adding a lighter one.
Nits
?per_page=1fetches a real incident just to verify connectivity. Works fine, but a lighter-weight endpoint (if Better Stack has one) would be cleaner. Not a blocker.axiosError.message ?? 'unknown error'—messageon a real Error is always defined, so'unknown error'is effectively dead code. Harmless.
What looks good
- Same edit-in-place UX pattern as
/alert - Policy ID hidden from unauthorized users
- Proper Markdown escaping on error detail
- Structured logging with userId and status
/helpupdated to include the new command
- Block unauthorized users before making any API call (mirrors /alert) - Add 2-minute cooldown per user via a namespaced key (status:<userId>) to prevent API hammering - Remove now-redundant authorized check and policyLine conditional - Remove unreachable dead code (axiosError.message ?? 'unknown error')
|
Thanks for the thorough review @jangid! Here's what was addressed in commit 00fed42: 1. 2. No rate limiting on 3. Noted (not changed):
|
jangid
left a comment
There was a problem hiding this comment.
Re-reviewed after the ~5-week pause. Thanks @harshaalphafi — your commit 00fed42 cleanly addresses all three substantive points from my earlier review:
- Auth gating ✅
/statusnow blocks unauthorized users with the sameALLOWED_USERSguard before any API call, mirroring/alert. The redundantpolicyLineconditional was correctly dropped. - Rate limiting ✅ Reusing the
cooldownsmap with a namespacedstatus:<userId>key (no collision with/alert) is exactly right. - Dead-code fallback ✅ Removed.
The command logic is good to go from my side. Two small things keep me at comment rather than approve:
-
CI is red, and part of that is this PR. I installed deps and ran
npm run fmt:checkagainst your HEAD (00fed42):bot.tsfailsprettier --check. Most of it is pre-existing tree-wide debt —mainitself has been red since CI landed inf6057c5, andeslint.config.mjs/README.mdfail independently of this PR — but your new/statusblock does contribute one genuine violation: theauthLineternary needs reformatting. A quicknpm run fmt && git commiton the new code clears your part. (Separately, someone should land a tree-wideprettier --writeonmainto get CI green again — happy to do that in its own PR so this one isn't blocked on unrelated debt.) -
Closes #12is still in the commit body. You noted you'd fix the PR description — that's still pending, and the commit message references the wrong issue (#12 was/help+/start). Point it at the actual/statusissue or drop the line.
Not abandoned in my view — just stalled. The work is essentially done. If you can run npm run fmt on the new code and fix the issue reference, I'm happy to approve. If priorities have shifted and this isn't worth finishing, let's close it rather than leave it open.
Automated review — PR stale since 2026-06-22The The two items keeping this at comment are the same ones @jangid flagged on 2026-06-22 — both still unaddressed (HEAD is still
Neither is a code-correctness problem — the feature is essentially done. Running Automated review; no approval implied. |
Summary
Implements the
/statuscommand from #12. The original issue requested three commands —/start,/help, and/status. The first two were implemented in commit9bc167aand the issue was closed, but/statuswas skipped as optional at the time./statusmakes a liveGETto the Better Stack incidents API using the configured bearer token⏳placeholder is sent immediately, then edited in-place with the result (same UX pattern as/alert)ALLOWED_USERS— unauthorized users are rejected before any API call is madecooldownsmap (namespaced asstatus:<userId>)Behaviour
Connected (authorized user):
API unreachable or token invalid:
Test plan
npx tsc --noEmitpasses/statusin Telegram returns connected message with correct HTTP 200/statuswith an invalidBETTER_STACK_API_TOKENreturns the unreachable message with HTTP 401🚫 Error: You are not authorized to use this command./statuswithin 2 minutes returns the cooldown message with remaining seconds/helpnow lists/status