Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -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<typeof startWebhookReceiverSession>;
let verifyExchange: ReturnType<typeof verifyMessageExchange>;

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. 🚀`,
},
]);
});
5 changes: 4 additions & 1 deletion twilio-iac/helplines/nz/staging.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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 : {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Collaborator

Choose a reason for hiding this comment

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

f_end_integration_test - this might have been a typo in my original example, there's no reason to prefix the name of that step with 'f_' (unless there is?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's an attempt to standardise the naming of studio widgets, so that's where this comes from - I think Humairaa is busy on updating all studio flows

"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",
Expand Down
Loading