Skip to content

Comments

CHI-3737: Migrate adjustCapacity, janitor, and transfers task router listeners to lambdas/account-scoped#3951

Open
Copilot wants to merge 7 commits intomasterfrom
copilot/migrate-task-router-handlers
Open

CHI-3737: Migrate adjustCapacity, janitor, and transfers task router listeners to lambdas/account-scoped#3951
Copilot wants to merge 7 commits intomasterfrom
copilot/migrate-task-router-handlers

Conversation

Copy link
Contributor

Copilot AI commented Feb 23, 2026

Migrates three remaining task router listeners from the serverless repo into the lambdas/account-scoped lambda, each gated by a use_twilio_lambda_* feature flag that short-circuits the handler entirely when not set.

Description

  • conversation/adjustCapacityTaskRouterListener.tsRESERVATION_ACCEPTED / RESERVATION_REJECTED; reuses existing adjustChatCapacity module; also gates internally on enable_manual_pulling
  • conversation/janitorTaskRouterListener.tsTASK_CANCELED, TASK_WRAPUP, TASK_COMPLETED, TASK_DELETED, TASK_SYSTEM_DELETED; handles bot-capture cleanup, custom-channel cleanup, and conversation orchestration deactivation (respecting enable_post_survey); uses existing chatChannelJanitor and hasTaskControl
  • transfer/transfersTaskRouterListener.tsRESERVATION_ACCEPTED/REJECTED/TIMEOUT/WRAPUP, TASK_CANCELED, TASK_QUEUE_ENTERED; full chat + voice transfer state machine; implements transitionAgentParticipants locally against the Flex Interaction API
  • customChannels/aseloCustomChannels.ts — new file containing AseloCustomChannel enum and isAseloCustomChannel() helper (used by janitor to detect custom channel types); re-exported from customChannelToFlex.ts for backward compatibility
  • taskrouter/index.ts — imported the three new listeners
  • adjustChatCapacity.ts — removed the now-superseded adjustChatCapacityHandler HTTP handler function and its associated unused imports
  • router.ts — removed the conversation/adjustChatCapacity route that was served by the removed handler

Feature flags:

Listener Flag
adjustCapacity use_twilio_lambda_adjust_capacity
janitor use_twilio_lambda_janitor
transfers use_twilio_lambda_transfers

All log statements use severity-appropriate methods (console.info, console.debug, console.error) and include accountSid and taskSid as context to aid debugging.

Unit tests added for all 3 listeners (mocking their dependencies) as well as the underlying adjustChatCapacity and chatChannelJanitor modules.

Checklist

  • Corresponding issue has been opened
  • New tests added
  • Feature flags added
  • Strings are localized
  • Tested for chat contacts
  • Tested for call contacts

Other Related Issues

None

Verification steps

  1. Enable each use_twilio_lambda_* flag in Flex service configuration.
  2. Trigger the relevant TaskRouter events (accept/reject a chat reservation, complete/cancel a chat task, perform a cold or warm transfer) and confirm behaviour matches the serverless implementation.
  3. Verify that with the flag disabled, no handler logic executes (logs should show the debug-level "skipped" message).
  4. Confirm the conversation/adjustChatCapacity HTTP endpoint is no longer available (requests should return a 404/unmatched route response).

AFTER YOU MERGE

  1. Cut a release tag using the Github workflow. Wait for it to complete and notify in the #aselo-deploys Slack channel.
  2. Comment on the ticket with the release tag version AND any additional instructions required to configure an environment to test the changes.
  3. Only then move the ticket into the QA column in JIRA

You are responsible for ensuring the above steps are completed. If you move a ticket into QA without advising what version to test, the QA team will assume the latest tag has the changes. If it does not, the following confusion is on you! :-P

Original prompt

This section details on the original issue you should resolve

<issue_title>Migrate remaining</issue_title>
<issue_description>## Description

Migrate the following 3 remaining task router handlers into the lambdas/account-scoped lambda:

https://github.com/techmatters/serverless/blob/master/functions/taskRouterListeners/adjustCapacityListener.ts - put this in the conversation directory
https://github.com/techmatters/serverless/blob/master/functions/taskRouterListeners/janitorListener.ts - put this in the transfer directory
https://github.com/techmatters/serverless/blob/master/functions/taskRouterListeners/transferListener.ts - put this in the transfer directory

Add feature flags for each listener starting with use_twilio_lambda_ - if the flag is not set, none of the code in the relevant handler executes

Additional context

Follow the same patterns as for other task router handlers that have been migrated - for example, lambdas/account-scoped/task/addCustomerExternalIdTaskRouterListener.ts - ensure the handler files are of the TaskRouterEventHandler type, ensure you import the handler in taskrouter/index.ts

For https://github.com/techmatters/serverless/blob/master/functions/taskRouterListeners/adjustCapacityListener.ts - be sure to reuse the code in the existing adjustChatCapacity.ts module</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: stephenhand <1694716+stephenhand@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate remaining task router handlers to account-scoped lambda Migrate adjustCapacity, janitor, and transfers task router listeners to lambdas/account-scoped Feb 23, 2026
Copilot AI requested a review from stephenhand February 23, 2026 16:14
Copy link
Collaborator

@stephenhand stephenhand left a comment

Choose a reason for hiding this comment

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

Convert console.log statements to ones that use the method appropriate to their severity level (console.warn, console.error etc.). Enhance these log statements with contextual data to aid debugging, making sure to include the accountSid and the relevant task SID as a minimum. Include any additional log statements that could aid debugging

Refer to https://github.com/techmatters/aselo-coding-standards/blob/sjh/log-levels/logging-levels.md for guidance on selecting appropriate logging levels

Add unit tests for the 3 migrated listeners. Unit test the listener logic separately from the modules they depend on (i.e. adjustChannelCapacity.ts, chatChannelJanitor.ts) - mocking them as required, but if those dependencies lack test coverage, add tests for those too

Telegram = 'telegram',
}

export const isAseloCustomChannel = (channelType?: string): boolean =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this isn't related to converting custom channel messages to flex conversation messages, it should be moved to its own file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in fddfe87. Moved AseloCustomChannel and isAseloCustomChannel to a new customChannels/aseloCustomChannels.ts file. customChannelToFlex.ts re-exports them for backward compatibility.

…add unit tests

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

Copilot AI commented Feb 24, 2026

Convert console.log statements to ones that use the method appropriate to their severity level (console.warn, console.error etc.). Enhance these log statements with contextual data to aid debugging, m...

Done in fddfe87:

  • All console.log statements replaced with appropriate severity levels (console.info for lifecycle events, console.debug for skip/trace messages, console.error for failures), with accountSid and taskSid included in each message.

  • Unit tests added for all 3 listeners with mocked dependencies:

    • tests/unit/conversation/adjustCapacityTaskRouterListener.test.ts (5 tests covering flag disabled, non-chat channel, enable_manual_pulling disabled, and both flags enabled)
    • tests/unit/transfer/janitorTaskRouterListener.test.ts (10 tests covering flag disabled, channel type filtering, bot capture cleanup, custom channel cleanup, conversation orchestration deactivation, and error re-throw)
    • tests/unit/transfer/transfersTaskRouterListener.test.ts (10 tests covering flag disabled, chat worker/queue transfers, voice warm/cold transfers, and error re-throw)

    Each listener's dependencies (adjustChatCapacity, chatChannelJanitor, hasTaskControl, etc.) are mocked with jest.mock.

Copy link
Collaborator

@stephenhand stephenhand left a comment

Choose a reason for hiding this comment

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

Remove the adjustChatCapacityHandler function and associated route from adjustChatCapacity.ts

Add unit test coverage for the adjustChatCapacity and chatChannelJanitor methods

…apacity and chatChannelJanitor

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

Copilot AI commented Feb 24, 2026

Remove the adjustChatCapacityHandler function and associated route from adjustChatCapacity.ts

Add unit test coverage for the adjustChatCapacity and chatChannelJanitor methods

Done in a92f529:

  • Removed adjustChatCapacityHandler and its unused imports from adjustChatCapacity.ts, and removed the conversation/adjustChatCapacity route and import from router.ts
  • Added tests/unit/conversation/adjustChatCapacity.test.ts (7 tests covering setTo1 and increaseUntilCapacityAvailable paths including edge cases)
  • Added tests/unit/conversation/chatChannelJanitor.test.ts (8 tests covering the conversation and channel deactivation paths, proxy session handling, and error resilience)

Copilot AI requested a review from stephenhand February 24, 2026 14:59
@stephenhand stephenhand requested a review from gpaoloni February 24, 2026 18:20
@stephenhand stephenhand marked this pull request as ready for review February 25, 2026 10:49
@stephenhand stephenhand changed the title Migrate adjustCapacity, janitor, and transfers task router listeners to lambdas/account-scoped CHI-3737: Migrate adjustCapacity, janitor, and transfers task router listeners to lambdas/account-scoped Feb 25, 2026
Copy link
Collaborator

@stephenhand stephenhand left a comment

Choose a reason for hiding this comment

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

move the janitorTaskRouterListener from the transfer directory to the conversation directory. Do the same for the associated unit tests

stephenhand and others added 2 commits February 25, 2026 11:15
…n directory

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

Copilot AI commented Feb 25, 2026

move the janitorTaskRouterListener from the transfer directory to the conversation directory. Do the same for the associated unit tests

Done in 63bb692. Moved janitorTaskRouterListener.ts from transfer/ to conversation/ (updating relative imports), moved the test file to tests/unit/conversation/, and updated taskrouter/index.ts to import from the new location. The old transfer/janitorTaskRouterListener.ts now re-exports from the new location as a stub for backward compatibility.

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.

Migrate remaining task router handlers from serverless

2 participants