-
Notifications
You must be signed in to change notification settings - Fork 474
Init stack telegram alerts #978
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
base: dev
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds a Telegram callback flow: the init-stack CLI posts completion payloads to a backend callback endpoint; the backend validates and forwards formatted notifications to the Telegram Bot API. New env vars and a local script env override were added. Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as init-stack CLI
participant Backend as Backend Callback Endpoint
participant Telegram as Telegram Bot API
CLI->>Backend: POST /init-script-callback (completion payload)
rect rgb(235, 245, 255)
Backend->>Backend: validate payload & env vars
Backend->>Backend: build formatted message
end
Backend->>Telegram: POST /bot{token}/sendMessage (formatted text)
alt Telegram OK
Telegram-->>Backend: 200 OK
Backend-->>CLI: 200 { success: true }
else Telegram Error
Telegram-->>Backend: error
Backend-->>Caller: throws StackAssertionError / 500
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (2)📚 Learning: 2025-10-20T22:25:40.427ZApplied to files:
📚 Learning: 2025-10-20T22:25:40.427ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Greptile Overview
Greptile Summary
Adds Telegram notification system to track init-stack CLI usage by sending alerts on success/failure to a configured Telegram bot.
Key Changes
- New backend API endpoint at
/api/latest/integrations/telegramfor forwarding messages to Telegram Bot API - New
telegram.tsmodule in init-stack package to format and send notifications - Integration points in
index.tsto notify on both success and error paths - Environment variables
STACK_INIT_TELEGRAM_BOT_TOKENandSTACK_INIT_TELEGRAM_CHAT_IDfor configuration
Critical Issues Found
.env.developmenthas incompleteSTACKline (line 72) that breaks the file syntax- API endpoint mismatch:
telegram.tscalls/api/v1/integrations/telegrambut the route is defined at/api/latest/integrations/telegram - Missing error handling in backend route - returns success even when Telegram API fails
- Telegram notification errors are silently swallowed with no logging
Confidence Score: 1/5
- This PR has critical issues that will cause runtime failures
- Two breaking bugs: broken
.env.developmentfile syntax and wrong API endpoint path that will cause all notifications to fail with 404 errors apps/backend/.env.development(broken syntax) andpackages/init-stack/src/telegram.ts(wrong endpoint)
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/backend/.env.development | 0/5 | Incomplete STACK line (line 72) breaks env file syntax |
| packages/init-stack/src/telegram.ts | 2/5 | New Telegram notification module with wrong API endpoint and no error handling |
| apps/backend/src/app/api/latest/integrations/telegram/route.tsx | 3/5 | New API route for Telegram messaging, missing error handling for Telegram API failures |
Sequence Diagram
sequenceDiagram
participant User as User/CI
participant InitStack as init-stack CLI
participant Telegram as telegram.ts
participant Backend as Backend API
participant TelegramAPI as Telegram Bot API
User->>InitStack: Run init-stack command
alt Success Path
InitStack->>InitStack: Execute initialization
InitStack->>InitStack: Collect metrics & options
InitStack->>Telegram: notifyTelegramOnCompletion(success=true)
Telegram->>Telegram: buildMessage(payload)
Telegram->>Backend: POST /api/v1/integrations/telegram
Note over Telegram,Backend: ⚠️ Wrong endpoint (should be /api/latest)
Backend->>Backend: Validate env vars
Backend->>TelegramAPI: POST /bot{token}/sendMessage
TelegramAPI-->>Backend: Response
Backend-->>Telegram: {success: true}
Telegram-->>InitStack: void (no error handling)
InitStack->>User: Show success message
else Failure Path
InitStack->>InitStack: Error occurs
InitStack->>Telegram: notifyTelegramOnCompletion(success=false)
Telegram->>Telegram: buildMessage(payload with error)
Telegram->>Backend: POST /api/v1/integrations/telegram
Backend->>TelegramAPI: POST /bot{token}/sendMessage
TelegramAPI-->>Backend: Response
Backend-->>Telegram: {success: true}
Telegram-->>InitStack: void (errors swallowed)
InitStack->>User: Show error & exit(1)
end
Additional Comments (1)
-
apps/backend/.env.development, line 72 (link)syntax: Incomplete line
STACKbreaks the env file
6 files reviewed, 5 comments
apps/backend/src/app/api/latest/integrations/telegram/route.tsx
Outdated
Show resolved
Hide resolved
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.
Actionable comments posted: 6
🧹 Nitpick comments (1)
packages/init-stack/src/telegram.ts (1)
10-10: Consider using Map instead of Record per coding guidelines.The coding guidelines specify using ES6 Maps instead of Records in TypeScript code. While Record is acceptable for type definitions representing JSON payloads, consider whether a Map would be more appropriate here if the keys are dynamic.
As per coding guidelines.
If you decide to change it:
- options: Record<string, unknown>, + options: Map<string, unknown>,Note: This would require changes in the calling code (index.ts) to pass a Map instead of an object. Given that
optionslikely comes fromprogram.opts()which returns a plain object, keeping the Record type may be more pragmatic for this use case.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
apps/backend/.env(1 hunks)apps/backend/src/app/api/latest/integrations/telegram/route.tsx(1 hunks)packages/init-stack/package.json(1 hunks)packages/init-stack/src/index.ts(3 hunks)packages/init-stack/src/telegram.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use ES6 Maps instead of Records wherever possible in TypeScript code
Files:
packages/init-stack/src/index.tsapps/backend/src/app/api/latest/integrations/telegram/route.tsxpackages/init-stack/src/telegram.ts
🧬 Code graph analysis (2)
packages/init-stack/src/index.ts (1)
packages/init-stack/src/telegram.ts (1)
notifyTelegramOnCompletion(22-26)
apps/backend/src/app/api/latest/integrations/telegram/route.tsx (3)
apps/backend/src/route-handlers/smart-route-handler.tsx (1)
createSmartRouteHandler(209-294)packages/stack-shared/src/schema-fields.ts (5)
yupObject(247-251)adaptSchema(330-330)yupString(187-190)yupNumber(191-194)yupBoolean(195-198)packages/stack-shared/src/utils/env.tsx (1)
getEnvVariable(16-58)
🪛 dotenv-linter (4.0.0)
apps/backend/.env
[warning] 86-86: [SpaceCharacter] The line has spaces around equal sign
(SpaceCharacter)
[warning] 86-86: [UnorderedKey] The STACK_INIT_TELEGRAM_BOT_TOKEN key should go before the STACK_INTEGRATION_CLIENTS_CONFIG key
(UnorderedKey)
[warning] 86-86: [ValueWithoutQuotes] This value needs to be surrounded in quotes
(ValueWithoutQuotes)
[warning] 87-87: [UnorderedKey] The STACK_INIT_TELEGRAM_CHAT_ID key should go before the STACK_INTEGRATION_CLIENTS_CONFIG key
(UnorderedKey)
[warning] 87-87: [ValueWithoutQuotes] This value needs to be surrounded in quotes
(ValueWithoutQuotes)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: build (22.x)
- GitHub Check: build (22.x)
- GitHub Check: build (22.x)
- GitHub Check: restart-dev-and-test-with-custom-base-port
- GitHub Check: setup-tests
- GitHub Check: check_prisma_migrations (22.x)
- GitHub Check: all-good
- GitHub Check: lint_and_build (latest)
- GitHub Check: docker
- GitHub Check: restart-dev-and-test
- GitHub Check: Vercel Agent Review
- GitHub Check: Security Check
🔇 Additional comments (1)
packages/init-stack/package.json (1)
15-15: LGTM!The addition of
STACK_INIT_API_BASE_URLfor local development aligns with the existing pattern of environment variable overrides in the script.
apps/backend/src/app/api/latest/integrations/telegram/route.tsx
Outdated
Show resolved
Hide resolved
apps/backend/src/app/api/latest/integrations/telegram/route.tsx
Outdated
Show resolved
Hide resolved
|
Some new issue(s) might be present. Please use the following link(s) to view them: https://zeropath.com/app/issues/ee47130d-ce55-47a6-990a-5a050c3bf06a Additionally, the following low severity issue(s) were found: https://zeropath.com/app/issues/71318597-69d7-42cf-99f0-37ef9703d0ea Reply to this PR with |
apps/backend/src/app/api/latest/integrations/telegram/route.tsx
Outdated
Show resolved
Hide resolved
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/init-stack/package.json (1)
15-15: Consider documenting the port scheme inline.The port concatenation
${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}02is intentional but may not be immediately obvious to future maintainers. Adding a brief inline comment or extracting it to a.env.localor.env.examplefile might improve clarity for developers unfamiliar with the port allocation scheme.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/init-stack/package.json(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: Vercel Agent Review
- GitHub Check: all-good
- GitHub Check: build (22.x)
- GitHub Check: setup-tests
- GitHub Check: docker
- GitHub Check: build (22.x)
- GitHub Check: build (22.x)
- GitHub Check: restart-dev-and-test-with-custom-base-port
- GitHub Check: restart-dev-and-test
- GitHub Check: check_prisma_migrations (22.x)
- GitHub Check: lint_and_build (latest)
- GitHub Check: Security Check
🔇 Additional comments (1)
packages/init-stack/package.json (1)
15-15: Change is correct and verified.The env var
STACK_INIT_API_BASE_URLis properly used inpackages/init-stack/src/telegram.ts(line 23) to construct the Telegram notification endpoint URL. The backend correctly runs on port 8102 locally (${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}02), as documented inAGENTS.mdandapps/backend/package.json. Alltest-run-*scripts automatically inherit this env var since they invokeinit-stack:local, so no additional setup is needed in other scripts.
apps/backend/src/app/api/latest/integrations/telegram/route.tsx
Outdated
Show resolved
Hide resolved
apps/backend/src/app/api/latest/integrations/telegram/route.tsx
Outdated
Show resolved
Hide resolved
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.
some comments!
|
Some new issue(s) might be present. Please use the following link(s) to view them: Additionally, the following low severity issue(s) were found: https://zeropath.com/app/issues/f1094827-b6ea-4d49-baea-2a8e80e3a05f Reply to this PR with |
Summary by CodeRabbit
New Features
Chores