Skip to content

Add support for configuring default ticket priority via UNTHREAD_DEFAULT_PRIORITY environment variable#31

Merged
warengonzaga merged 9 commits intodevfrom
copilot/fix-30
Jul 3, 2025
Merged

Add support for configuring default ticket priority via UNTHREAD_DEFAULT_PRIORITY environment variable#31
warengonzaga merged 9 commits intodevfrom
copilot/fix-30

Conversation

Copy link
Contributor

Copilot AI commented Jul 2, 2025

This PR adds support for configuring default ticket priority for messages received through the Telegram bot using the UNTHREAD_DEFAULT_PRIORITY environment variable. This enables automatic priority assignment for tickets based on deployment configuration, which is particularly valuable for business-critical channels.

Changes Made

1. Environment Configuration (src/config/env.ts)

  • Added getDefaultTicketPriority() function with validation for Unthread API priority values
  • Validates only allowed values: 3 (low), 5 (medium), 7 (high), 9 (critical)
  • Gracefully handles invalid values with warning messages

2. Ticket Creation (src/services/unthread.ts)

  • Modified createTicketJSON() to conditionally include priority field in API payload
  • Priority is only added when environment variable is set and valid
  • Enhanced logging to include priority information in ticket creation logs

3. Documentation (.env.example)

  • Added UNTHREAD_DEFAULT_PRIORITY with clear usage examples
  • Documented all valid priority values with descriptions

Usage Examples

# High priority for business-critical channels  
UNTHREAD_DEFAULT_PRIORITY=7

# Medium priority for standard support
UNTHREAD_DEFAULT_PRIORITY=5

# Leave unset for Unthread's default behavior (no priority field)
# UNTHREAD_DEFAULT_PRIORITY=

API Payload Changes

Before (current behavior maintained when variable not set):

{
  "type": "slack",
  "title": "[Telegram Ticket] Acme Corp",
  "status": "open",
  "customerId": "cust_123",
  "onBehalfOf": { ... }
}

After (when UNTHREAD_DEFAULT_PRIORITY=7):

{
  "type": "slack", 
  "title": "[Telegram Ticket] Acme Corp",
  "status": "open",
  "customerId": "cust_123",
  "onBehalfOf": { ... },
  "priority": 7
}

Key Features

  • Non-breaking: Fully backward compatible - works without setting the environment variable
  • Validation: Only accepts valid Unthread API priority values (3, 5, 7, 9)
  • Graceful handling: Invalid values are logged and ignored
  • Minimal implementation: Only adds priority field when configured
  • Enhanced observability: Priority information included in logs

This implementation allows different deployments to automatically tag tickets with appropriate priorities without hardcoding preferences, enabling better workflow management across business-critical and standard support channels.

Fixes #30.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
@warengonzaga warengonzaga changed the base branch from main to dev July 2, 2025 16:09
Copilot AI changed the title [WIP] Support configuring default ticket priority via environment variable Add support for configuring default ticket priority via UNTHREAD_DEFAULT_PRIORITY environment variable Jul 2, 2025
Copilot AI requested a review from warengonzaga July 2, 2025 16:10
Copy link
Member

@warengonzaga warengonzaga left a comment

Choose a reason for hiding this comment

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

@copilot let's add a default value here. Let's set it to 5 or medium priority.

Copy link
Contributor Author

Copilot AI commented Jul 2, 2025

@copilot let's add a default value here. Let's set it to 5 or medium priority.

The default value of 5 (medium priority) has been set in the .env.example file as requested. The UNTHREAD_DEFAULT_PRIORITY environment variable is now configured with this default value, providing automatic medium priority assignment for new tickets while maintaining backward compatibility. f5ccd78

Copilot AI requested a review from warengonzaga July 2, 2025 16:19
@warengonzaga
Copy link
Member

@copilot can you bump the version according to your changes?

Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 2, 2025

@copilot can you bump the version according to your changes?

Version bumped to 1.0.0-beta.6 to reflect the new UNTHREAD_DEFAULT_PRIORITY feature addition. b9da554

Copilot AI requested a review from warengonzaga July 2, 2025 16:32
@warengonzaga warengonzaga requested a review from Copilot July 2, 2025 16:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds support for setting a default ticket priority via the UNTHREAD_DEFAULT_PRIORITY environment variable, with validation and optional payload inclusion.

  • Introduces getDefaultTicketPriority() for parsing and validating the env var
  • Updates createTicketJSON to include priority when configured and logs its value
  • Updates version, .env.example, and documentation for the new variable

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/config/env.ts Added getDefaultTicketPriority with validation and warning
src/services/unthread.ts Fetched default priority, conditionally added priority to payload, and enhanced logs
package.json Bumped version to 1.0.0-beta.6
.env.example Documented UNTHREAD_DEFAULT_PRIORITY with allowed values
Comments suppressed due to low confidence (2)

src/config/env.ts:95

  • There are no unit tests for getDefaultTicketPriority. Add tests to cover valid values, invalid strings, and the unset case to prevent regressions.
export function getDefaultTicketPriority(): 3 | 5 | 7 | 9 | undefined {

src/services/unthread.ts:320

  • Add unit tests for createTicketJSON to assert that priority is included when UNTHREAD_DEFAULT_PRIORITY is set and omitted otherwise.
    if (defaultPriority !== undefined) {

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@warengonzaga
Copy link
Member

@copilot suggest a fix here: #31 (comment)

…afety

Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 3, 2025

@copilot suggest a fix here: #31 (comment)

Fixed! Replaced the any type with a proper CreateTicketPayload interface that defines all the required and optional fields for type safety. Also added the missing LogEngine import in env.ts. 5685247

@warengonzaga
Copy link
Member

@copilot can you get the latest code from the dev branch?

Copy link
Contributor Author

Copilot AI commented Jul 3, 2025

@copilot can you get the latest code from the dev branch?

Updated with latest code from dev branch. The merge successfully integrates the LogEngine improvements while preserving all UNTHREAD_DEFAULT_PRIORITY feature functionality. ab77423

@warengonzaga
Copy link
Member

…TicketPayload

Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 3, 2025

@copilot can you please fix this? https://github.com/wgtechlabs/unthread-telegram-bot/actions/runs/16040631781/job/45261390732?pr=31

Fixed the TypeScript compilation error by adding a non-null assertion operator for CHANNEL_ID in the CreateTicketPayload. The validation check ensures the value is defined, so the assertion is safe. 2eb68b8

@warengonzaga warengonzaga marked this pull request as ready for review July 3, 2025 03:44
@warengonzaga
Copy link
Member

@copilot can you ensure that all of the configuration for the bot is required?

TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
UNTHREAD_API_KEY=your_unthread_api_key_here
UNTHREAD_SLACK_CHANNEL_ID=your_unthread_slack_channel_id_here
UNTHREAD_WEBHOOK_SECRET=your_unthread_webhook_secret_here

I can see the UNTHREAD_SLACK_CHANNEL_ID not having checks at the runtime level.

Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 3, 2025

@copilot can you ensure that all of the configuration for the bot is required?

TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here

...

All bot configuration is now required with centralized validation. Added validateEnvironment() call at startup that validates all critical environment variables including UNTHREAD_SLACK_CHANNEL_ID. Removed redundant individual checks from multiple files for cleaner, more maintainable code. The bot will exit gracefully with clear error messages if any required configuration is missing. 365637d

@warengonzaga warengonzaga merged commit f76f1fb into dev Jul 3, 2025
3 checks passed
@warengonzaga warengonzaga deleted the copilot/fix-30 branch July 13, 2025 14:01
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.

Support configuring default ticket priority via environment variable

3 participants