Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
603cb5d
Added channel caputre and bot webhook functions
gpaoloni Mar 14, 2023
a53d7b2
Added option to first set of messages
gpaoloni Mar 14, 2023
704e374
Use new attributes
gpaoloni Mar 14, 2023
90bbd09
Fixed silly error =)
gpaoloni Mar 14, 2023
64dca28
Approach change: trigger flow via API after channel is released
gpaoloni Mar 15, 2023
7999801
Fixed studio flow sid
gpaoloni Mar 15, 2023
05f4495
Added service user to the channel
gpaoloni Mar 15, 2023
79391ab
Carry around from unique id
gpaoloni Mar 15, 2023
45f0766
Use fromServiceUser to compare unique sids (breaks for webchat otherw…
gpaoloni Mar 15, 2023
dc2a379
Mimic default twilio executions from address (channelSid)
gpaoloni Mar 15, 2023
e22172f
Added logic to cleanup the webhook
gpaoloni Mar 15, 2023
7b039d9
Create control task for 'pre-survey' and clean up stale chat channel …
mythilytm Jun 2, 2023
30be307
Merge remote-tracking branch 'origin/master' into gian_CHI-175-lex
gpaoloni Jun 7, 2023
cf37ff6
Factored out Lex client, cleanup
gpaoloni Jun 7, 2023
b943d7b
next action factored out, prep work to support more bots
gpaoloni Jun 7, 2023
a9bc7fb
ch: unit test for captureChannelWithBot and chatbotCallback
acedeywin Jun 13, 2023
7d04615
ch: merge master
acedeywin Jun 13, 2023
d16a392
log all the channel attributes
acedeywin Jun 15, 2023
8ce3903
ch: add license to test files
acedeywin Jun 15, 2023
b157f97
ch: solve conflict and merge master
acedeywin Jun 15, 2023
b3f7385
ch: refactor and add new test
acedeywin Jun 19, 2023
5ba4aa2
ch: fix lint
acedeywin Jun 19, 2023
4117c36
ch: merger from master
acedeywin Jun 20, 2023
d40f4f3
Merge remote-tracking branch 'origin/master' into gian_CHI-175-lex
gpaoloni Jun 21, 2023
f64413d
Use export on functions rather than default
gpaoloni Jun 21, 2023
e80004e
ch: merge update from gian_CHI-175-lex
acedeywin Jun 22, 2023
cf69345
bg: refactor test to match update
acedeywin Jun 22, 2023
8c9f9f7
fx: remove unwanted test mock and add TWILIO_WORKSPACE_SID
acedeywin Jun 22, 2023
0208d3b
fx: remove if block in the chatbotCallback test
acedeywin Jun 26, 2023
56841df
Merge pull request #473 from techmatters/CHI-1967_productionize_lex_p…
acedeywin Jun 26, 2023
8f0a2e1
Merge remote-tracking branch 'origin/master' into gian_CHI-175-lex
gpaoloni Jul 5, 2023
82c539c
Lex: Support to multiple languages (#480)
murilovmachado Jul 5, 2023
0fc156d
Change Bot Name to follow agreed pattern (#488)
murilovmachado Jul 10, 2023
90f115e
Adjust postSurveyInit and postSurveyListener to make them work with t…
gpaoloni Jul 25, 2023
2478e8b
Merge remote-tracking branch 'origin/master' into gian_CHI-175-lex
gpaoloni Jul 25, 2023
82e542f
Moved lexClient into /channelCapture
gpaoloni Jul 26, 2023
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
19 changes: 15 additions & 4 deletions .github/actions/main-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ inputs:
s3-bucket:
description: 'S3 bucket name where Aselo documents are stored'
required: true
helpline-name:
description: 'The identifier in the format "<short helpline>-<short env>" used for this helpline'
helpline-code:
description: 'The short (usually 2 character) upper case code used to identify the helpline internally, e.g. ZA, IN, BR.'
required: true
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'
Expand All @@ -81,6 +87,9 @@ inputs:
runs:
using: 'composite'
steps:
- name: Set helpline-name
run: echo "helpline-name=${{ inputs.helpline-code }}_${{ inputs.environment-code }}" >> $GITHUB_ENV
shell: bash
# Set any env vars needed from Parameter Store here
# Slack env
- name: Set GITHUB_ACTIONS_SLACK_BOT_TOKEN
Expand All @@ -100,6 +109,8 @@ runs:
- name: Fill .env
run: |
cat <<EOT >> .env
HELPLINE_CODE=${{ inputs.helpline-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 }}
Expand Down Expand Up @@ -131,7 +142,7 @@ runs:
- name: Execute custom action (if any)
uses: ./.github/actions/custom-actions
with:
helpline-name: ${{ inputs.helpline-name }}
helpline-name: ${{ env.helpline-name }}
account-sid: ${{ inputs.account-sid }}
# Install dependencies for the twilio functions
- name: Install dependencies for the twilio functions
Expand Down Expand Up @@ -170,6 +181,6 @@ runs:
if: ${{ inputs.send-slack-message != 'false' }}
with:
channel-id: ${{ env.ASELO_DEPLOYS_CHANNEL_ID }}
slack-message: "`[Serverless]` Deployment to `${{ inputs.helpline-name }}` from ${{ github.ref_type }} `${{ github.ref_name }}` requested by `${{ github.triggering_actor }}` completed using workflow '${{ github.workflow }}' with SHA ${{ github.sha }} :rocket:."
slack-message: "`[Serverless]` Deployment to `${{ env.helpline-name }}` from ${{ github.ref_type }} `${{ github.ref_name }}` requested by `${{ github.triggering_actor }}` completed using workflow '${{ github.workflow }}' with SHA ${{ github.sha }} :rocket:."
env:
SLACK_BOT_TOKEN: ${{ env.GITHUB_ACTIONS_SLACK_BOT_TOKEN }}
4 changes: 3 additions & 1 deletion .github/workflows/custom_helpline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ jobs:
aselo-app-secret-key: $ASELO_APP_SECRET_KEY
aws-region: $HELPLINE_AWS_REGION
s3-bucket: $S3_BUCKET
helpline-name: ${{inputs.helpline_code}}_${{inputs.environment_code}}
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 }}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ For help on twilio-run commands run:
| `S3_ENDPOINT` | _local transcripts only_ http://localhost:4566 |
| `ASELO_APP_ACCESS_KEY` | AWS_ACCESS_KEY_ID with access to s3 bucket (can be any string for localstack) |
| `ASELO_APP_SECRET_KEY` | AWS_SECRET_ACCESS_KEY for ASELO_APP_ACCESS_KEY (can be any string for localstack |
| `HELPLINE_CODE` | The short (usually 2 character) upper case code used to identify the helpline internally, e.g. ZA, IN, BR. |
| `ENVIRONMENT_CODE` | The short upper case code used to identify the environment internally, e.g. STG, PROD, DEV |

## Deployment

Expand Down
99 changes: 99 additions & 0 deletions functions/channelCapture/captureChannelWithBot.protected.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/* eslint-disable import/no-dynamic-require */
/**
* 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/.
*/

/* eslint-disable global-require */
/* eslint-disable import/no-dynamic-require */
import '@twilio-labs/serverless-runtime-types';
import {
responseWithCors,
bindResolve,
error400,
error500,
success,
} from '@tech-matters/serverless-helpers';
import type { Context, ServerlessCallback } from '@twilio-labs/serverless-runtime-types/types';
import type {
ChannelCaptureHandlers,
HandleChannelCaptureParams,
} from './channelCaptureHandlers.private';
import type { AWSCredentials } from './lexClient.private';

type EnvVars = {
HELPLINE_CODE: string;
ENVIRONMENT: string;
CHAT_SERVICE_SID: string;
TWILIO_WORKSPACE_SID: string;
SURVEY_WORKFLOW_SID: string;
HRM_STATIC_KEY: string;
} & AWSCredentials;

export type Body = Partial<HandleChannelCaptureParams>;

export const handler = async (
context: Context<EnvVars>,
event: Body,
callback: ServerlessCallback,
) => {
console.log('===== captureChannelWithBot handler =====');
const response = responseWithCors();
const resolve = bindResolve(callback)(response);

try {
const {
channelSid,
message,
triggerType,
releaseType,
studioFlowSid,
language,
botSuffix,
additionControlTaskAttributes,
controlTaskTTL,
memoryAttribute,
releaseFlag,
} = event;

const handlerPath = Runtime.getFunctions()['channelCapture/channelCaptureHandlers'].path;
const channelCaptureHandlers = require(handlerPath) as ChannelCaptureHandlers;

const result = await channelCaptureHandlers.handleChannelCapture(context, {
channelSid,
message,
language,
botSuffix,
triggerType,
releaseType,
studioFlowSid,
memoryAttribute,
releaseFlag,
additionControlTaskAttributes,
controlTaskTTL,
});

if (result.status === 'failure' && result.validationResult.status === 'invalid') {
resolve(error400(result.validationResult.error));
return;
}

resolve(success('Channel captured by bot =)'));
} catch (err) {
if (err instanceof Error) resolve(error500(err));
else resolve(error500(new Error(String(err))));
}
};

export type CaptureChannelWithBot = { handler: typeof handler };
Loading