Skip to content

Commit

Permalink
Add env var injection to AS_DEV
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhand committed Dec 20, 2024
1 parent b62d9c0 commit c61b2f5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,9 @@ 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
28 changes: 23 additions & 5 deletions functions/webhooks/taskrouterCallback.protected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ const LISTENERS_FOLDER = 'taskrouterListeners/';
type EnvVars = {
TWILIO_WORKSPACE_SID: string;
CHAT_SERVICE_SID: string;
DELEGATE_WEBHOOK_URL: string;
ACCOUNT_SID: string;
};

type EventFieldsWithRequest = EventFields & {
request: { headers: Record<string, string | string[]> };
};

/**
Expand All @@ -45,13 +51,13 @@ const getListeners = (): [string, TaskrouterListener][] => {

const runTaskrouterListeners = async (
context: Context<EnvVars>,
event: EventFields,
event: EventFieldsWithRequest,
callback: ServerlessCallback,
) => {
const listeners = getListeners();

await Promise.all(
listeners
await Promise.all([
...listeners
.filter(([, listener]) => listener.shouldHandle(event))
.map(async ([path, listener]) => {
console.debug(
Expand All @@ -66,12 +72,24 @@ const runTaskrouterListeners = async (
`===== Successfully executed listener at ${path} for event: ${event.EventType}, task: ${event.TaskSid} =====`,
);
}),
);
async () => {
if (context.DELEGATE_WEBHOOK_URL) {
return fetch(`${context.DELEGATE_WEBHOOK_URL}/${context.ACCOUNT_SID}${context.PATH}`, {
method: 'POST',
headers: {
'X-Original-Webhook-Url': `https//:${context.DOMAIN_NAME}${context.PATH}`,
...event.request.headers,
},
});
}
return Promise.resolve();
},
]);
};

export const handler = async (
context: Context<EnvVars>,
event: EventFields,
event: EventFieldsWithRequest,
callback: ServerlessCallback,
) => {
const response = responseWithCors();
Expand Down

0 comments on commit c61b2f5

Please sign in to comment.