Skip to content

CHI-3295: use new prepopulate config in Twilio Lambda #2970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: CHI-3295-formdef_package_move
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
83f36da
Tests passing for populateMappings
stephenhand May 14, 2025
0e9dc8b
Add more tests and fix issues highlighted by tests
stephenhand May 14, 2025
511dfce
Flip dependencies so hrm-form-definitions depends on hrm-types
stephenhand May 14, 2025
f54a6ee
Fix package pathing in lambda dockerfile
stephenhand May 14, 2025
91bee68
Try changing nrm-form-definitions -> hrm-types dependency to a file d…
stephenhand May 14, 2025
0b3f52c
Break dependency between hrm-types and hrm-form-definitions
stephenhand May 14, 2025
8182028
Fix build
stephenhand May 14, 2025
05283cf
Fix build
stephenhand May 14, 2025
8bd0596
Fix a bunch of deps
stephenhand May 14, 2025
8cd8aea
Move hrm-form-definitions tests to lambda CI
stephenhand May 15, 2025
be1c87a
Linter
stephenhand May 15, 2025
f5acf27
Fix lambda service tests
stephenhand May 15, 2025
3b3fcf3
Fix lambda service tests
stephenhand May 15, 2025
d9994d0
Fix lambda service tests
stephenhand May 15, 2025
f3edffc
Upgrade @babel/runtime
stephenhand May 15, 2025
e31890c
Upgrade package-lock.json
stephenhand May 15, 2025
5f979a1
Build lambdas for plugin tests
stephenhand May 15, 2025
ef0f223
Build lambdas for plugin tests
stephenhand May 15, 2025
2064750
Install lambda packages outside workspace for unit tests
stephenhand May 15, 2025
a2d5a5a
Try copying packages to local node_modules :-/
stephenhand May 15, 2025
56b5e50
Try copying packages to local node_modules :-/
stephenhand May 15, 2025
05bc0c6
Try copying packages to local node_modules :-/
stephenhand May 15, 2025
9b804ff
Shotgun fixing
stephenhand May 15, 2025
266d335
Shotgun fixing
stephenhand May 15, 2025
cbdbd31
Shotgun fixing
stephenhand May 15, 2025
85ba443
Remove DefinitionVersionId enum
stephenhand May 15, 2025
c827677
Try reordering ci calls installing flex plugin deps
stephenhand May 16, 2025
77b0141
Try reordering ci calls installing flex plugin deps
stephenhand May 16, 2025
81df3fa
Remove reference to old DefinitionVersion enum
stephenhand May 16, 2025
dc68730
Remove unused export
stephenhand May 16, 2025
81df0f6
Fix form def deploy path
stephenhand May 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/actions/install-flex-plugin/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ runs:
- name: Install the Twilio CLI and plugins
run: npm install -g twilio-cli && twilio plugins:install @twilio-labs/[email protected]
shell: bash
- name: Install hrm-form-definitions Packages
run: npm ci
working-directory: ${{ inputs.path }}/lambdas/packages/hrm-form-definitions
shell: bash
- name: Install plugin-hrm-form Packages
run: npm ci
working-directory: ${{ inputs.path }}/plugin-hrm-form
shell: bash
- name: Install hrm-types packages
run: npm ci
working-directory: ${{ inputs.path }}/lambdas
shell: bash
4 changes: 2 additions & 2 deletions .github/scripts/setupDeployFormDefinitionsEnv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ fi
helpline="${helpline,,}"

path="form-definitions/${helpline}"
helpline_dir="./hrm-form-definitions/${path}"
helpline_dir="./lambdas/packages/hrm-form-definitions/${path}"

if [ ! -d "$helpline_dir" ]; then
echo "${helpline} is not a valid helpline. It must be one of: $(ls ./hrm-form-definitions/form-definitions)"
echo "${helpline} is not a valid helpline. It must be one of: $(ls ./lambdas/packages/hrm-form-definitions/form-definitions)"
fi

echo "environment=${environment}" >> $GITHUB_ENV
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/flex-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ jobs:
node-version: '20.x'
- name: Install Flex Plugin
uses: ./.github/actions/install-flex-plugin
- name: Run hrm-form-definitions Tests
run: npm run test
working-directory: ./lambdas/packages/hrm-form-definitions
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/twilio-lambda-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ jobs:
run: |
npm ci
working-directory: ./lambdas
- name: Build Lambda packages
run: |
npm run build
working-directory: ./lambdas

- name: Run Unit Tests
run: |
Expand Down
4 changes: 1 addition & 3 deletions e2e-tests/ui-tests/aselo-service-mocks/hrm/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import flexContext from '../../flex-in-a-box/global-context';
import { addSeconds, subHours } from 'date-fns';
// eslint-disable-next-line import/no-extraneous-dependencies
import { DefinitionVersionId } from 'hrm-form-definitions';
// eslint-disable-next-line import/no-extraneous-dependencies
import { Page } from '@playwright/test';
import context from '../global-context';
import * as path from 'path';
Expand All @@ -39,7 +37,7 @@ const generateMockCases = (toGenerate: number): any[] => {
'case category 2': ['subcategory3'],
},
info: {
definitionVersion: DefinitionVersionId.demoV1,
definitionVersion: 'demo-v1',
},
createdAt: time.toISOString(),
updatedAt: time.toISOString(),
Expand Down
6 changes: 3 additions & 3 deletions lambdas/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see https://www.gnu.org/licenses/.

FROM public.ecr.aws/lambda/nodejs:22 as build

Check warning on line 15 in lambdas/Dockerfile

View workflow job for this annotation

GitHub Actions / twilio-lambda-ci / Build Lambda Image (account-scoped)

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

ARG lambda_dir
ENV lambda_dir ${lambda_dir}

Check warning on line 18 in lambdas/Dockerfile

View workflow job for this annotation

GitHub Actions / twilio-lambda-ci / Build Lambda Image (account-scoped)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ARG lambda_name
ENV lambda_name ${lambda_name}

Check warning on line 20 in lambdas/Dockerfile

View workflow job for this annotation

GitHub Actions / twilio-lambda-ci / Build Lambda Image (account-scoped)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

# This is a bit complicated by the need for access to the packages.
# We must have the full repo context for our docker build so we can
# copy the hrm-lib package and labmdas folders so that the file: based
# dependency in package.json can be resolved
COPY ${lambda_dir}/${lambda_name} /tmp/build/${lambda_dir}/${lambda_name}
COPY ${lambda_dir}/../packages /tmp/build/${lambda_dir}/../packages
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are a few github lint notes up in this file, maybe address them?

COPY ${lambda_dir}/../packages /tmp/build/packages
COPY package.json package-lock.json tsconfig.json tsconfig.base.json ${lambda_dir}/${lambda_name}/tsconfig.build.json /tmp/build/

RUN dnf install -y rsync \
&& cd /tmp/build \
&& npm ci -w ${lambda_dir}/${lambda_name} -w ${lambda_dir}/../packages/* --verbose \
&& npm ci -w ${lambda_dir}/${lambda_name} -w packages/* --verbose \
&& npx tsc -b tsconfig.build.json --verbose \
&& cp -r ${lambda_dir}/${lambda_name}/dist/. /var/task/ \
&& mkdir -p /var/task/${lambda_dir} \
&& cp -r ${lambda_dir}/../packages /var/task/${lambda_dir}/../packages/ \
&& cp -r packages /var/task/ \
&& cp -r node_modules /var/task/

# Ignore errors if node_modules is not present
Expand Down
2 changes: 2 additions & 0 deletions lambdas/account-scoped/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
},
"dependencies": {
"@aws-sdk/client-ssm": "^3.716.0",
"@tech-matters/hrm-form-definitions": "^1.0.0",
"@tech-matters/hrm-types": "^1.0.0",
"@twilio-labs/serverless-runtime-types": "^4.0.1",
"date-fns": "^4.1.0",
"lodash": "^4.17.21",
Expand Down
40 changes: 40 additions & 0 deletions lambdas/account-scoped/src/hrm/availableContactFormSelector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (C) 2021-2023 Technology Matters
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/

import { HrmContactRawJson } from '@tech-matters/hrm-types';
import { DefinitionVersion } from '@tech-matters/hrm-form-definitions';

export type ContactFormDefinitionName = keyof Pick<
DefinitionVersion['tabbedForms'],
'ChildInformationTab' | 'CallerInformationTab' | 'CaseInformationTab'
>;

export type ContactFormName = keyof Omit<
HrmContactRawJson,
'callType' | 'definitionVersion' | 'categories' | 'contactlessTask'
>;

export type AvailableContactFormSelector = (
parameter?: any,
) => (
source: keyof DefinitionVersion['prepopulateMappings'],
preEngagementSelections: any,
surveyAnswers: any,
) => ContactFormDefinitionName[];

export const staticAvailableContactTabSelector: AvailableContactFormSelector =
availableTabs => () =>
availableTabs;
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

/* eslint-disable global-require */
/* eslint-disable import/no-dynamic-require */
import {
HrmContact,
populateHrmContactFormFromTask,
} from './populateHrmContactFormFromTask';
import { populateHrmContactFormFromTaskByKeys } from './populateHrmContactFormFromTaskByKeys';
import { registerTaskRouterEventHandler } from '../taskrouter/taskrouterEventHandler';
import { RESERVATION_ACCEPTED } from '../taskrouter/eventTypes';
import type { EventFields } from '../taskrouter';
Expand All @@ -30,8 +27,10 @@ import {
patchOnInternalHrmEndpoint,
postToInternalHrmEndpoint,
} from './internalHrmRequest';
import { isErr } from '../Result';
import { isErr, isOk } from '../Result';
import { inferHrmAccountId } from './hrmAccountId';
import { HrmContact } from '@tech-matters/hrm-types';
import { populateHrmContactFormFromTaskByMappings } from './populateHrmContactFormFromTaskByMappings';

// Temporarily copied to this repo, will share the flex types when we move them into the same repo

Expand All @@ -45,7 +44,7 @@ const BLANK_CONTACT: HrmContact = {
childInformation: {},
callerInformation: {},
caseInformation: {},
callType: '',
callType: '' as any,
contactlessTask: {
channel: '' as any,
date: '',
Expand Down Expand Up @@ -112,6 +111,7 @@ export const handleEvent = async (
helpline_code: helplineCode,
feature_flags: {
enable_backend_hrm_contact_creation: enableBackendHrmContactCreation,
use_prepopulate_mappings: usePrepopulateMappings,
},
} = serviceConfig.attributes;

Expand Down Expand Up @@ -211,16 +211,22 @@ export const handleEvent = async (
timeOfContact: new Date().toISOString(),
};
console.debug('Creating HRM contact with timeOfContact:', newContact.timeOfContact);
const populatedContact = await populateHrmContactFormFromTask(
const prepopulate = usePrepopulateMappings
? populateHrmContactFormFromTaskByMappings
: populateHrmContactFormFromTaskByKeys;
const populatedContactResult = await prepopulate(
taskAttributes,
newContact,
formDefinitionsVersionUrl,
);
if (isErr(populatedContactResult)) {
console.warn(`Populating contact ${newContact.id} failed, creating blank contact`);
}
const responseResult = await postToInternalHrmEndpoint<HrmContact, HrmContact>(
hrmAccountId,
hrmApiVersion,
'contacts',
populatedContact,
isOk(populatedContactResult) ? populatedContactResult.data : newContact,
);
if (isErr(responseResult)) {
console.error(
Expand Down
Loading
Loading