From 9d9e684deb6c877dfdb610d023c3c1280d8b8f4c Mon Sep 17 00:00:00 2001 From: Sinekhaya Date: Tue, 2 Dec 2025 10:31:35 +0200 Subject: [PATCH 1/4] add instagram integration --- .../nz/customChannelChatbot.test.ts | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 lambdas/integrationTestRunner/src/integrationTests/nz/customChannelChatbot.test.ts 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..1643229209 --- /dev/null +++ b/lambdas/integrationTestRunner/src/integrationTests/nz/customChannelChatbot.test.ts @@ -0,0 +1,80 @@ +/** + * 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. 🚀`, + }, + ]); +}); From 4057009f1bb46d87dc31426d9d662646aa33c8e3 Mon Sep 17 00:00:00 2001 From: Sinekhaya Date: Tue, 2 Dec 2025 10:32:16 +0200 Subject: [PATCH 2/4] update studio flow --- twilio-iac/helplines/nz/staging.hcl | 5 +- .../instagram-lex-priority-v2-lambda-sd.tftpl | 71 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) 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", From c041823753156e5a9dd6ef2a87bea1451d787045 Mon Sep 17 00:00:00 2001 From: Sinekhaya Date: Tue, 2 Dec 2025 10:52:17 +0200 Subject: [PATCH 3/4] fix --- .../src/integrationTests/nz/customChannelChatbot.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lambdas/integrationTestRunner/src/integrationTests/nz/customChannelChatbot.test.ts b/lambdas/integrationTestRunner/src/integrationTests/nz/customChannelChatbot.test.ts index 1643229209..937ffd963e 100644 --- a/lambdas/integrationTestRunner/src/integrationTests/nz/customChannelChatbot.test.ts +++ b/lambdas/integrationTestRunner/src/integrationTests/nz/customChannelChatbot.test.ts @@ -43,7 +43,8 @@ test('NZ/staging instagram custom channel chatbot integration test', async () => 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: '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`, From 949d0890af25ae7a5b93697cfcdc42916101f476 Mon Sep 17 00:00:00 2001 From: Sinekhaya Date: Tue, 2 Dec 2025 11:13:40 +0200 Subject: [PATCH 4/4] fix prettier format --- .../src/integrationTests/nz/customChannelChatbot.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lambdas/integrationTestRunner/src/integrationTests/nz/customChannelChatbot.test.ts b/lambdas/integrationTestRunner/src/integrationTests/nz/customChannelChatbot.test.ts index 937ffd963e..ce6671ceb5 100644 --- a/lambdas/integrationTestRunner/src/integrationTests/nz/customChannelChatbot.test.ts +++ b/lambdas/integrationTestRunner/src/integrationTests/nz/customChannelChatbot.test.ts @@ -43,8 +43,10 @@ test('NZ/staging instagram custom channel chatbot integration test', async () => 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: '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`,