Conversation
Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
β¦afety Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
β¦TicketPayload Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Add support for configuring default ticket priority via UNTHREAD_DEFAULT_PRIORITY environment variable
There was a problem hiding this comment.
Pull Request Overview
This PR prepares the v1.0.0-beta.6 release by centralizing environment validation, adding configurable default ticket priority, and cleaning up inline non-null checks.
- Introduce
getDefaultTicketPriorityand wire it into ticket creation - Add global
validateEnvironment()call and remove manual env-var checks - Bump version to v1.0.0-beta.6 and update
.env.example
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/services/unthread.ts | Imported and applied default ticket priority; replaced manual env checks with non-null asserts |
| src/index.ts | Added global env validation; replaced manual token checks with non-null assertions |
| src/database/connection.ts | Removed manual POSTGRES_URL check; added non-null assertion |
| src/config/env.ts | Enhanced validation logging; added getDefaultTicketPriority; removed unused var |
| package.json | Updated version to v1.0.0-beta.6 |
| .env.example | Documented UNTHREAD_DEFAULT_PRIORITY |
Comments suppressed due to low confidence (5)
src/config/env.ts:36
- Add
UNTHREAD_API_KEYandTELEGRAM_BOT_TOKENtoREQUIRED_ENV_VARSso theyβre validated byvalidateEnvironment()before use.
const REQUIRED_ENV_VARS = [
src/config/env.ts:99
- Consider adding unit tests for
getDefaultTicketPriority()to cover valid, invalid, and missing environment values.
export function getDefaultTicketPriority(): 3 | 5 | 7 | 9 | undefined {
src/services/unthread.ts:324
- Add tests for
createTicketJSONto verify thatpriorityis only added to the payload whenUNTHREAD_DEFAULT_PRIORITYis set.
if (defaultPriority !== undefined) {
src/services/unthread.ts:318
- [nitpick] The non-null assertion on
CHANNEL_IDis redundant; itβs already asserted when declared. You can drop the!here.
channelId: CHANNEL_ID!,
src/index.ts:293
- [nitpick] Since
PLATFORM_REDIS_URLis checked invalidateEnvironment(), the!assertion here is no longer needed.
await BotsStore.initialize(db, process.env.PLATFORM_REDIS_URL!);
π WalkthroughWalkthroughSir, the system has received several updates. A new environment variable for default ticket priority has been introduced, with corresponding logic to handle and validate it. Logging has been standardized using LogEngine, and environment variable checks have been centralized for reliability. The package version has also been incremented. Changes
π Recent review detailsConfiguration used: CodeRabbit UI π Files selected for processing (1)
β Files skipped from review due to trivial changes (1)
β° Context from checks skipped due to timeout of 90000ms (2)
πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
π§Ή Nitpick comments (1)
src/config/env.ts (1)
13-13: Minor documentation inconsistency detected, sir.The documentation references
WEBHOOK_REDIS_URLas required, however, the AI summary indicates this variable was removed from the required list. Consider updating the documentation to reflect the current implementation state.- * - WEBHOOK_REDIS_URL: Redis connection for webhook event processing
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (6)
.env.example(1 hunks)package.json(1 hunks)src/config/env.ts(3 hunks)src/database/connection.ts(1 hunks)src/index.ts(3 hunks)src/services/unthread.ts(5 hunks)
π§° Additional context used
π§ Learnings (2)
π Common learnings
Learnt from: warengonzaga
PR: wgtechlabs/unthread-telegram-bot#24
File: docker-compose.yaml:29-29
Timestamp: 2025-06-22T10:12:09.684Z
Learning: The Unthread Telegram Bot project is currently in beta development phase (v1.0.0-beta.2) and does not yet have official versioned Docker builds available, making the use of :latest tags acceptable for development purposes in docker-compose.yaml.
package.json (1)
Learnt from: warengonzaga
PR: wgtechlabs/unthread-telegram-bot#24
File: docker-compose.yaml:29-29
Timestamp: 2025-06-22T10:12:09.684Z
Learning: The Unthread Telegram Bot project is currently in beta development phase (v1.0.0-beta.2) and does not yet have official versioned Docker builds available, making the use of :latest tags acceptable for development purposes in docker-compose.yaml.
𧬠Code Graph Analysis (2)
src/database/connection.ts (1)
src/config/env.ts (1)
isProduction(84-86)
src/services/unthread.ts (1)
src/config/env.ts (1)
getDefaultTicketPriority(99-115)
β° Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Validate Changes
π Additional comments (15)
package.json (1)
3-3: Excellent, sir! Version advancement proceeds as expected.The progression from beta.5.1 to beta.6 follows proper semantic versioning protocols for your beta release cycle. This aligns perfectly with the new priority configuration feature and environment validation enhancements detailed in the accompanying modifications.
.env.example (1)
34-37: Splendid documentation, sir! Priority configuration implemented with exceptional clarity.The new
UNTHREAD_DEFAULT_PRIORITYenvironment variable is meticulously documented with clear value mappings and usage instructions. The default value of 5 (medium) represents a sensible baseline, and the guidance about empty values creating tickets without priority is precisely what users need to understand the feature behavior.src/database/connection.ts (2)
66-66: Consistent application of the new validation pattern, sir.The non-null assertion for
POSTGRES_URLin the logging context maintains consistency with the validation approach established at line 59.
59-59: Validation Confirmed: POSTGRES_URL is Covered by Centralized Env ValidationCertainly, sir. I have verified that
validateEnvironment()in src/config/env.ts iterates overREQUIRED_ENV_VARS, which includes"POSTGRES_URL", and will throw if itβs absent. The non-null assertion onprocess.env.POSTGRES_URLis therefore safe.β’ Location: src/config/env.ts (REQUIRED_ENV_VARS array, lines 39β43)
β’ No further changes required.src/index.ts (3)
31-33: Excellent architectural decision, sir! Environment validation now proceeds with military precision.The centralized environment validation approach ensures all critical configuration issues are identified before any service initialization begins. This early validation pattern prevents partial system initialization failures and provides clearer error messaging to operators.
58-58: Non-null assertion now operates under validated conditions, sir.With the upstream environment validation in place, this assertion operates with confidence that
TELEGRAM_BOT_TOKENhas been verified for presence and validity.
293-293: Platform Redis URL assertion follows the established validation protocol, sir.The non-null assertion for
PLATFORM_REDIS_URLmaintains consistency with the centralized validation pattern, ensuring the BotsStore initialization proceeds with verified configuration.src/services/unthread.ts (4)
122-134: Superb interface definition, sir! The CreateTicketPayload structure exhibits proper typing discipline.The new interface provides excellent type safety for the Unthread API payload, with the optional priority field correctly typed to match the allowed values (3, 5, 7, 9). This ensures compile-time validation of the payload structure and prevents invalid priority values from reaching the API.
222-223: Environment variable assertions now operate under validated conditions, sir.The non-null assertions for
UNTHREAD_API_KEYandUNTHREAD_SLACK_CHANNEL_IDalign perfectly with the centralized validation pattern established throughout the codebase.
310-326: Priority configuration implementation demonstrates excellent conditional logic, sir.The implementation correctly retrieves the default priority from the centralized configuration and conditionally includes it in the payload only when defined. This approach prevents sending undefined or invalid priority values to the Unthread API while maintaining backward compatibility for installations without priority configuration.
348-349: Logging enhancement provides valuable operational intelligence, sir.The inclusion of priority information in the ticket creation log (with a sensible fallback of 'not set') provides operators with clear visibility into the priority assignment behavior, facilitating debugging and operational monitoring.
src/config/env.ts (4)
31-32: Sir, excellent choice implementing structured logging.The LogEngine integration represents a significant upgrade from primitive console logging methods. This will provide superior observability and debugging capabilities across your application infrastructure.
58-67: Structured error reporting now operational, sir.The enhanced error logging with detailed context and user-friendly guidance transforms what was once a crude validation process into an elegant diagnostic system. The structured approach with
missingVariablesandtotalMissingprovides actionable intelligence for troubleshooting.
70-71: System status reporting elevated to professional standards.The success logging with environment mode indication provides clear operational visibility - precisely what any well-engineered system requires.
95-115: Priority validation system: sophisticated and bulletproof.The
getDefaultTicketPriorityfunction demonstrates exceptional engineering:
- Graceful handling of undefined environment variables
- Robust validation against Unthread API constraints
- Appropriate warning system for invalid configurations
- Precise TypeScript typing with union types
The implementation elegantly balances flexibility with safety, sir.
Docstrings generation was requested by @warengonzaga. * #33 (comment) The following files were modified: * `src/config/env.ts` * `src/services/unthread.ts`
|
Note Generated docstrings for this pull request at #34 |
π Add docstrings to `dev`
Summary by CodeRabbit
New Features
Chores