Skip to content

Conversation

@BilalG1
Copy link
Collaborator

@BilalG1 BilalG1 commented Oct 23, 2025

Summary by CodeRabbit

  • New Features

    • Stack initialization now sends completion callbacks (success/failure) to a configured notification service.
    • Backend endpoint added to receive and forward initialization completion notifications.
  • Chores

    • Added configuration entries for Telegram callback integration.
    • Local init tooling updated to respect a configurable API base URL for callback delivery.

@vercel
Copy link

vercel bot commented Oct 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
stack-backend Ready Ready Preview Comment Nov 5, 2025 11:40am
stack-dashboard Ready Ready Preview Comment Nov 5, 2025 11:40am
stack-demo Ready Ready Preview Comment Nov 5, 2025 11:40am
stack-docs Ready Ready Preview Comment Nov 5, 2025 11:40am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2025

Note

Other AI code review bot(s) detected

CodeRabbit 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.

Walkthrough

Adds 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

Cohort / File(s) Summary
Backend env
apps/backend/.env
Added STACK_TELEGRAM_BOT_TOKEN and STACK_TELEGRAM_CHAT_ID placeholders.
Local script env
packages/init-stack/package.json
Prepends STACK_INIT_API_BASE_URL=... to init-stack:local script.
CLI callback logic
packages/init-stack/src/index.ts
Imports and calls invokeCallback on success and error paths, sending context and error info.
CLI telegram client
packages/init-stack/src/telegram.ts
New types (TelegramErrorInfo, TelegramCompletionPayload) and exported invokeCallback(payload) sending JSON POST to configured base URL or default.
Backend callback route
apps/backend/src/app/api/.../init-script-callback/route.tsx
New POST handler validating completionPayloadSchema, requires Telegram env vars, builds message, posts to Telegram API, and returns { success: true }; includes safe JSON helpers and error handling.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Files needing extra attention:
    • apps/backend/.../init-script-callback/route.tsx — message formatting, schema fidelity, and Telegram error handling.
    • packages/init-stack/src/index.ts — ensure all context fields are serialized appropriately on success and error.
    • packages/init-stack/src/telegram.ts — base URL resolution and POST behavior.

Possibly related PRs

Poem

🐇 I hopped a log and sent a note,
A payload wrapped in carrot coat,
From CLI burrow to backend tree,
The bot now sings the init's decree,
Hooray — a hop, a ping, and glee!

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description contains only the repository's standard HTML comment reminder about reading CONTRIBUTING.md guidelines, with no additional substantive content whatsoever. While the minimal template was technically followed, the description provides zero explanation of what was changed, why these changes were needed, or how the Telegram integration works. This leaves reviewers without any context or rationale for the significant functional changes introduced across multiple files.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "Init stack telegram alerts" is concise, clear, and directly related to the main objectives of the changeset. The pull request adds comprehensive Telegram integration to the init-stack process, including environment variable configuration, a new callback module, and a backend route to handle completion notifications. The title accurately captures this primary change from the developer's perspective without unnecessary noise or vagueness.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch init-stack-telegram-alerter

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ae5b2bf and 3273f1a.

📒 Files selected for processing (1)
  • packages/init-stack/package.json (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-10-20T22:25:40.427Z
Learnt from: CR
PR: stack-auth/stack-auth#0
File: AGENTS.md:0-0
Timestamp: 2025-10-20T22:25:40.427Z
Learning: Applies to packages/{stack,js}/** : Never update packages/stack or packages/js directly; they are copies

Applied to files:

  • packages/init-stack/package.json
📚 Learning: 2025-10-20T22:25:40.427Z
Learnt from: CR
PR: stack-auth/stack-auth#0
File: AGENTS.md:0-0
Timestamp: 2025-10-20T22:25:40.427Z
Learning: Applies to packages/template/** : When changes are needed for stack or js packages, make them in packages/template instead

Applied to files:

  • packages/init-stack/package.json
⏰ 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: build (22.x)
  • GitHub Check: restart-dev-and-test
  • GitHub Check: check_prisma_migrations (22.x)
  • GitHub Check: setup-tests
  • GitHub Check: all-good
  • GitHub Check: restart-dev-and-test-with-custom-base-port
  • GitHub Check: build (22.x)
  • GitHub Check: lint_and_build (latest)
  • GitHub Check: build (22.x)
  • GitHub Check: docker
  • GitHub Check: Security Check
🔇 Additional comments (1)
packages/init-stack/package.json (1)

15-15: Verification complete: STACK_INIT_API_BASE_URL is properly consumed.

The environment variable is correctly declared in packages/init-stack/src/telegram.ts and read via process.env[API_BASE_ENV] with a fallback to the production API (https://api.stack-auth.com). The change enables local development to point to a configurable local endpoint, and the port construction defaults to 8102 as expected. No issues found.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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/telegram for forwarding messages to Telegram Bot API
  • New telegram.ts module in init-stack package to format and send notifications
  • Integration points in index.ts to notify on both success and error paths
  • Environment variables STACK_INIT_TELEGRAM_BOT_TOKEN and STACK_INIT_TELEGRAM_CHAT_ID for configuration

Critical Issues Found

  • .env.development has incomplete STACK line (line 72) that breaks the file syntax
  • API endpoint mismatch: telegram.ts calls /api/v1/integrations/telegram but 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.development file syntax and wrong API endpoint path that will cause all notifications to fail with 404 errors
  • apps/backend/.env.development (broken syntax) and packages/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
Loading

Additional Comments (1)

  1. apps/backend/.env.development, line 72 (link)

    syntax: Incomplete line STACK breaks the env file

6 files reviewed, 5 comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 options likely comes from program.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

📥 Commits

Reviewing files that changed from the base of the PR and between f20e74c and 269929e.

📒 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.ts
  • apps/backend/src/app/api/latest/integrations/telegram/route.tsx
  • packages/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_URL for local development aligns with the existing pattern of environment variable overrides in the script.

@zeropath-ai
Copy link

zeropath-ai bot commented Oct 23, 2025

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 @zeropath-ai followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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}02 is intentional but may not be immediately obvious to future maintainers. Adding a brief inline comment or extracting it to a .env.local or .env.example file might improve clarity for developers unfamiliar with the port allocation scheme.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 269929e and d0e8cf5.

📒 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_URL is properly used in packages/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 in AGENTS.md and apps/backend/package.json. All test-run-* scripts automatically inherit this env var since they invoke init-stack:local, so no additional setup is needed in other scripts.

@BilalG1 BilalG1 requested a review from N2D4 October 23, 2025 22:04
@BilalG1 BilalG1 assigned N2D4 and unassigned BilalG1 Oct 23, 2025
Copy link
Contributor

@N2D4 N2D4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments!

@github-actions github-actions bot assigned BilalG1 and unassigned N2D4 Oct 24, 2025
@zeropath-ai
Copy link

zeropath-ai bot commented Oct 27, 2025

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 @zeropath-ai followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

@BilalG1 BilalG1 requested a review from N2D4 October 27, 2025 20:07
@BilalG1 BilalG1 assigned N2D4 and unassigned BilalG1 Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants