From 48e09cdaa0371c9dcbf95aa2e2ebd762d5f5266d Mon Sep 17 00:00:00 2001 From: Stephen Hand Date: Thu, 16 Jan 2025 15:00:06 +0000 Subject: [PATCH 1/2] Add feature flag check for delegating taskrouter webhook calls. Get delegated URL fromn service configuration rather than it being separately configured --- .../custom-actions/aselo_development_custom/action.yml | 5 ----- functions/webhooks/taskrouterCallback.protected.ts | 9 +++++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/actions/custom-actions/aselo_development_custom/action.yml b/.github/actions/custom-actions/aselo_development_custom/action.yml index a7c5f80c..08e91f5f 100644 --- a/.github/actions/custom-actions/aselo_development_custom/action.yml +++ b/.github/actions/custom-actions/aselo_development_custom/action.yml @@ -230,9 +230,4 @@ runs: - name: Add MODICA_TEST_SEND_MESSAGE_URL run: echo "MODICA_TEST_SEND_MESSAGE_URL=${{ env.MODICA_TEST_SEND_MESSAGE_URL }}" >> .env - shell: bash - - - - name: Add DELEGATE_WEBHOOK_URL - run: echo "DELEGATE_WEBHOOK_URL=https://hrm-development.tl.techmatters.org/lambda/twilio/account-scoped" >> .env shell: bash \ No newline at end of file diff --git a/functions/webhooks/taskrouterCallback.protected.ts b/functions/webhooks/taskrouterCallback.protected.ts index 15cf4fa2..a8603a81 100644 --- a/functions/webhooks/taskrouterCallback.protected.ts +++ b/functions/webhooks/taskrouterCallback.protected.ts @@ -56,8 +56,13 @@ const runTaskrouterListeners = async ( ) => { const listeners = getListeners(); let delegatePromise: Promise = Promise.resolve(); - if (context.DELEGATE_WEBHOOK_URL) { - const delegateUrl = `${context.DELEGATE_WEBHOOK_URL}/${context.ACCOUNT_SID}${context.PATH}`; + const serviceConfig = await context.getTwilioClient().flexApi.configuration.get().fetch(); + const { + feature_flags: { enable_task_router_event_delegation: enableTaskRouterEventDelegation }, + hrm_base_url: hrmBaseUrl, + } = serviceConfig.attributes; + if (enableTaskRouterEventDelegation) { + const delegateUrl = `${hrmBaseUrl}/${context.ACCOUNT_SID}${context.PATH}`; const forwardedHeaderEntries = Object.entries(request.headers).filter( ([key]) => key.toLowerCase().startsWith('x-') || key.toLowerCase().startsWith('t-'), ); From b67544e30addf90cbe2dc0d1c76208a7eb532922 Mon Sep 17 00:00:00 2001 From: Stephen Hand Date: Fri, 17 Jan 2025 01:04:56 +0000 Subject: [PATCH 2/2] Fix path in delegation --- functions/webhooks/taskrouterCallback.protected.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/webhooks/taskrouterCallback.protected.ts b/functions/webhooks/taskrouterCallback.protected.ts index a8603a81..5e3198b5 100644 --- a/functions/webhooks/taskrouterCallback.protected.ts +++ b/functions/webhooks/taskrouterCallback.protected.ts @@ -62,7 +62,7 @@ const runTaskrouterListeners = async ( hrm_base_url: hrmBaseUrl, } = serviceConfig.attributes; if (enableTaskRouterEventDelegation) { - const delegateUrl = `${hrmBaseUrl}/${context.ACCOUNT_SID}${context.PATH}`; + const delegateUrl = `${hrmBaseUrl}/lambda/twilio/account-scoped/${context.ACCOUNT_SID}${context.PATH}`; const forwardedHeaderEntries = Object.entries(request.headers).filter( ([key]) => key.toLowerCase().startsWith('x-') || key.toLowerCase().startsWith('t-'), );