From 5131603de12c32a88f476a9ee3261983237c8901 Mon Sep 17 00:00:00 2001 From: Murilo Machado Date: Thu, 6 Jul 2023 15:38:10 +0100 Subject: [PATCH] Change Bot Name to follow agreed pattern --- .github/actions/main-action/action.yml | 5 ++++- .github/workflows/custom_helpline.yml | 1 + functions/captureChannelWithBot.protected.ts | 18 +++++++++++------- tests/captureChannelWithBot.test.ts | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/actions/main-action/action.yml b/.github/actions/main-action/action.yml index 4e3e533f..b5721ea7 100644 --- a/.github/actions/main-action/action.yml +++ b/.github/actions/main-action/action.yml @@ -73,6 +73,9 @@ inputs: environment-code: description: 'The short upper case code used to identify the environment internally, e.g. STG, PROD, DEV' required: true + environment: + description: The environment to deploy to, e.g. staging, production, development (Yes, this is a duplicate of the above, but it's needed for the workflow to run... for now) + required: true send-slack-message: description: 'Specifies if should send a Slack message at the end of successful run. Defaults to true' required: false @@ -107,7 +110,7 @@ runs: run: | cat <> .env HELPLINE_CODE=${{ inputs.helpline-code }} - ENVIRONMENT_CODE=${{ inputs.environment-code }} + ENVIRONMENT=${{ inputs.environment }} TWILIO_WORKSPACE_SID=${{ inputs.workspace-sid }} TWILIO_CHAT_TRANSFER_WORKFLOW_SID=${{ inputs.transfer-workflow-sid }} SYNC_SERVICE_API_KEY=${{ inputs.sync-service-api-key }} diff --git a/.github/workflows/custom_helpline.yml b/.github/workflows/custom_helpline.yml index 91991a61..1809b063 100644 --- a/.github/workflows/custom_helpline.yml +++ b/.github/workflows/custom_helpline.yml @@ -193,6 +193,7 @@ jobs: s3-bucket: $S3_BUCKET helpline-code: ${{inputs.helpline_code}} environment-code: ${{inputs.environment_code}} + environment: ${{inputs.environment}} # Set 'false' if the target environment is production OR the force_enable_operating_hours override option is checked - otherwise 'true' disable-operating-hours: ${{ (inputs.force_enable_operating_hours || inputs.environment_code == 'PROD') && 'false' || 'true' }} send-slack-message: ${{ inputs.send-slack-message }} diff --git a/functions/captureChannelWithBot.protected.ts b/functions/captureChannelWithBot.protected.ts index 503a0822..607b08cb 100644 --- a/functions/captureChannelWithBot.protected.ts +++ b/functions/captureChannelWithBot.protected.ts @@ -26,11 +26,11 @@ import { error500, success, } from '@tech-matters/serverless-helpers'; -import { LexClient, BotType } from './helpers/lexClient.private'; +import { LexClient } from './helpers/lexClient.private'; type EnvVars = { HELPLINE_CODE: string; - ENVIRONMENT_CODE: string; + ENVIRONMENT: string; CHAT_SERVICE_SID: string; ASELO_APP_ACCESS_KEY: string; ASELO_APP_SECRET_KEY: string; @@ -44,8 +44,8 @@ export type Body = { message: string; // (in Studio Flow, trigger.message.Body) The triggering message fromServiceUser: string; // (in Studio Flow, trigger.message.From) The service user unique name studioFlowSid: string; // (in Studio Flow, flow.flow_sid) The Studio Flow sid. Needed to trigger an API type execution once the channel is released. - language: string; - type: BotType; + language: string; // (in Studio Flow, {{trigger.message.ChannelAttributes.pre_engagement_data.language | default: 'en-US'}} ) + type: 'pre_survey' | 'post_survey'; // (hardcoded in Studio Flow) }; export const handler = async ( @@ -80,6 +80,10 @@ export const handler = async ( resolve(error400('type')); return; } + if (!language) { + resolve(error400('language')); + return; + } const channel = await context .getTwilioClient() @@ -104,9 +108,9 @@ export const handler = async ( }), ); - const { ENVIRONMENT_CODE, HELPLINE_CODE } = context; - const languageSuffix = (language || 'en-US').replace('-', '_'); - const botName = `${ENVIRONMENT_CODE}_${HELPLINE_CODE}_${type}_${languageSuffix}`; + const { ENVIRONMENT, HELPLINE_CODE } = context; + const languageSanitized = language.replace('-', '_'); // Lex doesn't accept '-' + const botName = `${ENVIRONMENT}_${HELPLINE_CODE.toLowerCase()}_${languageSanitized}_${type}`; const chatbotCallbackWebhook = await channel.webhooks().create({ type: 'webhook', diff --git a/tests/captureChannelWithBot.test.ts b/tests/captureChannelWithBot.test.ts index 5968be43..15610376 100644 --- a/tests/captureChannelWithBot.test.ts +++ b/tests/captureChannelWithBot.test.ts @@ -94,7 +94,7 @@ const mockContext = { TWILIO_WORKSPACE_SID: 'WE23xxx0orre', SURVEY_WORKFLOW_SID: 'AZexxx903esd', HELPLINE_CODE: 'AS', - ENVIRONMENT_CODE: 'DEV', + ENVIRONMENT: 'development', }; const mockEvent: Body = {