COVID19 Test Result 2-way SMS
Tags: twiliohackathon, node, microsoft
Published: 2020-04-28 20:35:47

[Comment]: # (All of this is placeholder text. Use this format or any other format of your choosing to best describe your project.)

[Reminder]: # (Make sure you've submitted the Twilio CodeExchange agreement: https://ahoy.twilio.com/code-exchange-community)

[Important]: # (By making a submission, you agree to the competition's terms: https://www.twilio.com/legal/twilio-dev-hackathon-terms)

## Background

Our regional public health unit in Ontario Canada has had a hard time keeping up with notifying clients of their negative COVID19 test results. They want these notifications to be automated in order to get the results out faster and more efficiently. SMS has been chosen to notify the clients.

## What I built

A solution to automatically notify clients that they have tested negative for COVID19.

## Demo Link

Sorry, no demo for this solution at this time.

## Link to Code

Here is the NodeJS web hook to handle incoming text messages from clients.
https://github.com/CodeWilliamson/covid19-notification

## How I built it

### Stack

- Microsoft SharePoint
- Microsoft Power Automate
- Twilio
- NodeJS

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/sopuui41ktu1mrzsuhip.jpg)

I used Microsoft Power Automate to tap into a SharePoint list that our public health department has been using to track clients' COVID19 test results. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1s1f8m4keqo957254g3w.png)

The power automate flow runs every 15 minutes and pulls in a batch of list items that meet the criteria to send a client an SMS message. Power Automate will then use the Twilio connector to send out an SMS message to the client. The message sent to the client will contain an ID that the client has to text back. That will match the response to the lab results list item in order to update it. It is done this way because multiple clients and multiple lab tests might be done for the same phone number.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/opslldvg0m75o93lbd3e.png)

There is another power automate flow that will check the system status of all SMSs sent out to ensure they are delivered. If the phone number can't receive SMS then the system status will reflect that in the SharePoint list item. The client is then asked in the message to respond to the text with an ID number given.

I built a webhook in NodeJS (https://github.com/CodeWilliamson/covid19-notification) to receive the client's response from Twilio and update the SharePoint list item to show that the client has acknowledged the test result notification. The webhook is configured in Twilio by creating an SMS messaging service and configuring like so:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/94wu4qjnpbig6vx2pys0.png)

The key is to configure the request url to hit your custom webhook code.

### Issues

I ran into an issue when trying to use the Twilio status callback to update the SharePoint list item. The problem is that it runs too quickly for SharePoint to handle the update and I got many 409 conflict errors. This is why I built an asynchronous flow to check the status of SMSs after instead of using the on-demand status callback that Twilio provides.