AWS for Industries
Building multilingual SMS chatbot campaigns to support COVID-19 patients remotely
The expansion of laboratory tests for COVID-19 have provided health systems with tools to screen for the coronavirus in their community. While some patients have tested positive for COVID-19 and were well enough to manage their symptoms and recover at home, healthcare providers have been challenged with identifying individuals who have waited longer than advisable to seek medical care related to worsening respiratory status. To help address this and to reduce the number of preventable complications in individuals managing COVID-19 at home, one health system has provided support for individuals at home is deploying a scalable, SMS-based home monitoring program to check-in with patients that are COVID-19 positive.
This blog post describes an SMS-based, multilingual home monitoring solution that medical centers and hospitals have deployed to check in with and support their COVID-19 patients daily. The solution is built on a clinical protocol that has been defined by healthcare organizations in assessing for COVID-19 related complications. It also allows for escalation to a nursing phone line if worsening symptoms, such as respiratory status is confirmed and supports a workflow for care providers to secure consent and register patients into their specific program.
Upon enrollment, patients can engage via SMS with a conversational chat experience in their preferred language. During the clinical protocol evaluation, should any escalations with care providers be necessary, the solution can connect the patient with a care provider from within the chat experience. The solution can set time parameters for engagement (e.g. 14 days of monitoring) and automatically notify users of opting out, as long as it is within the fixed start and end dates of the Pinpoint campaign determined by the healthcare provider. The below steps demonstrate how to deploy this solution for your organization to support outreach engagement through a multilingual SMS chatbot campaign.
AWS Solution and Suggested Deployment
This architecture diagram demonstrated the AWS resources needed for this solution, followed by step-by-step guidance for deployment using CloudFormation (CFN) templates.
Step 1: Deploy a campaign registration portal. To enable an SMS campaign, you will first follow the documentation to create an Amazon Pinpoint project, request a long code phone number, and enable a two way SMS channel. The self-managed opt-outs will need to be enabled (see figure in Step 6), since we will use Lambda hook function to fulfill opt-ins/outs operations in Step 5. Take a note of both the Pinpoint project ID and phone number, which will be used in this step. The first CFN deployment will set up a registration portal that helps your organization to enroll new endpoints, e.g. COVID-19 patient phone numbers, into SMS campaign program. The deployment will create a REST API, hosted by AWS API Gateway, and an integrated Lambda proxy function, with appropriate permission policies, to perform the following operations:
- Validate phone number through Amazon Pinpoint phoneNumberValidate API
- Create Pinpoint endpoint through Amazon Pinpoint updateEndpoint API
- Translate the confirmation message according to the preferred language provided through Amazon TranslateText API
- Send confirmation message in user preferred language through Amazon Pinpoint sendMessages API
Once Amplify deployment is finished, you can make changes to this React app to integrate the registration form within this app. You can make change directly in your fork of GitHub repo, or run the local copy with Amplify CLI. You just need to copy/upload the webpage html plus js file to the public folder of this React app and have a hyperlink to the registration page in App.js file:
Once Amplify deployment is finished, you can make changes to this React app to leverage its pre-built UI component for authentication of registration form. You will need to copy/upload the register.html plus SMSFormHandler.js file to the public folder of this React app and have a hyperlink to the registration page in App.js file:
Step 3: Using QnA Bot to respond to a SMS message. To respond to user SMS text messages, e.g. evaluate COVID-19 patient symptoms and complications, you can deploy a Question and Answer (QnA) bot to apply the clinical evaluation protocol in the SMS transactional messages. After you deploy the QnA bot, take a note of BotName and BotAlias from the Output tab of CFN deployment, which will be used in Step 6. Once the QnA bot is ready, you can download clinical protocol question document and import it into the QnA bot Content Designer. The questions with ID as covid.checkin.3, covid.checkin.5, and covid.checkin.6 will be configured further in Step 5 to add the Lambda Hook function.
Step 4: Enable escalation phone call. To enable outbound phone call through Amazon Connect, you can follow this guide to provision a Amazon Connect instance and claim a phone number that will be used for outbound phone call. You can download the contact flow configuration file and create a new custom contact flow by importing it. Make sure the phone number you have claimed is associated with this contact flow. The contact flow will check user defined attribute ‘userPreferredLocale’, then decide how to play prompts and which phone number to transfer to after the outbound call is initiated (the example here only have two different numbers, but you may transfer the call to many different ones)
You will need to take a note of the contact flow ARN (highlighted in red box) and phone number, which will be used in the next step.
Step 5: Deploy AWS Lambda hook functions. Through this deployment, you will create a set of AWS Lambda hook functions including one for initiating the outbound phone call through Amazon Connect and two for self-managed opt-ins/opt-outs. When you deploy the CFN template, make sure the stack name starts with ‘qna-’ or ‘QNA-’. These prefix of AWS Lambda hook functions are required for QnA bot to trigger them.
The output of this deployment has three AWS Lambda hook functions, which will be copied over to the corresponding question Advanced setting for AWS Lambda hook in QnA Content designer:
- LambdaHookConnect function for ID covid.checkin.3 with question: we will connect you soon
- PinpointCampaignOptin function for ID covid.checkin.5 with question: enroll
- PinpointCampaignOptout function for ID covid.checkin.6 with question: stop
In QnA bot Content designer, you will have each of these three questions with AWS Lambda hook configured. The AWS Lambda hook function will trigger after the question is answered.
Once you have the questions for ‘enroll’ and ‘stop’ set up with Lambda Hook functions which can flip the OptOut attribute for a given Amazon Pinpoint endpoint, you can turn on ‘self-managed opt-outs’ for your two-way SMS in Amazon Pinpoint. You will not need the carrier level keywords for opt out anymore.
Step 6: Integrate Amazon Pinpoint with QnA bot. Until now, you have an Amazon Pinpoint project using two-way SMS with a registration system (deployed in Step 1) and a conversational QnA bot with clinical evaluation protocol (deployed in Step 3). Both of them support multiple languages through Amazon Translate API. Next, you will need to integrate them through a SNS channel for two way SMS that is subscribed by an AWS Lambda function that interacts with a QnA Bot. The QnA bot will have questions to trigger AWS Lambda hook functions for self-managed opt-ins/opt-outs and initiating outbound phone call to the SMS user. The following CFN template, named PinpointLexIntegration, should create resources for you.
You will need to configure two-way SMS in Amazon Pinpoint using the created SNS topic.
QnA bot supports multiple languages through Amazon Translate, and which language to use is determined by a session attribute named “userPreferredLocale”. The AWS Lambda function deployed above first retrieves the user preferred language for an Amazon Pinpoint endpoint, then sends the SMS text plus the preferred language attribute to QnA bot through Amazon Lex PostText API.
Step 7: Automatically opt-out endpoint after certain number of days. The Amazon Pinpoint SMS campaign has a fixed start and end dates, how to automatically opt out phone numbers from campaign according to a rolling time window, e.g. 14 days after opt in? It was achieved by an AWS Lambda function, which can retrieve the Amazon Pinpoint stream log data and check the date difference between the endpoint opt in timestamp and most recent campaign timestamp to determine if it is time to opt out phone number from campaign by flipping the value of OptOut attribute from NONE to ALL. The AWS Lambda function will also send one last message to the patients in their preferred language, to notify the them that they have finished SMS checkin program and they can reply ‘ENROLL’ to enroll back into the campaign. You can deploy the following CFN template to stream out the Amazon Pinpoint events to Amazon S3 storage through Amazon Kinesis Firehose, which will trigger the AWS Lambda function to parse the Amazon S3 object and to flip the value of endpoint OptOut attribute if it is beyond a given age limit and send out the SMS notice.
After deployment, you will need to enable the Amazon Pinpoint event stream and send the events to the Amazon Kinesis Data Firehose created through this deployment.
By taking the above outlined steps, you have deployed a SMS campaign platform using Amazon Pinpoint, enabling your organization to register SMS users on their behalf, support the language they prefer to communicate, and opt them out after a defined number of days.
Technology and tools like the SMS chatbot can provide healthcare organizations with the capabilities to scale their engagement channels across their population for broad outreach, while creating more personalized ways to engage and support their patients. Users can respond and interact using two-way SMS channels with the organization’s chatbot and can easily escalate to speak with call center agents initiated and transferred by Amazon Connect. The applications of this tool extend beyond addressing the current COVID-19 crisis, as more healthcare organizations, both healthcare provider or healthcare payor, are developing new channels for engagement to better personalize the healthcare journey. In doing so, these organizations can engage and empower healthcare consumers in their overall health and wellness goals, condition management programs, population health management programs, or clinical trial initiatives for the communities they serve. To find the latest development to this solution, check out sms chatbot multilingual repository on GitHub.
If you want to learn more about this solution or other AWS Healthcare offerings, please visit https://aws.amazon.com/health or contact your local sales representative.
1. QnA bot features and deployment guide.
2. Self paced guide for set up Amazon Connect instance for Chatbot.