diff --git a/lambdas/integrationTestRunner/src/integrationTests/nz/customChannelChatbot.test.ts b/lambdas/integrationTestRunner/src/integrationTests/nz/customChannelChatbot.test.ts new file mode 100644 index 0000000000..ce6671ceb5 --- /dev/null +++ b/lambdas/integrationTestRunner/src/integrationTests/nz/customChannelChatbot.test.ts @@ -0,0 +1,83 @@ +/** + * Copyright (C) 2021-2025 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 { startWebhookReceiverSession } from '../../webhookReceiver/client'; +import { verifyInstagramMessageExchange } from '../../instagram'; +import { verifyMessageExchange } from '../../verify'; + +const HELPLINE_CODE = 'NZ'; +const TEST_TIMEOUT_MILLISECONDS = 5 * 60 * 1000; + +let webhookReceiverSession: ReturnType; +let verifyExchange: ReturnType; + +beforeEach(async () => { + webhookReceiverSession = startWebhookReceiverSession(HELPLINE_CODE); + verifyExchange = verifyInstagramMessageExchange(webhookReceiverSession, HELPLINE_CODE); + jest.setTimeout(TEST_TIMEOUT_MILLISECONDS); +}); + +afterEach(async () => { + await webhookReceiverSession.end(); +}); + +test('NZ/staging instagram custom channel chatbot integration test', async () => { + await verifyExchange([ + { + sender: 'service-user', + text: `Hello from integration test ${webhookReceiverSession.sessionId}`, + }, + { + sender: 'flex', + text: `Kia ora, you've reached Youthline.`, + }, + { + sender: 'flex', + text: `If you'd like to talk to the Helpline, please respond 'Yes'. To contact the Fundraising and Marketing team, please respond 'No'.`, + }, + { + sender: 'service-user', + text: `Yes`, + }, + { + sender: 'flex', + text: `Thank you, the next message will be from one of our counsellors. Your conversation will be recorded and may be monitored for quality purposes. For more information, here's a link to our privacy statement: https://youthline.co.nz/privacy-statements/"`, + }, + { + sender: 'flex', + text: `You have selected to speak to the Helpline.`, + }, + { + sender: 'flex', + text: `Your conversation is confidential, but if we feel that you or someone else is at serious risk of harm, we may have to link in with other services. We will let you know if that becomes necessary. \nDo you need urgent support? \n1. Yes \n2. No`, + }, + { + sender: 'service-user', + text: `2`, + }, + { + sender: 'flex', + text: `We will connect you with someone soon. Your conversation will be recorded and may be monitored for quality purposes. For more information, here is a link to our privacy statement: https://youthline.co.nz/privacy-statements/`, + }, + { + sender: 'flex', + text: `You're now talking with Youthline.`, + }, + { + sender: 'flex', + text: `Integration test run completed successfully. 🚀`, + }, + ]); +}); diff --git a/twilio-iac/helplines/nz/staging.hcl b/twilio-iac/helplines/nz/staging.hcl index 46941b415d..c188d75098 100644 --- a/twilio-iac/helplines/nz/staging.hcl +++ b/twilio-iac/helplines/nz/staging.hcl @@ -69,7 +69,9 @@ locals { channel_type = "custom" contact_identity = "instagram" templatefile = "/app/twilio-iac/helplines/nz/templates/studio-flows/instagram-lex-priority-v2-lambda-sd.tftpl" - channel_flow_vars = {} + channel_flow_vars = { + widget_from = "Youthline" + } chatbot_unique_names = [] }, whatsapp : { @@ -84,6 +86,7 @@ locals { } } get_profile_flags_for_identifier_base_url = "https://hrm-staging.tl.techmatters.org/lambda/twilio/account-scoped" + enable_integration_tests = true #System Down Configuration system_down_templatefile = "/app/twilio-iac/helplines/templates/studio-flows/system-down.tftpl" enable_system_down = true diff --git a/twilio-iac/helplines/nz/templates/studio-flows/instagram-lex-priority-v2-lambda-sd.tftpl b/twilio-iac/helplines/nz/templates/studio-flows/instagram-lex-priority-v2-lambda-sd.tftpl index ebc70c7667..1c47f3c18a 100644 --- a/twilio-iac/helplines/nz/templates/studio-flows/instagram-lex-priority-v2-lambda-sd.tftpl +++ b/twilio-iac/helplines/nz/templates/studio-flows/instagram-lex-priority-v2-lambda-sd.tftpl @@ -504,7 +504,78 @@ ${ "key": "system_down" } ] + }, + { + "name": "split_check_for_integration", + "type": "split-based-on", + "transitions": [ + { + "next": "is_bot", + "event": "noMatch" + }, + { + "next": "f_end_integration_test", + "event": "match", + "conditions": [ + { + "friendly_name": "{{trigger.conversation.ChannelAttributes.testSessionId}}", + "arguments": [ + "{{trigger.conversation.ChannelAttributes.testSessionId}}" + ], + "type": "is_not_blank", + "value": "Is Not Blank" + } + ] + } + ], + "properties": { + "input": "{{trigger.conversation.ChannelAttributes.testSessionId}}", + "offset": { + "x": 950, + "y": 1010 + } } + }, + { + "name": "f_end_integration_test", + "type": "run-function", + "transitions": [ + { + "event": "success" + }, + { + "event": "fail" + } + ], + "properties": { + "service_sid": "${serverless_service_sid}", + "environment_sid": "${serverless_environment_sid}", + "offset": { + "x": 1200, + "y": 1210 + }, + "function_sid": "${flow_vars.send_message_janitor_function_sid}", + "parameters": [ + { + "value": "{{flow.channel.address}}", + "key": "channelSid" + }, + { + "value": "{{flow.channel.address}}", + "key": "conversationSid" + }, + { + "value": "Integration test run completed successfully. 🚀", + "key": "message" + }, + { + "value": "${channel_flow_vars.widget_from}", + "key": "from" + } + ], + "url": "${serverless_url}/sendMessageAndRunJanitor" + } + } } ], "initial_state": "Trigger",